Hi guys,
I'm having trouble with my code and I'm kind of new in Java so I don't know what to do. I have to do a program with Buttons and each button has to take me to another class (I don't know if I'm being clear). For example if I click the button "Bingo" my class named Bingo (which I already have) should run but I don't know how to do that.
Here's my code:
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
public class GameFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
JFrame tablero=new JFrame();
JButton Bingo=new JButton("Bingo");
JButton Adivina=new JButton("Adivina Palabras");
JButton Black=new JButton("Blackjack");
JLabel t=new JLabel(" Bienvenido al Casino. Elige lo que quieras jugar:");
public GameFrame() {
setTitle("Casino");
setLayout(new GridLayout(5, 2, 20, 3));
add(t);
add(new JLabel (""));
add(new JLabel (""));
add(new JLabel (""));
add (Bingo);
Bingo.addActionListener(this);
add (Adivina);
Adivina.addActionListener(this);
add (Black);
Black.addActionListener(this);
pack();
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == Bingo){
new Bingo();
}else{
if(e.getSource() == Adivina){
new Adivinar();
}else{
new Blackjack();
}
}
}
}