import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.image.*; public class Lamp extends Applet implements ActionListener,AdjustmentListener{ Scrollbar kerimisriba=new Scrollbar(Scrollbar.VERTICAL,20,5,1,30); Image lamp=Toolkit.getDefaultToolkit().getImage("lamp.gif"); Button nupp=new Button(" Lamp põlema "); Button nupp1=new Button(" Tuttu ja lamp kustu! "); TextField tf=new TextField(10); int roheline=0; int punane=0; int sinine=0; public Lamp(){ setBackground(Color.black); setLayout(new BorderLayout()); Panel p1=new Panel(new GridLayout(1,3)); add("West", kerimisriba); add("South", tf); kerimisriba.addAdjustmentListener(this); p1.add(nupp); p1.add(nupp1); add(p1,BorderLayout.NORTH); nupp.addActionListener(this); nupp1.addActionListener(this); } public void adjustmentValueChanged(AdjustmentEvent e){ tf.setText(kerimisriba.getValue()+""); //Graphics g=this.getGraphics(); //int kollane=Integer.parseInt(tf.getText().trim()); } public void actionPerformed(ActionEvent e){ int kollane=Integer.parseInt(tf.getText().trim()); Graphics g=this.getGraphics(); if(e.getSource()==nupp){ if(kollane==5){ g.setColor(new Color(punane+244,roheline+231,sinine)); } if(kollane==10){ g.setColor(new Color(punane+245,roheline+235,sinine+94)); } if(kollane==15){ g.setColor(new Color(punane+239,roheline+237,sinine+185)); } if(kollane==20){ g.setColor(new Color(punane+249,roheline+246,sinine+220)); } if(kollane==25){ g.setColor(new Color(punane+250,roheline+248,sinine+231)); } //g.setColor(Color.yellow); g.fillOval(40,290,200,200); } if(e.getSource()==nupp1){ g.setColor(Color.white); g.fillOval(40,290,200,200); } } public void paint(Graphics g){ g.drawImage(lamp, 0, 0, getWidth(), getHeight(), this); } public static void main(String argumendid[]){ Frame f=new Frame("Õpime lampi ökonoomselt kasutama"); f.setSize(840, 970); f.add(new Lamp()); f.setVisible(true); } }