I have created main menu, after selecting start new game, user must select weapon (ex. dagger with JButton), this is how it looks:
public class GUI {
public GUI() {
initGUI();
}
public void initGUI {
(..................some methods.........................)
final JButton newGame = new JButton(new ImageIcon(..));
newGame.setLocation(250, 420);
content.add(newGame);
final JButton buttonDagger = new JButton(new ImageIcon(..));
buttonDagger.setLocation(250, 420);
content.add(buttonDagger);
class NewGameAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
newGame.setVisible(false);
daggerButton.setVisible(true);
frame.add(new Barracks());
}
}
class DaggerAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
daggerButton.setVisible(false);
Weapon w = new Weapon("Dagger", 3, 8, 5);
frame.add(new Arena());
}
}
buttonDagger.addActionListener(new DaggerAction());
newGame.addActionListener(new NewGameAction());
}
}
Class DaggerAction is inside initGUI function, is an initialization of daggerButton, after clicking on that, dagger must be created. So my problem is, how I can reach that Weapon w object? Or maybe there is an option to create it's copy somewhere during DaggerAction initialization? Or maybe there is an other way to initialize such select thigs? I will really appreciate your help, thanks. GUI is the main class which handle all the graphics. And I want to appear weapon object in Barracks class, which is initialized after starting new game.






