Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class MyGridLayout extends Frame{
  6. JFrame f;
  7. JButton[][] b = new JButton[10][10];
  8. JButton[][] c = new JButton[10][10];
  9. JButton bt;
  10. JTextField tf;
  11. JPanel p1,p2;
  12. Game G = new Game();
  13. MyGridLayout(){
  14. f=new JFrame();
  15.  
  16. /*for (int i = 0; i < 3; i++) {
  17. for (int j = 0; j < 3; j++) {
  18. b[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
  19. b[i][j].setEnabled(false);
  20. }
  21. }
  22.  
  23. for (int i = 0; i < 3; i++) {
  24. for (int j = 0; j < 3; j++) {
  25. c[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
  26. c[i][j].setEnabled(false);
  27. }
  28. }
  29.  
  30.  
  31. tf = new JTextField();
  32. bt = new JButton("GO!");
  33.  
  34. JLabel label = new JLabel("Enemy");
  35. label.setBounds(800,550,151,30);
  36. label.setFont( new Font( "Arial", Font.PLAIN, 30));
  37. f.add(label);
  38.  
  39. for (int i = 0; i < 3; i++) {
  40. for (int j = 0; j < 3; j++) {
  41. b[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
  42. }
  43. }
  44.  
  45. for (int i = 0; i < 3; i++) {
  46. for (int j = 0; j < 3; j++) {
  47. c[i][j].setBounds(600 + (i * 50),10 + (j * 50), 50, 50);
  48. }
  49. }
  50.  
  51.  
  52. bt.setBounds(200,600,80,30);
  53. tf.setBounds(165,550,151,30);
  54.  
  55. //b[0][0].setFont( new Font( "Arial", Font.PLAIN, 10));
  56.  
  57. bt.addActionListener(new ActionListener(){
  58. public void actionPerformed(ActionEvent e){
  59.  
  60. String txt = tf.getText();
  61. G.move(txt.charAt(0));
  62. refresh();
  63. }
  64. });
  65.  
  66. for (int i = 0; i < 3; i++) {
  67. for (int j = 0; j < 3; j++) {
  68. f.add(b[i][j]);
  69. }
  70. }
  71.  
  72. for (int i = 0; i < 3; i++) {
  73. for (int j = 0; j < 3; j++) {
  74. f.add(c[i][j]);
  75. }
  76. }
  77.  
  78. f.add(tf); f.add(bt);
  79.  
  80. JPanel panel = new JPanel();
  81. panel.setBounds(550,0,600,800);
  82. panel.setBackground(Color.red);
  83. f.add(panel);
  84. */
  85.  
  86. f.setLayout(null);
  87. //setting grid layout of 3 rows and 3 columns
  88. f.setSize(1200,800);
  89. f.setVisible(true);
  90. }
  91.  
  92. public void refresh() {
  93. /*b[0][0].setText(Character.toString(G.controller[0][0].view()));
  94. b[0][1].setText(Character.toString(G.controller[0][1].view()));
  95. b[0][2].setText(Character.toString(G.controller[0][2].view()));
  96. b[1][0].setText(Character.toString(G.controller[1][0].view()));
  97. b[1][1].setText(Character.toString(G.controller[1][1].view()));
  98. b[1][2].setText(Character.toString(G.controller[1][2].view()));
  99. b[2][0].setText(Character.toString(G.controller[2][0].view()));
  100. b[2][1].setText(Character.toString(G.controller[2][1].view()));
  101. b[2][2].setText(Character.toString(G.controller[2][2].view())); */
  102. for (int i = 0; i < 3; i++) {
  103. for (int j = 0; j < 3; j++) {
  104. b[i][j].setText(Character.toString(G.controller[i][j].view()));
  105. }
  106. }
  107. }
  108.  
  109. public void Panel1() {
  110. p1 = new JPanel();
  111.  
  112. for (int i = 0; i < 3; i++) {
  113. for (int j = 0; j < 3; j++) {
  114. b[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
  115. b[i][j].setEnabled(false);
  116. }
  117. }
  118.  
  119. for (int i = 0; i < 3; i++) {
  120. for (int j = 0; j < 3; j++) {
  121. b[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
  122. }
  123. }
  124.  
  125. for (int i = 0; i < 3; i++) {
  126. for (int j = 0; j < 3; j++) {
  127. p1.add(b[i][j]);
  128. }
  129. }
  130.  
  131. p1.setBounds(0,0,600,800);
  132. p1.setBackground(Color.black);
  133. f.add(p1);
  134. }
  135.  
  136. public void Panel2() {
  137. p2 = new JPanel();
  138.  
  139. for (int i = 0; i < 3; i++) {
  140. for (int j = 0; j < 3; j++) {
  141. c[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
  142. c[i][j].setEnabled(false);
  143. }
  144. }
  145.  
  146. for (int i = 0; i < 3; i++) {
  147. for (int j = 0; j < 3; j++) {
  148. c[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
  149. }
  150. }
  151.  
  152. for (int i = 0; i < 3; i++) {
  153. for (int j = 0; j < 3; j++) {
  154. p2.add(c[i][j]);
  155. }
  156. }
  157.  
  158. p2.setBounds(600,0,600,800);
  159. p2.setBackground(Color.red);
  160. f.add(p2);
  161. }
  162.  
  163.  
  164. public static void main(String[] args) {
  165. MyGridLayout g = new MyGridLayout();
  166. g.Panel1();
  167. g.Panel2();
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement