Monday 19 February 2018

Digital Clock using Graphics2d in java

read more for code
read more for java code



https://www.dropbox.com/s/8ayqre83scnc7u3/Line.jar?dl=0








import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
public class Line  extends Frame implements Runnable
{
    static int x=0;
Line()
{
   addWindowListener(new WindowAdapter()
         {
             public void windowClosing(WindowEvent e)
             {
                 System.exit(0);
             }
         });
 
         setLayout(null);
}
public void paint(Graphics gd)
{
      Graphics2D g = (Graphics2D) gd;   
     paintComponent(g);

    g.setStroke(new BasicStroke(7F));

     Calendar c=Calendar.getInstance();
           int m=c.get(Calendar.MINUTE);
           int h=c.get(Calendar.HOUR);
           int s=c.get(Calendar.SECOND);
               g.setColor(Color.red);
           
           t(g,m/10,200);
           t(g,m%10,280);
           t(g,s/10,360);
           t(g,s%10,440);
           t(g,h/10,40);
            t(g,h%10,120);
}
public void paintComponent(Graphics2D g)
{
    x=1;
g.fillOval(175, 50, 7, 7);
g.fillOval(175, 100, 7, 7);
 
g.fillOval(335, 50, 7, 7);
g.fillOval(335, 100, 7, 7);
    g.drawOval(175, 50, 7, 7);
 
     g.drawOval(175, 100, 7, 7);
     g.drawOval(335, 50, 7, 7);
     g.drawOval(335, 100, 7, 7);
}
public void run()
{
    while(true)
    {
        try{
        Thread.currentThread().sleep(1000);}catch(Exception e){}
        repaint();
     
    }

public void one(Graphics g,int x,int y)
{
    if(x==360||x==40){
        g.drawLine(x+40,y,x+40,y+80);
 
    }
    else if(x==40||x==200)
    {
        g.drawLine(x+40,y,x+40,y+80);
    }
    else
    {
         g.drawLine(x,y,x,y+80);
    }
}
public void two(Graphics g,int x,int y)
{
    g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y,x+40,y+40);
     g.drawLine(x+40,y+40,x,y+40);
     g.drawLine(x,y+40,x,y+80);
      g.drawLine(x+40,y+80,x,y+80);
}
public void three(Graphics g,int x,int y)
{
     g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y,x+40,y+80);
      g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x+40,y+80,x,y+80);
   
}
public void four(Graphics g,int x,int y)
{
    g.drawLine(x,y,x,y+40);
     g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x+40,y,x+40,y+80);
   
}
public void five(Graphics g,int x,int y)
{
     g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x+40,y+80,x,y+80);
       g.drawLine(x,y+40,x,y);
        g.drawLine(x+40,y+40,x+40,y+80);
}
public void six(Graphics g,int x,int y)
{
    g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x+40,y+80,x,y+80);
       g.drawLine(x,y+80,x,y);
        g.drawLine(x+40,y+40,x+40,y+80);
     
}
public void seven(Graphics g,int x,int y)
{
    g.drawLine(x,y,x+40,y);
    g.drawLine(x+40,y,x+40,y+80);
}
public void eight(Graphics g,int x,int y)
{
     g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x+40,y+80,x,y+80);
       g.drawLine(x,y+80,x,y);
        g.drawLine(x+40,y,x+40,y+80);
     
}
public void nine(Graphics g,int x,int y)
{
    g.drawLine(x,y,x+40,y);
     g.drawLine(x+40,y+40,x,y+40);
      g.drawLine(x,y+40,x,y);
      g.drawLine(x+40,y,x+40,y+80);
      g.drawLine(x+40,y+80,x,y+80);
}
public void zero(Graphics g,int x,int y)
{
     g.drawLine(x,y,x+40,y);
       g.drawLine(x,y,x,y+80);
      g.drawLine(x+40,y+80,x,y+80);
        g.drawLine(x+40,y,x+40,y+80);
}
public void t(Graphics g,int i,int x)
{
   switch(i)
   {
       case 1:
           one(g,x,40);
           break;
       case 2:
           two(g,x,40);
           break;
            case 6:
           six(g,x,40);
           break;
       case 3:
           three(g,x,40);
           break;
            case 4:
          four(g,x,40);
           break;
       case 5:
           five(g,x,40);
           break;
         case 7:
           seven(g,x,40);
           break;
            case 8:
           eight(g,x,40);
           break;
            case 9:
           nine(g,x,40);
           break;
            case 0:
           zero(g,x,40);
           break;
   }
}
    public static void main(String[] args) {
  Line l=new Line();
  Thread t=new Thread(l);
  l.setSize(600,600);
   l.setVisible(true);
  t.start();

}
}
https://www.dropbox.com/s/8ayqre83scnc7u3/Line.jar?dl=0

Sunday 18 February 2018

calculator using java awt

https://www.dropbox.com/s/uxe35t2kua9huxq/Calci.jar?dl=0

