Guest User

java

a guest
Sep 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3.  
  4. import java.awt.Color;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9.  
  10.  
  11. public class Window extends JFrame implements ActionListener {
  12.    
  13.     JButton button1, button2, button3, button4, button5, button6, button7, button8, button9;
  14.     JLabel label;
  15.    
  16.     public Window() {
  17.         setSize(420,400);
  18.         setTitle("Tic Tac Toe");
  19.         setLayout(null);
  20.        
  21.         label = new JLabel("Please choice your position!");
  22.         label.setBounds(150,2,200,50);
  23.         add(label);
  24.        
  25.         button1 = new JButton("HERE");
  26.         button1.setBounds(50,50,80,80);
  27.         button1.addActionListener(this);
  28.         add(button1);
  29.        
  30.         button2 = new JButton("HERE");
  31.         button2.setBounds(150,50,80,80);
  32.         add(button2);
  33.        
  34.         button3 = new JButton("HERE");
  35.         button3.setBounds(250,50,80,80);
  36.         add(button3);
  37.        
  38.         button4 = new JButton("HERE");
  39.         button4.setBounds(50,150,80,80);
  40.         add(button4);
  41.        
  42.         button5 = new JButton("HERE");
  43.         button5.setBounds(150,150,80,80);
  44.         add(button5);
  45.        
  46.         button6 = new JButton("HERE");
  47.         button6.setBounds(250,150,80,80);
  48.         add(button6);
  49.        
  50.         button7 = new JButton("HERE");
  51.         button7.setBounds(50,250,80,80);
  52.         add(button7);
  53.        
  54.         button8 = new JButton("HERE");
  55.         button8.setBounds(150,250,80,80);
  56.         add(button8);
  57.        
  58.         button9 = new JButton("HERE");
  59.         button9.setBounds(250,250,80,80);
  60.         add(button9);
  61.        
  62.     }
  63.  
  64.     @Override
  65.     public void actionPerformed(ActionEvent e) {
  66.  
  67.         Object source = e.getSource();
  68.        
  69.         if(source == button1) {
  70.             if(TicTacToe.addCharacterUser(1,1)) {
  71.                 button1.setForeground(Color.RED);
  72.             } else {
  73.                 label.setText("This position is occupied!");
  74.             }
  75.         }
  76.        
  77.     }
  78.    
  79. }
Add Comment
Please, Sign In to add comment