Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class aaaaaaaaaaaaa extends JFrame {
- private JPanel contentPane;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- aaaaaaaaaaaaa frame = new aaaaaaaaaaaaa();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public aaaaaaaaaaaaa() {
- boolean jogador = true;
- setTitle("Jogo da Velha");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 434, 350);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- final JButton b1 = new JButton("");
- b1.setBackground(SystemColor.menu);
- b1.setBounds(10, 11, 107, 61);
- contentPane.add(b1);
- final JButton b2 = new JButton("");
- b2.setBackground(SystemColor.menu);
- b2.setBounds(145, 11, 107, 61);
- contentPane.add(b2);
- final JButton b3 = new JButton("");
- b3.setBackground(SystemColor.menu);
- b3.setBounds(281, 11, 107, 61);
- contentPane.add(b3);
- final JButton b4 = new JButton("");
- b4.setBackground(SystemColor.menu);
- b4.setBounds(281, 95, 107, 61);
- contentPane.add(b4);
- final JButton b5 = new JButton("");
- b5.setBackground(SystemColor.menu);
- b5.setBounds(145, 95, 107, 61);
- contentPane.add(b5);
- final JButton b6 = new JButton("");
- b6.setBackground(SystemColor.menu);
- b6.setBounds(10, 95, 107, 61);
- contentPane.add(b6);
- final JButton b7 = new JButton("");
- b7.setBackground(SystemColor.menu);
- b7.setBounds(10, 175, 107, 61);
- contentPane.add(b7);
- final JButton b8 = new JButton("");
- b8.setBackground(SystemColor.menu);
- b8.setBounds(145, 175, 107, 61);
- contentPane.add(b8);
- final JButton b9 = new JButton("");
- b9.setBackground(SystemColor.menu);
- b9.setBounds(281, 175, 107, 61);
- contentPane.add(b9);
- if(jogador == true ){
- jogador =! jogador;
- // B1
- b1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b1.setText("X");
- }
- });
- // B2
- b2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b2.setText("X");
- }
- });
- // B3
- b3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b3.setText("X");
- }
- });
- // B4
- b4.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b4.setText("X");
- }
- });
- // B5
- b5.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b5.setText("X");
- }
- });
- // B6
- b6.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b6.setText("X");
- }
- });
- // B7
- b7.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b7.setText("X");
- }
- });
- // B8
- b8.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b8.setText("X");
- }
- });
- // B9
- b9.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b9.setText("X");
- }
- });
- }
- if(jogador != true){
- jogador =! jogador;
- b1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b1.setText("O");
- }
- });
- // B2
- b2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b2.setText("O");
- }
- });
- // B3
- b3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b3.setText("O");
- }
- });
- // B4
- b4.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b4.setText("O");
- }
- });
- // B5
- b5.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b5.setText("O");
- }
- });
- // B6
- b6.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b6.setText("O");
- }
- });
- // B7
- b7.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b7.setText("O");
- }
- });
- // B8
- b8.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b8.setText("O");
- }
- });
- // B9
- b9.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- b9.setText("O");
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment