fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. import java.awt.Color;
  13. import java.awt.Dimension;
  14. import java.awt.Graphics;
  15. import javax.swing.JFrame;
  16. import javax.swing.JPanel;
  17. import javax.swing.WindowConstants;
  18.  
  19. public class getQuadrant extends JPanel {
  20.  
  21. boolean COLORDED_MODE = true;
  22.  
  23. int tankX = 384;
  24. int tankY = 128;
  25.  
  26. long speed = 300l;
  27.  
  28. long speed0 = 3l;
  29.  
  30. /**
  31. * Write your code here.
  32. */
  33.  
  34. void runTheGame() throws Exception {
  35.  
  36. move(4);
  37. move(4);
  38. move(4);
  39. move(1);
  40. move(1);
  41. move(1);
  42. move(2);
  43. move(2);
  44. move(0);
  45. move(3);
  46. }
  47.  
  48. void move(int direction) throws InterruptedException {
  49.  
  50. int distance = 64;
  51. int i = 0;
  52. int pace = 8;
  53.  
  54. if (tankX == 512 && direction == 4 || tankX == 64 && direction == 3) {
  55. direction = 0;
  56.  
  57. }
  58. if (tankY == 512 && direction == 2 || tankY == 0 && direction == 1) {
  59. direction = 0;
  60.  
  61. }
  62.  
  63. while (i < distance) {
  64. i += pace;
  65. if (direction == 4) {
  66. tankX += pace;
  67. } else if (direction == 3) {
  68. tankX -= pace;
  69. } else if (direction == 1) {
  70. tankY -= pace;
  71. } else if (direction == 2) {
  72. tankY += pace;
  73. } else if (direction == 0) {
  74. tankX += 0;
  75. tankY += 0;
  76. Thread.sleep(speed0);
  77. } else {
  78. System.out.println("wrong direction");
  79. }
  80. repaint();
  81. Thread.sleep(speed);
  82. }
  83. }
  84.  
  85. // Magic bellow. Do not worry about this now, you will understand everything
  86. // in this course.
  87. // Please concentrate on your tasks only.
  88.  
  89. final int BF_WIDTH = 576;
  90. final int BF_HEIGHT = 576;
  91.  
  92. public static void main(String[] args) throws Exception {
  93. getQuadrant bf = new getQuadrant();
  94. bf.runTheGame();
  95. }
  96.  
  97. public getQuadrant() throws Exception {
  98. JFrame frame = new JFrame("BATTLE FIELD, DAY 2");
  99. frame.setLocation(500, 150);
  100. frame.setMinimumSize(new Dimension(BF_WIDTH, BF_HEIGHT + 22));
  101. frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  102. frame.getContentPane().add(this);
  103. frame.pack();
  104. frame.setVisible(true);
  105. }
  106.  
  107. @Override
  108. protected void paintComponent(Graphics g) {
  109. super.paintComponent(g);
  110.  
  111. int i = 0;
  112. Color cc;
  113. for (int v = 0; v < 9; v++) {
  114. for (int h = 0; h < 9; h++) {
  115. if (COLORDED_MODE) {
  116. if (i % 2 == 0) {
  117. cc = new Color(252, 241, 177);
  118. } else {
  119. cc = new Color(233, 243, 255);
  120. }
  121. } else {
  122. cc = new Color(180, 180, 180);
  123. }
  124. i++;
  125. g.setColor(cc);
  126. g.fillRect(h * 64, v * 64, 64, 64);
  127. }
  128. }
  129.  
  130. g.setColor(new Color(255, 0, 0));
  131. g.fillRect(tankX, tankY, 64, 64);
  132. }
  133.  
  134. }
  135. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:12: error: illegal start of expression
	import java.awt.Color;
	^
Main.java:12: error: not a statement
	import java.awt.Color;
	               ^
Main.java:13: error: illegal start of expression
import java.awt.Dimension;
^
Main.java:13: error: not a statement
import java.awt.Dimension;
               ^
Main.java:14: error: illegal start of expression
import java.awt.Graphics;
^
Main.java:14: error: not a statement
import java.awt.Graphics;
               ^
Main.java:15: error: illegal start of expression
import javax.swing.JFrame;
^
Main.java:15: error: not a statement
import javax.swing.JFrame;
                  ^
Main.java:16: error: illegal start of expression
import javax.swing.JPanel;
^
Main.java:16: error: not a statement
import javax.swing.JPanel;
                  ^
Main.java:17: error: illegal start of expression
import javax.swing.WindowConstants;
^
Main.java:17: error: not a statement
import javax.swing.WindowConstants;
                  ^
Main.java:19: error: illegal start of expression
public class getQuadrant extends JPanel {
^
Main.java:135: error: reached end of file while parsing
}
 ^
14 errors
stdout
Standard output is empty