fork download
  1. import javax.swing.*;
  2. import java.awt.BorderLayout;
  3. import java.awt.Color;
  4. import java.awt.Container;
  5. import java.awt.Font;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11. import java.awt.event.KeyListener;
  12. import java.io.IOException;
  13.  
  14. public class main implements Runnable {
  15.  
  16. int rows;
  17. int columns;
  18. int LiczbaORGANIZMOW = 0;
  19. JLabel flagCounter;
  20. JButton[][] buttons;
  21.  
  22.  
  23. public static void main(String[] args) throws IOException,
  24. ClassNotFoundException {
  25. // TODO Auto-generated method stub
  26. new main().run();
  27. }
  28.  
  29. public main() throws IOException, ClassNotFoundException {
  30. Swiat elo = new Swiat();
  31. rows = 21;
  32. columns = 21;
  33. buttons = new JButton[rows][columns];
  34. flagCounter = new JLabel("Liczba Organizmow: " + elo.liczbaaOrg);
  35.  
  36. JFrame frame = new JFrame("Obiektowka");
  37. Container topCon = new Container();
  38. Container botCon = new Container();
  39. JPanel pane = new JPanel();
  40. JPanel p = new JPanel();
  41. JButton New = new JButton();
  42. JButton Wczytaj = new JButton();
  43. JButton Zapisz = new JButton();
  44. JButton Tura = new JButton();
  45. JButton Czysc = new JButton();
  46.  
  47.  
  48. botCon.setSize(5, 5);
  49. topCon.setLayout(new BorderLayout());
  50. botCon.setLayout(new BorderLayout());
  51. topCon.setSize(500, 500);
  52. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53. frame.setBounds(235, 235, 235, 235);
  54.  
  55. New.setSize(50, 50);
  56. New.setBounds(50, 50, 50, 50);
  57. New.setText("Nowa Tura");
  58. New.addActionListener(new ActionListener() {
  59. public void actionPerformed(ActionEvent arg0) {
  60. UtworzSwiat(elo);
  61. }
  62. });
  63. New.setVisible(true);
  64.  
  65. Wczytaj.setSize(50, 50);
  66. Wczytaj.setBounds(50, 50, 50, 50);
  67. Wczytaj.setText("Wczytaj");
  68. Wczytaj.addActionListener(new ActionListener() {
  69. public void actionPerformed(ActionEvent arg0) {
  70. resetBoard(elo);
  71. }
  72. });
  73. Wczytaj.setVisible(true);
  74.  
  75. Zapisz.setSize(50, 50);
  76. Zapisz.setBounds(50, 50, 50, 50);
  77. Zapisz.setText("Zapisz");
  78. Zapisz.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent arg0) {
  80. Zapisz(elo);
  81. }
  82. });
  83. Zapisz.setVisible(true);
  84.  
  85. Tura.setSize(50, 50);
  86. Tura.setBounds(50, 50, 50, 50);
  87. Tura.setText("Kolejna Tura");
  88. Tura.addActionListener(new ActionListener() {
  89. public void actionPerformed(ActionEvent arg0) {
  90. WykonajTure(elo);
  91. }
  92. });
  93. Tura.setVisible(true);
  94.  
  95. Czysc.setSize(50, 50);
  96. Czysc.setBounds(50, 50, 50, 50);
  97. Czysc.setText("Czyszczenie");
  98. Czysc.addActionListener(new ActionListener() {
  99. public void actionPerformed(ActionEvent arg0) {
  100. resetBoard(elo);
  101. }
  102. });
  103. Czysc.setVisible(true);
  104.  
  105. pane.add(flagCounter);
  106. pane.add(New);
  107. pane.add(Wczytaj);
  108. pane.add(Zapisz);
  109. pane.add(Tura);
  110. pane.add(Czysc);
  111. pane.setBounds(100, 100, 100, 100);
  112. pane.setSize(100, 100);
  113. frame.setVisible(true);
  114. topCon.add(pane);
  115. p.setLayout(new GridLayout(rows, columns, 0, 0));
  116.  
  117. for (int x = 0; x < rows; x++) {
  118. for (int y = 0; y < columns; y++) {
  119. if (x == 0 && y == 0) {
  120. buttons[x][y] = new JButton();
  121. buttons[x][y].setVisible(true);
  122. p.add(buttons[x][y]);
  123. }
  124.  
  125. else if (x == 0) {
  126. buttons[x][y] = new JButton();
  127. buttons[x][y].setVisible(true);
  128. buttons[x][y].setText(Integer.toString(y - 1));
  129. p.add(buttons[x][y]);
  130.  
  131. } else if (y == 0) {
  132. buttons[x][y] = new JButton();
  133. buttons[x][y].setVisible(true);
  134. buttons[x][y].setText("as");
  135. buttons[x][y].setText(Integer.toString(x - 1));
  136. p.add(buttons[x][y]);
  137.  
  138. } else {
  139. buttons[x][y] = new JButton();
  140. buttons[x][y].setVisible(true);
  141. buttons[x][y]
  142. .setFont(new Font("Lucida Sans", Font.BOLD, 12));
  143. buttons[x][y].setBackground(Color.white);
  144. p.add(buttons[x][y]);
  145. }
  146. }
  147.  
  148. }
  149. frame.add(p);
  150. p.setVisible(true);
  151. botCon.add(p);
  152. botCon.setVisible(true);
  153. topCon.setVisible(true);
  154. frame.add(botCon, BorderLayout.CENTER);
  155. frame.add(topCon, BorderLayout.NORTH);
  156. frame.setBounds(200, 100, columns * 20, rows * 20);
  157. pane.addKeyListener(new KAdapter());
  158. pane.requestFocus();
  159. frame.setVisible(true);
  160.  
  161. }
  162.  
  163. //funkjce
  164.  
  165. @Override
  166. public void run() {
  167.  
  168. }
  169.  
  170. }
  171.  
  172. class KAdapter extends KeyAdapter implements KeyListener {
  173.  
  174. @Override
  175. public void keyPressed(KeyEvent e) {
  176.  
  177. System.out.println("Wczytaj ruch :");
  178.  
  179. int key = e.getKeyCode();
  180.  
  181. if (key == KeyEvent.VK_LEFT) {
  182. System.out.println("elo lewo ");
  183. }
  184.  
  185. if (key == KeyEvent.VK_RIGHT) {
  186.  
  187. }
  188.  
  189. if (key == KeyEvent.VK_UP) {
  190.  
  191. }
  192.  
  193. if (key == KeyEvent.VK_DOWN) {
  194.  
  195. }
  196. }
  197.  
  198. @Override
  199. public void keyReleased(KeyEvent e) {
  200. // TODO Auto-generated method stub
  201.  
  202. }
  203.  
  204. @Override
  205. public void keyTyped(KeyEvent e) {
  206. // TODO Auto-generated method stub
  207. }
  208. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:165:2: error: stray '@' in program
  @Override
  ^
prog.cpp:174:2: error: stray '@' in program
  @Override
  ^
prog.cpp:198:2: error: stray '@' in program
  @Override
  ^
prog.cpp:204:2: error: stray '@' in program
  @Override
  ^
prog.cpp:1:1: error: 'import' does not name a type
 import javax.swing.*;
 ^
prog.cpp:2:1: error: 'import' does not name a type
 import java.awt.BorderLayout;
 ^
prog.cpp:3:1: error: 'import' does not name a type
 import java.awt.Color;
 ^
prog.cpp:4:1: error: 'import' does not name a type
 import java.awt.Container;
 ^
prog.cpp:5:1: error: 'import' does not name a type
 import java.awt.Font;
 ^
prog.cpp:6:1: error: 'import' does not name a type
 import java.awt.GridLayout;
 ^
prog.cpp:7:1: error: 'import' does not name a type
 import java.awt.event.ActionEvent;
 ^
prog.cpp:8:1: error: 'import' does not name a type
 import java.awt.event.ActionListener;
 ^
prog.cpp:9:1: error: 'import' does not name a type
 import java.awt.event.KeyAdapter;
 ^
prog.cpp:10:1: error: 'import' does not name a type
 import java.awt.event.KeyEvent;
 ^
prog.cpp:11:1: error: 'import' does not name a type
 import java.awt.event.KeyListener;
 ^
prog.cpp:12:1: error: 'import' does not name a type
 import java.io.IOException;
 ^
prog.cpp:14:1: error: expected unqualified-id before 'public'
 public class main  implements Runnable {
 ^
stdout
Standard output is empty