import java.awt.event.*;
import java.awt.*;
import java.util.ArrayList;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class Calci extends Frame implements ActionListener {
TextArea ta;
Button b1,b2,b3,b0,b4,b5,b6,b7,b8,b9,ba,bs,bm,bi,bo,bb,be,bp,bc,bn,bq;
Calci(){
    ab.add("b1");ab.add("b2");ab.add("b3");ab.add("b4");ab.add("b5");ab.add("b6");
    ab.add("b7");ab.add("b8");ab.add("b9");ab.add("b0");ab.add("ba");ab.add("bs");
    ab.add("bm");ab.add("bi");
    ta=new TextArea("",3,10,TextArea.SCROLLBARS_NONE);
    b1=new Button("1");ba=new Button("+");bq=new Button("^");
    b2=new Button("2");bs=new Button("-");
    b3=new Button("3");bm=new Button("x");
    b4=new Button("4");bi=new Button("/");
    b5=new Button("5");bo=new Button("%");
    b6=new Button("6");bb=new Button("<-");
    b7=new Button("7");be=new Button("=");
    b8=new Button("8");bp=new Button(".");
    b9=new Button("9");bc=new Button("C");
    b0=new Button("0");bn=new Button("~");
    b1.setBackground(Color.CYAN);b2.setBackground(Color.CYAN);b3.setBackground(Color.CYAN);
    b4.setBackground(Color.CYAN);b5.setBackground(Color.CYAN);b6.setBackground(Color.CYAN);
    b7.setBackground(Color.CYAN);b8.setBackground(Color.CYAN);b9.setBackground(Color.CYAN);
    ta.setBounds(20,30,200,50);b1.setBounds(20,120,40,20);
    b7.setBounds(20,80,40,20);b2.setBounds(60,120,40,20);
    b8.setBounds(60,80,40,20);b3.setBounds(100,120,40,20);
    b9.setBounds(100,80,40,20);bb.setBounds(20,140,40,20);
    b4.setBounds(20,100,40,20);b0.setBounds(60,140,40,20);
    b5.setBounds(60,100,40,20);bp.setBounds(100,140,40,20);
    b6.setBounds(100,100,40,20);bi.setBounds(140,80,40,20);
    ba.setBounds(140,140,40,20);bn.setBounds(20,160,40,20);
    bc.setBounds(60,160,40,20);bq.setBounds(100,160,40,20);
    be.setBounds(140,160,40,20);
    b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);
     b4.addActionListener(this);b5.addActionListener(this);b6.addActionListener(this);
      b7.addActionListener(this);b8.addActionListener(this);b9.addActionListener(this);
       b0.addActionListener(this);ba.addActionListener(this);bs.addActionListener(this);
        be.addActionListener(this);bi.addActionListener(this);bm.addActionListener(this);
        bb.addActionListener(this);bn.addActionListener(this);bq.addActionListener(this);
        bc.addActionListener(this);bo.addActionListener(this);bp.addActionListener(this);
    add(ta);bm.setBounds(140,100,40,20);bs.setBounds(140,120,40,20);
    add(b7);add(b4);add(b1);add(bb);add(ba);add(bi);add(bn);
    add(b8);add(b5);add(b2);add(b0);add(bs);add(bq);add(be);
    add(b9);add(b6);add(b3);add(bp);add(bm);add(bc);
    addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e)
        {dispose();
        }
    });
    ta.setText("");
    setLayout(null);
}
public void actionPerformed(ActionEvent e){
    if(bb==e.getSource()){
ta.setText(ta.getText().substring(0,ta.getText().length()-1));}
    else if(bc==e.getSource()){
        ta.setText("");}
    else if(bn==e.getSource())
    {
        Double d=Double.parseDouble(ta.getText());
        if(ta.getText().charAt(0)=='-')
        {
            ta.setText(ta.getText().substring(1));
        }
        else if(d!=0.0)
        {
            ta.setText("-".concat(ta.getText()));
        }
    }
    else if(bq==e.getSource())
    {
        Double d=Double.parseDouble(ta.getText());
         if(d!=0.0)
        {
            d=d*d;
            ta.setText(String.valueOf(d));
        }

    }

    else if(be==e.getSource())
    {
        try{

        ta.setText(exp(ta.getText().replace('x','*')));

        }
        catch(Exception ext)
        {

        }

    }  else {

    ta.append(e.getActionCommand());

    }
}
public String  exp(String foo) throws Exception
{
    ScriptEngineManager s=new ScriptEngineManager();
    ScriptEngine se=s.getEngineByName("JavaScript");
    return String.valueOf(se.eval(foo));
}
    public static void main(String[] args) {
        Calci c=new Calci();
        c.setSize(200,300);
        c.setVisible(true);
    }
}

CODING FPGROWTH IN PYTHON FROM SCRATCH

dats=[['google','amazon',],['amazon','google','python','cse'],['cse','google&#...