Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class MyGridLayout extends Frame{
- JFrame f;
- JButton[][] b = new JButton[10][10];
- JButton[][] c = new JButton[10][10];
- JButton bt;
- JTextField tf;
- JPanel p1,p2;
- Game G = new Game();
- MyGridLayout(){
- f=new JFrame();
- /*for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- b[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
- b[i][j].setEnabled(false);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- c[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
- c[i][j].setEnabled(false);
- }
- }
- tf = new JTextField();
- bt = new JButton("GO!");
- JLabel label = new JLabel("Enemy");
- label.setBounds(800,550,151,30);
- label.setFont( new Font( "Arial", Font.PLAIN, 30));
- f.add(label);
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- b[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- c[i][j].setBounds(600 + (i * 50),10 + (j * 50), 50, 50);
- }
- }
- bt.setBounds(200,600,80,30);
- tf.setBounds(165,550,151,30);
- //b[0][0].setFont( new Font( "Arial", Font.PLAIN, 10));
- bt.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- String txt = tf.getText();
- G.move(txt.charAt(0));
- refresh();
- }
- });
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- f.add(b[i][j]);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- f.add(c[i][j]);
- }
- }
- f.add(tf); f.add(bt);
- JPanel panel = new JPanel();
- panel.setBounds(550,0,600,800);
- panel.setBackground(Color.red);
- f.add(panel);
- */
- f.setLayout(null);
- //setting grid layout of 3 rows and 3 columns
- f.setSize(1200,800);
- f.setVisible(true);
- }
- public void refresh() {
- /*b[0][0].setText(Character.toString(G.controller[0][0].view()));
- b[0][1].setText(Character.toString(G.controller[0][1].view()));
- b[0][2].setText(Character.toString(G.controller[0][2].view()));
- b[1][0].setText(Character.toString(G.controller[1][0].view()));
- b[1][1].setText(Character.toString(G.controller[1][1].view()));
- b[1][2].setText(Character.toString(G.controller[1][2].view()));
- b[2][0].setText(Character.toString(G.controller[2][0].view()));
- b[2][1].setText(Character.toString(G.controller[2][1].view()));
- b[2][2].setText(Character.toString(G.controller[2][2].view())); */
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- b[i][j].setText(Character.toString(G.controller[i][j].view()));
- }
- }
- }
- public void Panel1() {
- p1 = new JPanel();
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- b[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
- b[i][j].setEnabled(false);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- b[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- p1.add(b[i][j]);
- }
- }
- p1.setBounds(0,0,600,800);
- p1.setBackground(Color.black);
- f.add(p1);
- }
- public void Panel2() {
- p2 = new JPanel();
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- c[i][j] = new JButton(Character.toString(G.controller[i][j].view()));
- c[i][j].setEnabled(false);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- c[i][j].setBounds(10 + (i * 50),10 + (j * 50), 50, 50);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- p2.add(c[i][j]);
- }
- }
- p2.setBounds(600,0,600,800);
- p2.setBackground(Color.red);
- f.add(p2);
- }
- public static void main(String[] args) {
- MyGridLayout g = new MyGridLayout();
- g.Panel1();
- g.Panel2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement