/* This is a converter program * */ import javax.swing.*; import java.awt.event.*; import java.awt.*; public class ConvertSelection extends JFrame { private JPanel panel; private JButton Length; private JButton Weight; private JButton Volume; private JButton Temp; private JButton exit; private boolean value = true; public ConvertSelection() { // Sets the title of the window setTitle("Convertion"); // Sets the size of the window setSize(250, 280); // Sets the start location of the window setLocationRelativeTo(null); // Sets the action if the window is close setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Creates a JPanel panel = new JPanel(); // Create the buttons Length = new JButton("Length"); Weight = new JButton("Weight"); Volume = new JButton("Volume"); Temp = new JButton("Temperature"); exit = new JButton("Exit"); // Create button listeners Length.addActionListener(new ButtonListener()); Weight.addActionListener(new ButtonListener()); Volume.addActionListener(new ButtonListener()); Temp.addActionListener(new ButtonListener()); exit.addActionListener(new ButtonListener()); // Creates a vertical box layout Box box = Box.createVerticalBox(); // Adds the button to the vertical box box.add(Length); // Creates a space between the components box.add(Box.createVerticalStrut(20)); box.add(Weight); // Creates a space between the components box.add(Box.createVerticalStrut(20)); box.add(Volume); // Creates a space between the components box.add(Box.createVerticalStrut(20)); box.add(Temp); // Creates a space between the components box.add(Box.createVerticalStrut(20)); box.add(exit); // Adds the box to the panel panel.add(box); // Adds the panel to the content pane add(panel); // Sets the window to be visible setVisible(value); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { try { /* If the length button is pushed Call the length class and set The visibility of this frame to be false * */ if(e.getSource()==Length) { value = false; setVisible(value); new ConvertLength(); } /* If the weight button is pushed Call the weight class and set The visibility of this frame to be false * */ if(e.getSource()==Weight) { value = false; setVisible(value); new ConvertWeight(); } /* If the volume button is pushed Call the volume class and set The visibility of this frame to be false * */ if(e.getSource()==Volume) { value = false; setVisible(value); new ConvertVolume(); } /* If the temperature button is pushed Call the tempertaure class and set The visibility of this frame to be false * */ if(e.getSource()==Temp) { value = false; setVisible(value); new ConvertTemperature(); } // If exit button is pused exit the program if(e.getSource()==exit) { JOptionPane.showMessageDialog(null, "Thank you for using the program"); System.exit(0); } } catch(NullPointerException ae) { } } } public static void main(String[] args) { new ConvertSelection(); } }