import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.util.Vector; public class kaal2 extends Applet implements MouseListener, ActionListener{ Graphics g; int x=160, y=40; int x2=170, y2=40; int x3=150, y3=40; public kaal2(){ addMouseListener(this); } public void paint(Graphics g){ //kaalu ylemine osa g.drawLine(50, 20, 100, 20); g.drawLine(55, 60, 95, 60); g.drawRect(55, 25, 40, 10); g.drawLine(50, 20, 55, 60); g.drawLine(100, 20, 95, 60); //kaalu alus g.drawRect(10, 70, 130, 30); //kaalujad g.drawRect(10, 55, 35, 5); g.drawRect(105, 55, 35, 5); // g.drawRect(x, y, 5, 15); g.drawRect(x2, y2, 5, 15); g.drawRect(x3, y3, 5, 15); } public void actionPerformed(ActionEvent e){} public void mousePressed(MouseEvent k){ //korval int hx=k.getX(); int hy=k.getY(); // System.out.println("x: "+x+" y: "+y+" hx: "+hx+" hy: "+hy); // System.out.println("x2: "+x2+" y2: "+y2); // System.out.println("x3: "+x3+" y3: "+y3); if(hx>=160&&hx<=165){ if(hy>=50){ x=25; y=40; }else{ x=120; y=40; } } //keskel if(hx>=120&&hx<=125){ if(hy>=50){ x=160; y=40; }else{ x=25; y=40; } } //vasakul if(hx>=25&&hx<=30){ if(hy>=50){ x=120; y=40; }else{ x=160; y=40; } } if(hx>=170&&hx<=175){ if(hy>=50){ x2=35; y2=40; }else{ x2=130; y2=40; } } //keskel if(hx>=130&&hx<=135){ if(hy>=50){ x2=170; y2=40; }else{ x2=35; y2=40; } } //vasakul if(hx>=35&&hx<=40){ if(hy>=50){ x2=130; y2=40; }else{ x2=170; y2=40; } } if(hx>=150&&hx<=155){ if(hy>=50){ x3=15; y3=40; }else{ x3=110; y3=40; } } //keskel if(hx>=110&&hx<=115){ if(hy>=50){ x3=150; y3=40; }else{ x3=15; y3=40; } } //vasakul if(hx>=15&&hx<=20){ if(hy>=50){ x3=110; y3=40; }else{ x3=150; y3=40; } } repaint(); } public void mouseReleased(MouseEvent k){} public void mouseClicked(MouseEvent k){} public void mouseEntered(MouseEvent k){} public void mouseExited(MouseEvent k){} public static void main(String argumendid[]){ Frame f=new Frame("Kaal"); f.add(new kaal2()); f.setSize(300, 300); f.setVisible(true); } }