import java.awt.*; import java.applet.*; import java.applet.Applet; import java.awt.event.*; import java.awt.Choice; public class Joonistamine2 extends Applet implements ActionListener, ItemListener { TextField tf1=new TextField("0"); Button nupp1=new Button("Mitu?"); int nr=0; int x=20; int asi=0; int y=40; boolean tegutse=false; public Joonistamine2(){ Panel p=new Panel(new GridLayout(1,3)); Choice valik=new Choice(); valik.addItem("Ruut"); valik.addItem("Joon"); valik.addItem("Pall"); valik.addItemListener(this); p.add(valik); p.add(tf1); p.add(nupp1); nupp1.addActionListener(this); add(p, BorderLayout.NORTH); } public void itemStateChanged(ItemEvent it){ String s=(String)it.getItem(); if(s=="Ruut") asi=0; else if(s=="Joon") asi=1; else if(s=="Pall") asi=2; } public void actionPerformed(ActionEvent e){ nr=Integer.parseInt(tf1.getText().trim()); tegutse=true; x=20; y=40; repaint(); } public void paint(Graphics g){ if(tegutse){ for(int i=1;i<=nr;i++){ if(nr>10){ tf1.setText("Max 10"); break;} if(asi==0) g.drawRect(x,y,20,20); else if(asi==1) g.drawLine(x,y,x,y+20); else if(asi==2) g.drawOval(x,y,20,20); x=x+30; if(i==5){ y=y+30; x=20;} } } } public static void main(String argumendid[]){ Frame f=new Frame("Joonistamine"); f.setSize(300,300); f.add(new Joonistamine2()); f.setVisible(true); } };