I currently have a panel with 4 buttons on it. (New Game, Load Game, Settings, Exit). When the user clicks "New Game" they are prompted to enter a Username, Class, and Race. When the user hits 'Ok' after entering in the information, I would like for another panel to pop up with more options on it, but I'm having some trouble making it do that. And knowing me, I'm probably just making a bonehead mistake and not seeing it.
It's kind of hard to explain this so I'll just post my current code;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
public class WarlogHunter extends JFrame
{
public WarlogHunter() throws NumberFormatException
{
player = new ArrayList();
class addButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(player.size() > 0)
{
JOptionPane.showMessageDialog(null, "Error - Please exit your current game before starting a new one.");
}
else
{
AddPanel ap = new AddPanel(appbook);
ap.setTitle("New Game");
ap.show();
}
}
}
class deleteButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
{
JOptionPane.showMessageDialog(null, "Error - No saved games found.");
return;
}
}
}
class cancelButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "Settings unavailable.");
}
}
class exitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
appbook = this;
int numPlayers = 0;
newGame = new JButton("New Game");
ActionListener addListener = new addButtonListener();
newGame.addActionListener(addListener);
load = new JButton("Load Game");
ActionListener delListener = new deleteButtonListener();
load.addActionListener(delListener);
settings = new JButton("Settings");
ActionListener cancelListener = new cancelButtonListener();
settings.addActionListener(cancelListener);
exit = new JButton("Exit");
ActionListener exitListener = new exitButtonListener();
exit.addActionListener(exitListener);
appointments = new JTextArea();
appointments.setLineWrap(true);
appointments.setEditable(false);
JPanel northPanel = new JPanel();
northPanel.add(newGame);
northPanel.add(load);
northPanel.add(settings);
northPanel.add(exit);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(1,4));
northPanel.setPreferredSize(new Dimension(575,35));
centerPanel.setPreferredSize(new Dimension(575,150));
getContentPane().add(northPanel, BorderLayout.NORTH);
getContentPane().add(centerPanel, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
ImageIcon icon = new ImageIcon("warlog.jpg");
JLabel label = new JLabel();
label.setIcon(icon);
centerPanel.add(label);
northPanel.setBackground(Color.BLACK);
this.getContentPane().add(centerPanel);
setVisible(true);
}
class adventureButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
//code for adventure, dont worry about this
}
}
public void addGame(NewGame a)
{
player.add(a);
if(player.size() > 0)
{
//code for new panel..?
}
}
public static void main(String[] args)
{
WarlogHunter ab = new WarlogHunter();
ab.setTitle("Warlog Hunter - ALPHA");
ab.setSize(368,256);
ab.setResizable(false);
ab.setDefaultLookAndFeelDecorated(true);
ab.show();
}
private JButton adventureTime;
private Image warlog;
private JButton newGame;
private JButton load;
private JButton settings;
private JButton exit;
private JTextArea appointments;
private ArrayList player;
private WarlogHunter appbook;
}Specificallypublic void addGame(NewGame a)
{
player.add(a);
if(player.size() > 0)
{
//code for new panel..?
}
}^Would this be an acceptable way of testing to see if I should open a new panel? I've tested it with other things (System.out.println, JOptionPane.showMessageDialog) and those pop up right after I hit "Ok"... so I must be doing something wrong.I've been trying something like this;
public void addGame(NewGame a)
{
player.add(a);
if(player.size() > 0)
{
JPanel adventurePanel = new JPanel();
adventureTime = new JButton("Go Adventure!");
ActionListener adventureListener = new adventureButtonListener();
adventureTime.addActionListener(adventureListener);
adventurePanel.add(adventureTime);
adventurePanel.setVisible(true);
}
}That compiles but when I hit "Ok" nothing happens....I basically just need a new panel with a "Go Adventure!" button and an "Exit" button on. (maybe a sleep button (for saving a game? idek if you can do that)).
Anyway, any help would be appreciated. I do have other classes in my program but I don't think they would help that much.
-Koola1d


Sign In
Create Account

Back to top









