fork download
  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. public class Demo extends Applet {
  8.  
  9. private Button button;
  10. private int x = 225;
  11. private int y = 50;
  12. private int WIDTH = 50;
  13. private int HEIGHT = 400;
  14.  
  15. @Override
  16. public void init() {
  17. // TODO Auto-generated method stub
  18. button = new Button("Cù Trọng Xoay!");
  19. add(button);
  20.  
  21. button.addActionListener(new ActionListener() {
  22.  
  23. @Override
  24. public void actionPerformed(ActionEvent e) {
  25. // TODO Auto-generated method stub
  26. int temp = x;
  27. x = y;
  28. y = temp;
  29.  
  30. temp = WIDTH;
  31. WIDTH = HEIGHT;
  32. HEIGHT = temp;
  33.  
  34. repaint();
  35. }
  36. });
  37. }
  38.  
  39. @Override
  40. public void paint(Graphics g) {
  41. // TODO Auto-generated method stub
  42. setSize(500, 500);
  43.  
  44. g.drawRect(x, y, WIDTH, HEIGHT);
  45.  
  46. setVisible(true);
  47. }
  48.  
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class Demo is public, should be declared in a file named Demo.java
public class Demo extends Applet {
       ^
1 error
stdout
Standard output is empty