Hard to explain. Deals with frames and Action Listener
Cameron Schultz
Greenhorn
Joined: May 08, 2006
Posts: 1
posted
0
Heres my problem: The getChoice method (OptionDialogFrame1 class) is called before i can select a radio button. How can i make it so i have time to choose a radio button before the value is returned? The below code compiles correctly, you can copy/paste it into a code writing program.
// Add action listener.for the menu button menuFileExit.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { IronTomRedFrame.this.windowClosed(); } } ); menuFileNew.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) {
String userName = JOptionPane.showInputDialog("Enter Ye Name, Mate!"); int island=0;
String islandLocation="x"; int villageLocation=0; int harborLocation=0; int islandLodgingOption=0; int pubOption=0; JOptionPane.showMessageDialog(null,"Story Frame 1","What to do with your scummy self...",JOptionPane.PLAIN_MESSAGE,new ImageIcon("G:\\IronTomRed\\src\\icon.gif")); JOptionPane.showMessageDialog(null,"Story Frame 2","What to do with your scummy self...",JOptionPane.PLAIN_MESSAGE,new ImageIcon("G:\\IronTomRed\\src\\icon.gif")); JOptionPane.showMessageDialog(null,"Story Frame 3","What to do with your scummy self...",JOptionPane.PLAIN_MESSAGE,new ImageIcon("G:\\IronTomRed\\src\\icon.gif")); ButtonPanel islandOneOptions = new ButtonPanel("Island 1 Options!",new String[]{"Shipyard","Village"}); OptionDialogFrame1 islandOne = new OptionDialogFrame1("Welcome To Island One",islandOneOptions); islandOne.show(); islandLocation = islandOne.getChoice(); if(islandLocation.equals("Village")){ ButtonPanel villageOptions = new ButtonPanel("Village Options!",new String[]{"Pub","Blacksmith","Stupidity"}); OptionDialogFrame1 villageOne = new OptionDialogFrame1("Welcome to the village!",villageOptions); villageOne.show(); islandOne.hide(); } if(islandLocation.equals("Shipyard")){ //ButtonPanel villageOptions = new ButtonPanel("Shipyard Options!",new String[]{"xxx","xxx","Stupidity"}); //OptionDialogFrame villageOne = new OptionDialogFrame("Welcome to the village!",villageOptions); //villageOne.show(); //islandOne.hide(); } System.out.println(islandLocation); }
} ); menuFileLoad.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { //old game loaded } } ); menuHelpHelp.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null,"Instructions for yon game.","What to do with your scummy self...",JOptionPane.PLAIN_MESSAGE,new ImageIcon("G:\\IronTomRed\\src\\icon.gif")); } } ); menuHelpAbout.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null,"Written by Benson "+'\n'+"Cameron "+'\n'+"Ben "+'\n'+"and Kenneth, the First Jew-Pirate ever Invented","Pay homage to thine infinitely betters...",JOptionPane.PLAIN_MESSAGE,new ImageIcon("G:\\IronTomRed\\src\\icon.gif")); } } ); menuFile.add(menuFileNew); menuFile.add(menuFileLoad); menuFile.add(menuFileExit);