Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import java.awt.Color;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- public class Window extends JFrame implements ActionListener {
- JButton button1, button2, button3, button4, button5, button6, button7, button8, button9;
- JLabel label;
- public Window() {
- setSize(420,400);
- setTitle("Tic Tac Toe");
- setLayout(null);
- label = new JLabel("Please choice your position!");
- label.setBounds(150,2,200,50);
- add(label);
- button1 = new JButton("HERE");
- button1.setBounds(50,50,80,80);
- button1.addActionListener(this);
- add(button1);
- button2 = new JButton("HERE");
- button2.setBounds(150,50,80,80);
- add(button2);
- button3 = new JButton("HERE");
- button3.setBounds(250,50,80,80);
- add(button3);
- button4 = new JButton("HERE");
- button4.setBounds(50,150,80,80);
- add(button4);
- button5 = new JButton("HERE");
- button5.setBounds(150,150,80,80);
- add(button5);
- button6 = new JButton("HERE");
- button6.setBounds(250,150,80,80);
- add(button6);
- button7 = new JButton("HERE");
- button7.setBounds(50,250,80,80);
- add(button7);
- button8 = new JButton("HERE");
- button8.setBounds(150,250,80,80);
- add(button8);
- button9 = new JButton("HERE");
- button9.setBounds(250,250,80,80);
- add(button9);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if(source == button1) {
- if(TicTacToe.addCharacterUser(1,1)) {
- button1.setForeground(Color.RED);
- } else {
- label.setText("This position is occupied!");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment