import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Pastapliiats1 extends Applet implements ActionListener, MouseListener{ int nr=1; int suurus=4; int i=nr*suurus; boolean vajutus=false; TextField tf=new TextField("1"); Button nupp=new Button(" OK "); public Pastapliiats1(){ add(tf); add(nupp); nupp.addActionListener(this); addMouseListener(this); } public void actionPerformed(ActionEvent e){ nr=Integer.parseInt(tf.getText().trim()); repaint(); } public void paint(Graphics g){ int i=nr*suurus; g.setColor(Color.black); g.drawLine(500-i, 250-i, 500-i, 410+i*2); g.drawLine(515+i, 250-i, 515+i, 410+i*2); g.drawLine(500-i, 250-i, 515+i, 250-i); g.drawLine(500-i, 410+i*2 , 505-i/2, 430+i*3); g.drawLine(515+i, 410+i*2, 510+i/2, 430+i*3); g.drawLine(505-i/2, 430+i*3, 510+i/2, 430+i*3); g.drawLine(515+i, 250-i, 520+i+i/2, 250-i); g.drawLine(520+i+i/2, 250-i, 520+i+i/2, 310); if (vajutus==false){ g.drawRect(503-i/2, 240-i*2, 9+i, 10+i); } if (vajutus==true){ g.drawRect(503-i/2, 245-i*2, 9+i, 5+i); g.drawLine(507-i/2, 430+i*3, 508-2, 440+i*4); g.drawLine(508+i/2, 430+i*3, 507+2, 440+i*4); g.drawLine(508-2, 440+i*4, 507+2, 440+i*4); } } public void mousePressed(MouseEvent e){ int i=nr*suurus; /* if(Math.abs((503-i/2+2)-e.getX())<(9+i)/2&&Math.abs((240-i*2+8)-e.getY())<(10+i)/2){ vajutus=true; } if(Math.abs((503-i/2+2)-e.getX())<(9+i)/2&&Math.abs((245-i*2+8)-e.getY())<(5+i)/2){ vajutus=false; } */ if(Math.abs((507)-e.getX())<(9+i)/2&&Math.abs((240+i/2)-e.getY())<(10+i) && vajutus==false){ vajutus=true; } else if(Math.abs((507)-e.getX())<(9+i)/2&&Math.abs((245+i/2)-e.getY())<(5+i) && vajutus==true){ vajutus=false; } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Pastapliiats"); f.setSize(1200, 900); f.add(new Pastapliiats1()); f.setVisible(true); } }