Been researching around and looking at many answers but have had no luck.
public class GUIinput extends JFrame{
//Num is the JTextfield variable used for later.
public JTextField num;
public JButton button;
public void test(){
//JPanel
JPanel panel = new JPanel();
//Welcome JLabel..Contains the welcome message.
JLabel welcome = new JLabel("Welcome to my Grade Calculator program!");
panel.add(welcome);
//Instructions J Label on how to work the program.
JLabel instructions = new JLabel("Enter your Mark and Weight to find your average grade!");
panel.add(instructions);
//JLabel---How many different assignments do the user want to evaluate?
JLabel number = new JLabel("<html><br>Firstly, please enter how many assignments/exams you want to evaluate?</html>");
panel.add(number);
//JTextField assigner.
num = new JTextField(18);
panel.add(num);
//Enter button
button = new JButton("Enter");
panel.add(button);
//JFrame maker.
setTitle("Grade Calculator");
setSize(575,250);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(panel);
//This action listener opens the new class Gradeanalysis(). The next window.
button.addActionListener(new Gradeanalysis());
//Action listener for the Textfield in case the user presses the enter key.
num.addActionListener(new Gradeanalysis());
}
public static void main(String[] args) {
new GUIinput().test();
}
}
This class is for the first window of the program. The program ask the user to enter a value which gets sent to another class. (Grade analysis).
public class Gradeanalysis extends GUIinput implements ActionListener{
@Override
public void actionPerformed (ActionEvent e){
int messageType = JOptionPane.PLAIN_MESSAGE;
/*ERROR IS HERE---*/JOptionPane.showMessageDialog(null,num.getText(),"fasfa",messageType);
JFrame frame = new JFrame("Grade Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(createMainPanel());
frame.pack();
frame.setVisible(true);
}
Now I cut a lot of code out which is not needed. So what the program should do is get the user input from the first window and when the user clicks the enter button the input should be displayed on a MessageDialog screen. Not the new JFrame.
Now I understand the problem is because of that line with the asterisks espically the "num.getText()" section.
If i add "num = new JTextField();" above that line the MessageDialog screen will be blank. I want it to display the input from the previous screen.
Have no clue how to go about this. Appreciate all help, thanks.