Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.* ;
- import java.awt.* ;
- import java.util.* ;
- import java.applet.* ;
- import javax.swing.* ;
- import java.awt.event.* ;
- import javax.swing.event.* ;
- import java.awt.Component;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.WindowConstants;
- import javax.swing.BorderFactory;
- import java.awt.Dimension;
- class OnePlayerGame extends JFrame implements ActionListener {
- Container contentPane = getContentPane() ;
- JPanel OnePlayerPnl = new JPanel( ) ;
- JPanel centerGrid = new JPanel (new GridLayout (4,4,-100,-190));
- ImageIcon whiteSquarePic = new ImageIcon( "white_Square.png" ) ; // Locate the menu image and assign it to a variable
- ImageIcon redSquarePic = new ImageIcon ( "red_Square.png" ) ;
- ImageIcon blueSquarePic = new ImageIcon( "blue_Square.png" ) ;
- ImageIcon blackCirclePic = new ImageIcon( "black_circle.png" ) ;
- JButton whiteSquare0 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare1 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare2 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare3 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare4 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare5 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare6 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare7 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare8 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare9 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare10 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare11 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare12 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare13 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare14 = new JButton( whiteSquarePic ) ;
- JButton whiteSquare15 = new JButton( whiteSquarePic ) ;
- JLabel redSquare = new JLabel( redSquarePic ) ;
- JLabel blueSquare = new JLabel( blueSquarePic ) ;
- JLabel blackCircle = new JLabel( blackCirclePic ) ;
- int gridArray[][] =
- {
- {0, 3},
- {1, 2},
- {2, 2},
- {3, 3},
- {4, 2},
- {5, 1},
- {6, 1},
- {7, 2},
- {8, 2},
- {9, 1},
- {10, 1},
- {11, 2},
- {12, 3},
- {13, 2},
- {14, 2},
- {15, 3},
- };
- boolean PlayerOneTurn = true ;
- public OnePlayerGame()
- {
- super ( "OnePlayerGame" ) ;
- setSize( 500, 600 ) ;
- setResizable( false );
- setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
- add( OnePlayerPnl ) ;
- centerGrid.add ( whiteSquare0 );
- centerGrid.add ( whiteSquare1 );
- centerGrid.add ( whiteSquare2 );
- centerGrid.add ( whiteSquare3 );
- centerGrid.add ( whiteSquare4 );
- centerGrid.add ( whiteSquare5 );
- centerGrid.add ( whiteSquare6 );
- centerGrid.add ( whiteSquare7 );
- centerGrid.add ( whiteSquare8 );
- centerGrid.add ( whiteSquare9 );
- centerGrid.add ( whiteSquare10 );
- centerGrid.add ( whiteSquare11 );
- centerGrid.add ( whiteSquare12 );
- centerGrid.add ( whiteSquare13 );
- centerGrid.add ( whiteSquare14 );
- centerGrid.add ( whiteSquare15 );
- // whiteSquare0.setBackground(null);
- // whiteSquare0.setBorder(null);
- // whiteSquare0.setBorderPainted(false);
- // whiteSquare0.setContentAreaFilled(false);
- // whiteSquare0.setOpaque(true);
- // whiteSquare0.setFocusPainted(false);
- // whiteSquare0.setBackground(BackgroundFactory.createEmptyBackground());
- whiteSquare0.setSize (size.width, size.height);
- whiteSquare1.setBackground(null);
- whiteSquare1.setBorder(null);
- whiteSquare1.setBorderPainted(false);
- whiteSquare1.setContentAreaFilled(false);
- whiteSquare2.setBackground(null);
- whiteSquare2.setBorder(null);
- whiteSquare2.setBorderPainted(false);
- whiteSquare2.setContentAreaFilled(false);
- whiteSquare3.setBackground(null);
- whiteSquare3.setBorder(null);
- whiteSquare3.setBorderPainted(false);
- whiteSquare3.setContentAreaFilled(false);
- whiteSquare4.setBackground(null);
- whiteSquare4.setBorder(null);
- whiteSquare4.setBorderPainted(false);
- whiteSquare4.setContentAreaFilled(false);
- whiteSquare5.setBackground(null);
- whiteSquare5.setBorder(null);
- whiteSquare5.setBorderPainted(false);
- whiteSquare5.setContentAreaFilled(false);
- whiteSquare6.setBackground(null);
- whiteSquare6.setBorder(null);
- whiteSquare6.setBorderPainted(false);
- whiteSquare6.setContentAreaFilled(false);
- whiteSquare7.setBackground(null);
- whiteSquare7.setBorder(null);
- whiteSquare7.setBorderPainted(false);
- whiteSquare7.setContentAreaFilled(false);
- whiteSquare8.setBackground(null);
- whiteSquare8.setBorder(null);
- whiteSquare8.setBorderPainted(false);
- whiteSquare8.setContentAreaFilled(false);
- whiteSquare9.setBackground(null);
- whiteSquare9.setBorder(null);
- whiteSquare9.setBorderPainted(false);
- whiteSquare9.setContentAreaFilled(false);
- whiteSquare10.setBackground(null);
- whiteSquare10.setBorder(null);
- whiteSquare10.setBorderPainted(false);
- whiteSquare10.setContentAreaFilled(false);
- whiteSquare11.setBackground(null);
- whiteSquare11.setBorder(null);
- whiteSquare11.setBorderPainted(false);
- whiteSquare11.setContentAreaFilled(false);
- whiteSquare12.setBackground(null);
- whiteSquare12.setBorder(null);
- whiteSquare12.setBorderPainted(false);
- whiteSquare12.setContentAreaFilled(false);
- whiteSquare13.setBackground(null);
- whiteSquare13.setBorder(null);
- whiteSquare13.setBorderPainted(false);
- whiteSquare13.setContentAreaFilled(false);
- whiteSquare14.setBackground(null);
- whiteSquare14.setBorder(null);
- whiteSquare14.setBorderPainted(false);
- whiteSquare14.setContentAreaFilled(false);
- whiteSquare15.setBackground(null);
- whiteSquare15.setBorder(null);
- whiteSquare15.setBorderPainted(false);
- whiteSquare15.setContentAreaFilled(false);
- contentPane.add("Center", centerGrid );
- whiteSquare0.addActionListener ( this );
- whiteSquare1.addActionListener ( this );
- whiteSquare2.addActionListener ( this );
- whiteSquare3.addActionListener ( this );
- whiteSquare4.addActionListener ( this );
- whiteSquare5.addActionListener ( this );
- whiteSquare6.addActionListener ( this );
- whiteSquare7.addActionListener ( this );
- whiteSquare8.addActionListener ( this );
- whiteSquare9.addActionListener ( this );
- whiteSquare10.addActionListener ( this );
- whiteSquare11.addActionListener ( this );
- whiteSquare12.addActionListener ( this );
- whiteSquare13.addActionListener ( this );
- whiteSquare14.addActionListener ( this );
- whiteSquare15.addActionListener ( this );
- setVisible( true ) ;
- }
- public void actionPerformed ( ActionEvent event )
- {
- if ( event.getSource() == whiteSquare0 )
- {
- if ( PlayerOneTurn == true ) whiteSquare0.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare0.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare1 )
- {
- if ( PlayerOneTurn == true ) whiteSquare1.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare1.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare2 )
- {
- if ( PlayerOneTurn == true ) whiteSquare2.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare2.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare3 )
- {
- if ( PlayerOneTurn == true ) whiteSquare3.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare3.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare4 )
- {
- if ( PlayerOneTurn == true ) whiteSquare4.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare4.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare5 )
- {
- if ( PlayerOneTurn == true ) whiteSquare5.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare5.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare6 )
- {
- if ( PlayerOneTurn == true ) whiteSquare6.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare6.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare7 )
- {
- if ( PlayerOneTurn == true ) whiteSquare7.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare7.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare8 )
- {
- if ( PlayerOneTurn == true ) whiteSquare8.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare8.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare8 )
- {
- if ( PlayerOneTurn == true ) whiteSquare9.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare9.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare10 )
- {
- if ( PlayerOneTurn == true ) whiteSquare10.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare10.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare11 )
- {
- if ( PlayerOneTurn == true ) whiteSquare11.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare11.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare12 )
- {
- if ( PlayerOneTurn == true ) whiteSquare12.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare12.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare13 )
- {
- if ( PlayerOneTurn == true ) whiteSquare13.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare13.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare14 )
- {
- if ( PlayerOneTurn == true ) whiteSquare14.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare14.setIcon( blueSquarePic ) ;
- }
- if ( event.getSource() == whiteSquare15 )
- {
- if ( PlayerOneTurn == true ) whiteSquare15.setIcon( redSquarePic );
- if ( PlayerOneTurn == false ) whiteSquare15.setIcon( blueSquarePic ) ;
- }
- }
- public static void main (String[] args)
- {
- OnePlayerGame gui = new OnePlayerGame() ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement