import java.applet.*; import java.awt.*; import java.awt.event.*; public class Lamp extends Applet implements MouseMotionListener, MouseListener, ActionListener{ int Sees2 = 1; int Väljas2 = 0; int Sees = 0; int värv_number; int Aeg_1; int Aeg_2; Button Nupp1=new Button("Sisesta Heledus"); Button Nupp2=new Button("Sisesta ''Muster''"); TextField tf1=new TextField("Heledus skaalal 1...5"); TextField tf2=new TextField("Siia kirjuta aeg kaua põleb (SEKUNDIT)"); TextField tf3=new TextField("Siia kirjuta aeg kaua Kustund on (SEKUNDIT)"); public Lamp(){ add(tf1); add(Nupp1); add(tf2); add(tf3); add(Nupp2); tf1.addActionListener(this); tf2.addActionListener(this); tf3.addActionListener(this); Nupp1.addActionListener(this); Nupp2.addActionListener(this); addMouseMotionListener(this); addMouseListener(this); } public void actionPerformed(ActionEvent e){ Graphics g=getGraphics(); if(e.getSource() == Nupp1){ try{ värv_number=Integer.parseInt(tf1.getText()); System.out.println(värv_number); }catch(Exception viga){ System.out.println("problemaaatika nupuga1!"); } } if(e.getSource() == Nupp2){ try{ Aeg_1=Integer.parseInt(tf2.getText()); Aeg_2=Integer.parseInt(tf3.getText()); while(true){ if(Väljas2 == 0){ g.setColor(Color.black); g.drawRect(200, 200, 80, 40); g.drawLine(235 ,240 ,235 ,280); g.drawLine(245 ,240 ,245 ,280); g.drawRect(220 ,280 ,40 ,10); g.setColor(Color.white); g.fillRect(201, 201, 79, 39); try{Thread.sleep(Aeg_2*1000);}catch(Exception ex){} } if(Sees2 == 1){ g.setColor(Color.black); g.drawRect(200, 200, 80, 40); g.drawLine(235 ,240 ,235 ,280); g.drawLine(245 ,240 ,245 ,280); g.drawRect(220 ,280 ,40 ,10); g.setColor(Color.yellow); g.fillRect(201, 201, 79, 39); try{Thread.sleep(Aeg_1*1000);}catch(Exception ex){} } } }catch(Exception viga){ System.out.println("problemaaatika nupuga2!"); } } } public void paint(Graphics g){ if(Sees == 0){ g.drawRect(200, 200, 80, 40); g.drawLine(235 ,240 ,235 ,280); g.drawLine(245 ,240 ,245 ,280); g.drawRect(220 ,280 ,40 ,10); } if(Sees == 1){ g.drawRect(200, 200, 80, 40); g.drawLine(235 ,240 ,235 ,280); g.drawLine(245 ,240 ,245 ,280); g.drawRect(220 ,280 ,40 ,10); g.setColor(Color.yellow); if(värv_number == 1){g.setColor(new Color(206, 206, 0)); } if(värv_number == 2){g.setColor(new Color(152, 223, 19)); } if(värv_number == 3){g.setColor(new Color(170, 238, 45)); } if(värv_number == 4){g.setColor(new Color(200, 243, 118));} if(värv_number == 5){g.setColor(new Color(216, 247, 157));} g.fillRect(201, 201, 79, 39); } } public void mousePressed(MouseEvent e){ if(Sees == 1){ Sees = 0; }else{ Sees = 1; } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Lambi funktsioonid"); f.setSize(900, 700); f.setLocation(50, 50); f.add(new Lamp()); f.setVisible(true); } }