Here's the code in it's most simplistic way:-
//v 1.3
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
// This example demonstrates the use of JButton, JTextField
// and JLabel.
public class LunarPhases implements ActionListener {
JPanel mainPanel, selectPanel, displayPanel, buttonPanel;
JComboBox phaseChoices = null;
JLabel phaseIconLabel = null;
JTextField tf = new JTextField(""
JButton myButton = new JButton("Andy"
// Constructor
public LunarPhases() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
// Add various widgets to the sub panels.
addWidgets();
// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(3,1,5,5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
mainPanel.add(buttonPanel);
myButton.setToolTipText("Click to exit"
}
buttonPanel.add(myButton);
tf.setColumns(20);
buttonPanel.add(tf);
ButtonHandler handler = new ButtonHandler();
myButton.addActionListener(handler);
// Listen to events from combo box.
phaseChoices.addActionListener(this);
}
// main method
public static void main(String[] args) {
// create a new instance of LunarPhases
LunarPhases phases = new LunarPhases();
// Create a frame and container for the panels.
JFrame lunarPhasesFrame = new JFrame("Lunar Phases"
// Set the look and feel.
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {}
lunarPhasesFrame.setContentPane(phases.mainPanel);
// Exit when the window is closed.
lunarPhasesFrame.setDefaultCloseOperation Frame.HIDE_ON_CLOSE);
// Show the converter.
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Assessment3 ass = new Assessment3();
JFrame newFrame = new JFrame("Andy"
newFrame.setContentPane(ass.mainPanel);
lunarPhasesFrame.setVisible(false);
newFrame.pack();
newFrame.setVisible(true);
}
}
}
//v 1.3
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
// This example demonstrates the use of JButton, JTextField
// and JLabel.
public class LunarPhases implements ActionListener {
JPanel mainPanel, selectPanel, displayPanel, buttonPanel;
JComboBox phaseChoices = null;
JLabel phaseIconLabel = null;
JTextField tf = new JTextField(""
JButton myButton = new JButton("Andy"
// Constructor
public LunarPhases() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
// Add various widgets to the sub panels.
addWidgets();
// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(3,1,5,5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
mainPanel.add(buttonPanel);
myButton.setToolTipText("Click to exit"
}
buttonPanel.add(myButton);
tf.setColumns(20);
buttonPanel.add(tf);
ButtonHandler handler = new ButtonHandler();
myButton.addActionListener(handler);
// Listen to events from combo box.
phaseChoices.addActionListener(this);
}
// main method
public static void main(String[] args) {
// create a new instance of LunarPhases
LunarPhases phases = new LunarPhases();
// Create a frame and container for the panels.
JFrame lunarPhasesFrame = new JFrame("Lunar Phases"
// Set the look and feel.
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {}
lunarPhasesFrame.setContentPane(phases.mainPanel);
// Exit when the window is closed.
lunarPhasesFrame.setDefaultCloseOperation Frame.HIDE_ON_CLOSE);
// Show the converter.
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Assessment3 ass = new Assessment3();
JFrame newFrame = new JFrame("Andy"
newFrame.setContentPane(ass.mainPanel);
lunarPhasesFrame.setVisible(false);
newFrame.pack();
newFrame.setVisible(true);
}
}
}