fork(2) download
  1. import java.applet.Applet;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. import javax.swing.Timer;
  6.  
  7. public class question extends Applet implements ActionListener{
  8. Button bt1;
  9. int count = 0;
  10. Timer timer;
  11.  
  12. public void init(){
  13. bt1 = new Button("start");
  14. add(bt1);
  15. bt1.addActionListener(this);
  16. timer = new Timer(1000, this);
  17. }
  18.  
  19. public void actionPerformed(ActionEvent e) {
  20. if (e.getSource() == bt1) {
  21. bt1.setEnabled(false);
  22. count += 1;
  23. repaint();
  24. timer.start();
  25. } else if (e.getSource() == timer) {
  26. count += 2;
  27. repaint();
  28. bt1.setEnabled(true);
  29. timer.stop();
  30. }
  31. }
  32.  
  33. public void paint(Graphics g){
  34. for(int i = 0; i < count; i++){
  35. g.drawRect(10, 10, 10 + i * 5, 10 + i * 5);
  36. }
  37. }
  38.  
  39. }
  40.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty