im trying to call a method in my main class (GUI) from a different class (ActionHandeler)
heres the method in GUI:
public static void main(String[] args) { // Schedule a job for the event dispatch thread: // creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { GUI gui = new GUI(); // Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); gui.launchFrame(); action.actionPerformed(null); } }); }
here is 'actionPerformed' in ActionHandeler:
@Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd != null) { if (cmd.equals("submit")) { try { int guessed; String input = g.type.getText(); int value = random(10); guessed = Integer.parseInt(input); if (guessed < 1 || guessed > 10) { JOptionPane.showMessageDialog(null, guessed + " is not a valid number!"); } else if (guessed == value) { JOptionPane.showMessageDialog(null, "You guessed it right! :D"); wins += 1; } else { JOptionPane.showMessageDialog(null, "Sorry the correct awenser was " + value + ". :/"); losses += 1; } } catch (Exception e1) { } } } }
I know that the parameters cant equal 'null'
I tried making it 'e' and 'ActionEvent' but its not workingaction.actionPerformed(null);
any help would be appreciated!