fork download
  1. import java.applet.Applet;
  2. import java.awt.Graphics;
  3. import java.awt.Color;
  4. import java.awt.Image;
  5. import java.awt.Dimension;
  6.  
  7. /* <applet code="Main.class" width="500" height="500"></applet> */
  8.  
  9. class ForDimChange {
  10. private Dimension dim;
  11. private Image buff;
  12. private Graphics ct;
  13. private int x, y;
  14. ForDimChange() {
  15. x = y = 0;
  16. update();
  17. }
  18. void update() {
  19. boolean flag = false;
  20. dim = getSize();
  21. if (x != dim.width) {
  22. x = dim.width;
  23. flag = true;
  24. }
  25. if (y != dim.height) {
  26. y = dim.height;
  27. flag = true;
  28. }
  29. if (flag) {
  30. buff = createImage(x, y);
  31. ct = buff.getGraphics();
  32. }
  33. }
  34. int get_dimx() { return x; }
  35. int get_dimy() { return y; }
  36. Image get_buff() { return buff; }
  37. Graphics get_ct() { return ct; }
  38. }
  39.  
  40. public class Main extends Applet implements Runnable {
  41. boolean chkx = true, chky = true;
  42. int x = 250, y = 140;
  43. Thread th;
  44. ForDimChange fdc;
  45.  
  46. class ForDimChange {
  47. private Dimension dim;
  48. private Image buff;
  49. private Graphics ct;
  50. private int x, y;
  51. ForDimChange() {
  52. x = y = 0;
  53. update();
  54. }
  55. void update() {
  56. boolean flag = false;
  57. dim = getSize();
  58. if (x != dim.width) {
  59. x = dim.width;
  60. flag = true;
  61. }
  62. if (y != dim.height) {
  63. y = dim.height;
  64. flag = true;
  65. }
  66. if (flag) {
  67. buff = createImage(x, y);
  68. ct = buff.getGraphics();
  69. }
  70. }
  71. int get_dimx() { return x; }
  72. int get_dimy() { return y; }
  73. Image get_buff() { return buff; }
  74. Graphics get_ct() { return ct; }
  75. }
  76.  
  77. public void init() {
  78. fdc = new ForDimChange();
  79. th = new Thread(this);
  80. th.start();
  81. }
  82.  
  83. public void run() {
  84. try {
  85. while (true) {
  86. fdc.update();
  87. if (chkx) x++; else x--;
  88. if (chky) y++; else y--;
  89. if (x == fdc.get_dimx()) chkx = false;
  90. if (x == 0) chkx = true;
  91. if (y == fdc.get_dimy()) chky = false;
  92. if (y == 0) chky = true;
  93.  
  94. repaint();
  95. Thread.sleep(10);
  96. }
  97. } catch (InterruptedException e) { };
  98. }
  99. public void update(Graphics g) {
  100. paint(g);
  101. }
  102. public void paint(Graphics g) {
  103. ct = fdc.get_ct();
  104. ct.setColor(Color.white);
  105. ct.fillRect(0, 0, fdc.get_dimx(), fdc.get_dimy());
  106. ct.setColor(Color.red);
  107. ct.fillRect(x, y, 20, 20);
  108. g.drawImage(fdc.get_buff(), 0, 0, this);
  109. }
  110. }
  111. /* end */
  112.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:20: cannot find symbol
symbol  : method getSize()
location: class ForDimChange
    dim = getSize();
          ^
Main.java:30: cannot find symbol
symbol  : method createImage(int,int)
location: class ForDimChange
      buff = createImage(x, y);
             ^
2 errors
stdout
Standard output is empty