Okay, so I am attempting to make a Flash cards program, and I want it to be that when the Add Set (or new deck of cards) is clicked, it will add a button to represent the set at the bottom of the frame.
What I have now will only show the button after the frame is resized. I don't really know what I'm doing with the panel, as I haven't figured out how to properly lay out all the parts yet.
I need the program to show the set icon in the bottom panel after the set it made.
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GraphicsUI extends JPanel {
private DeckList setsList;
CardActions action = new CardActions();
JButton addSetButton, addCardButton;
private JLabel label;
private JPanel bottomPanel;
public GraphicsUI(){
this.setPreferredSize(new Dimension(1000,825));
this.setBackground(Color.LIGHT_GRAY);
this.label = new JLabel();
label.setOpaque(true);
label.setBackground(Color.white);
label.setPreferredSize(new Dimension(600, 400));
ImageIcon img = new ImageIcon("setIcon.png");
//make that set image at bottom
this.addSetButton = new JButton("Add Set");
// this.addSetButton.setBackground(Color.white);
// this.addSetButton.setPreferredSize(new Dimension(240, 180));
this.add(addSetButton, BorderLayout.WEST);
this.addSetButton.addActionListener(new ButtonListener());
this.addCardButton = new JButton("Add Card");
// this.addCardButton
this.add(label);
JLabel blah = new JLabel();
blah.setPreferredSize(new Dimension(1000,30));
this.add(blah);
this.bottomPanel = new JPanel();
this.bottomPanel.setPreferredSize(new Dimension(1000, 400));
this.add(bottomPanel);
}
public class ButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
action.setCommand(CardActions.Command.ADDSET);
action.setList(getSetInfo());
}
}
private CardList getSetInfo(){
CardList cl = new CardList();
String setName = JOptionPane.showInputDialog("Enter the name of your set.");
if(setName.isEmpty()){
JOptionPane.showMessageDialog(this, "Cannot have an empty set.");
}
cl.setSetName(setName);
ImageIcon img = new ImageIcon("setIcon.png");
bottomPanel.add(new JButton(img));
return cl;
}
}