I need to make multiple action listeners for 4 radio buttons and a regular button. They all need to call different methods from another class
I currently have
Import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CardGameCH15 extends JFrame
{
public CardGameCH15()
{
super("Card Game");
add(new CardTable());
}
public static void main(String[] args)
{
CardGameCH15 frame = new CardGameCH15();
frame.setSize(500,200);
frame.setTitle("Card Game");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class CardTable extends JPanel implements ActionListener
{
String card;
ImageIcon cardIcon;
JButton dealButton = new JButton("Deal 5");
CardDeck deck;
JLabel card1 = new JLabel("");
JLabel card2 = new JLabel("");
JLabel card3 = new JLabel("");
JLabel card4 = new JLabel("");
JLabel card5 = new JLabel("");
JRadioButton jrb1 = new JRadioButton("1 Deck");
JRadioButton jrb2 = new JRadioButton("2 Decks");
JRadioButton jrb3 = new JRadioButton("3 Decks");
JRadioButton jrb4 = new JRadioButton("4 Decks");
public CardTable()
{
setLayout(new FlowLayout());
deck = new CardDeck(1);
dealHand();
add(card1);
add(card2);
add(card3);
add(card4);
add(card5);
add(dealButton);
add(jrb1);
add(jrb2);
add(jrb3);
add(jrb4);
}
dealButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dealHand();
}
});
THE ABOVE ACTION LISTENER IS NOT WORKING, IS THERE ANOTHER WAY OF WRITING MULTIPLE ACTION LISTENERS OR DID I MAKE A SYNTAX ERROR
private void dealHand()
{
String str;
if((str = deck.getCard()) != null)
card1.setIcon(new ImageIcon("image/card/" + str));
else
return;
if((str = deck.getCard()) != null)
card2.setIcon(new ImageIcon("image/card/" + str));
else
return;
if((str = deck.getCard()) != null)
card3.setIcon(new ImageIcon("image/card/" + str));
else
return;
if((str = deck.getCard()) != null)
card4.setIcon(new ImageIcon("image/card/" + str));
else
return;
if((str = deck.getCard()) != null)
card5.setIcon(new ImageIcon("image/card/" + str));
else
return;
}
}
}
I would appreciate any help...Thanks in advance