OK... so I am pretty new to Java and need some help.
I'll try to explain as best I can... I am trying to create a frame that will be a "menu frame" and then based on which option the user picks (JButton) it will then run the version of the program they have picked.
So first window is just a menu with 3 buttons: Version 1, Version 2, and EXIT.
What is the best way to implement this?
I know I don't know much... but how do I get the other 2 programs I have already written in here and linked to the buttons I created?
(the other 2 programs fill the same size frame) Right now the buttons just exit out of the program as a placeholder.
Any help would be appreciated.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.text.DecimalFormat;
public class choiceMenu extends JPanel{
//Variables
private JLabel choiceLabel;
private JButton exitButton, v1Button, v2Button;
public choiceMenu()
{
//Header Label
choiceLabel = new JLabel (" *Please Choose A Method* ");
//create the reset button
v1Button = new JButton("Version 1: User Defined Terms & Rates");
v1Button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
//create the exit button
v2Button = new JButton (" Version 2: Preset Terms & Rates ");
v2Button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
//create the exit button
exitButton = new JButton (" EXIT PROGRAM ");
exitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
//labels & fields
add(choiceLabel);
add(v1Button);
add(v2Button);
add(exitButton);
}
private static void createAndShowGui()
{
JFrame frame = new JFrame("Mortgage Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
choiceMenu calculator = new choiceMenu();
frame.setContentPane(calculator);
frame.setSize(425,550);
frame.setVisible(true);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
createAndShowGui();
}
}
);
}
}