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();
			}
		}

		);
	}

}

You don't run the programs, you call the methods. If the other programs are inside a main, then take that code and declare it as a method and call the method. For arguments, You might want to add some JTextFields. Check the API for JTextFields.

An example on how to do that thing with the main:

public static void main(String [] args) {
     [B]int a = 5;
     int b = 4;[/B]
     [B]int sum = a + b;[/B]
     System.out.println("Sum = "+sum);
}

Should be:

public class SomeUtilities {
    public static int getSum([B]int a, int b[/B]) {
        [B]int sum = a + b;[/B]
        return [B]sum[/B];
   }
}

At your "swing" code, you call the methods from the other classes. If you don't know how to do that I suggest you study some more on how to call and declare methods.

You don't run the programs, you call the methods. If the other programs are inside a main, then take that code and declare it as a method and call the method. For arguments, You might want to add some JTextFields. Check the API for JTextFields.

At your "swing" code, you call the methods from the other classes. If you don't know how to do that I suggest you study some more on how to call and declare methods.

I know how to run, and maybe that is a bad way to word it, other methods... my "calculate" button calls on the "calculator" method to do the match and come back with the numbers...

but my big problem I guess is making so that if I click one of those buttons on that first piece of code that I put up, that it then hides/closes/whatever the menu window(frame) and opens up a new frame/window with all of the proper GUI and calculations.

Alternatively "clearing" the current frame and replacing that GUI with the GUI I used in the other programs would work as well.

This article has been dead for over six months. Start a new discussion instead.