//needed for swing classes for all of the graphical components created in the GUI import javax.swing.*; //needed for the actionlistener class for events such as clicking a button in the application import java.awt.*; /* Needed for for ActionListener Interface for buttons performing a certain action such as calculating */ import java.awt.event.*; // this for your calculation to come out in a dollar format import java.text.DecimalFormat; // the class header which marks the start of a class definition public class Package_Selector_GUI extends JFrame //extends JFrame class to inherit members from the JFrame class { private JPanel packagePanel; //private JPanel phonePanel; //private JPanel optionPanel; //private JTextField PhoneTextField;// to hold the Phone input private JTextField PackageTextField; // to hold the Package input //private JTextField OptionTextField; // to hold the Option input private JMenuBar menuBar; // the menu bar private JMenu FileMenu; // the file menu private JMenu PhoneMenu; // the phone menu private JMenu PackageMenu; // the package menu private JMenu OptionMenu; // the option menu private JMenuItem exitItem; // the to exit private JRadioButtonMenuItem Package1; //to select 300minutes private JRadioButtonMenuItem Package2; // to select 800minutes private JRadioButtonMenuItem Package3; // to select 1500minutes private JRadioButtonMenuItem Model_100; // to select phone option1 private JRadioButtonMenuItem Model_110 ; // to select phone option2 private JRadioButtonMenuItem Model_200; // to select phone option3 private JCheckBoxMenuItem VoiceMail; // to select option1 private JCheckBoxMenuItem TextMessage; // to select option2 private JLabel messageLabel; public Package_Selector_GUI() { //to display a title setTitle("Anthony's GetItGotIt Phone Service"); // specifying an action for the close button setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // creating borderlayout manager setLayout(new BorderLayout()); //command to build the button panel buildPackagePanel(); add(packagePanel); //command to build the MenuBar buildMenuBar(); //packing all the contents of the window in the display and setting it visible pack(); setVisible(true); } //the build MenuBar method starts building the MenuBar private void buildMenuBar() { // creating the menu bar menuBar = new JMenuBar(); //creating the four menu tabs buildFileMenu(); buildPhoneMenu(); buildPackageMenu(); buildOptionMenu(); // adding the menu tabs to the menu bar menuBar.add(FileMenu); menuBar.add(PhoneMenu); menuBar.add(PackageMenu); menuBar.add(OptionMenu); // setting the windows menu bar setJMenuBar(menuBar); } //the build FileMenu method starts building the FileMenu private void buildFileMenu() { //creating an exit item for the file menu exitItem = new JMenuItem("Exit"); exitItem.setMnemonic(KeyEvent.VK_X); exitItem.addActionListener(new ExitListener()); //creating the Jmenu object for the file menu FileMenu = new JMenu("File"); FileMenu.setMnemonic(KeyEvent.VK_F); //adding the exit item to the the file menu FileMenu.add(exitItem); } //the build PhoneMenu method starts building the PhoneMenu private void buildPhoneMenu() { //creating the radio buttons for user to choose what phone they desire Model_100 = new JRadioButtonMenuItem ("Model_100",true); Model_100.setMnemonic(KeyEvent.VK_P); Model_110 = new JRadioButtonMenuItem ("Model_110"); Model_110.setMnemonic(KeyEvent.VK_H); Model_200 = new JRadioButtonMenuItem ("Model_200"); Model_200.setMnemonic(KeyEvent.VK_O); //grouping radio buttons together ButtonGroup bg = new ButtonGroup(); bg.add(Model_100); bg.add(Model_110); bg.add(Model_200); //creating the Jmenu object for the Phone menu PhoneMenu = new JMenu("Phone"); PhoneMenu.setMnemonic(KeyEvent.VK_N); //adding the menu items to the the phone menu PhoneMenu.add(Model_100); PhoneMenu.add(Model_110); PhoneMenu.add(Model_200); } //the build PackageMenu method starts building the PackageMenu private void buildPackageMenu() { //creating the radio buttons for user to choose what Package they desire Package1 = new JRadioButtonMenuItem ("300minutes",true); Package1.setMnemonic(KeyEvent.VK_A); Package2 = new JRadioButtonMenuItem ("800minutes"); Package2.setMnemonic(KeyEvent.VK_G); Package3 = new JRadioButtonMenuItem ("1500minutes"); Package3.setMnemonic(KeyEvent.VK_E); //grouping radio buttons together ButtonGroup bg = new ButtonGroup(); bg.add(Package1); bg.add(Package2); bg.add(Package3); //creating the Jmenu object for the Package Menu PackageMenu = new JMenu("Package"); PackageMenu.setMnemonic(KeyEvent.VK_S); //adding the menu items to the the Package Menu PackageMenu.add(Package1); PackageMenu.add(Package2); PackageMenu.add(Package3); } //the build OptionMenu method starts building the OptionMenu private void buildOptionMenu() { //creating the radio buttons for user to choose what Package they desire VoiceMail = new JCheckBoxMenuItem ("VoiceMail",true); VoiceMail.setMnemonic(KeyEvent.VK_V); TextMessage = new JCheckBoxMenuItem ("TextMessaging"); TextMessage.setMnemonic(KeyEvent.VK_T); //creating the Jmenu object for the Option Menu OptionMenu = new JMenu("Options"); OptionMenu.setMnemonic(KeyEvent.VK_R); //adding the menu items to the the Option Menu OptionMenu.add(VoiceMail); OptionMenu.add(TextMessage); } private void buildPackagePanel() { double Package1_rate = 45.00; double Package2_rate = 65.00; double Package3_rate = 99.00; String input; input = PackageTextField.getText(); messageLabel = new JLabel("Package desired"); PackageTextField = new JTextField(10); if (Package1.isSelected()) Package1_rate = Double.parseDouble(input); else if (Package2.isSelected()) Package2_rate = Double.parseDouble(input); else if (Package3.isSelected()) Package3_rate = Double.parseDouble(input); packagePanel = new JPanel(); packagePanel.add(messageLabel); packagePanel.add(PackageTextField); } /* private inner class that handles the event when the exit button is clicked */ private class ExitListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } /* this is the method header which is defined as the main method */ public static void main(String[] args) { Package_Selector_GUI psGUI = new Package_Selector_GUI(); } }
--- Update ---
Hello, I'm new the the forum but joined in hopes of figuring out various problems with my coding. I don't quite understand the error message I'm given (I'm very very new to Java programming) so bear with me, and thank you in advance for any help you are willing to offer.
MY ERROR MESSAGE
at Package_Selector_GUI.buildPackagePanel(Package_Selector_GUI.java:213) at Package_Selector_GUI.<init>(Package_Selector_GUI.java:64) at Package_Selector_GUI.main(Package_Selector_GUI.java:251)
MY FULL CODE
[/QUOTE]//needed for swing classes for all of the graphical components created in the GUI import javax.swing.*; //needed for the actionlistener class for events such as clicking a button in the application import java.awt.*; /* Needed for for ActionListener Interface for buttons performing a certain action such as calculating */ import java.awt.event.*; // this for your calculation to come out in a dollar format import java.text.DecimalFormat; // the class header which marks the start of a class definition public class Package_Selector_GUI extends JFrame //extends JFrame class to inherit members from the JFrame class { private JPanel packagePanel; //private JPanel phonePanel; //private JPanel optionPanel; //private JTextField PhoneTextField;// to hold the Phone input private JTextField PackageTextField; // to hold the Package input //private JTextField OptionTextField; // to hold the Option input private JMenuBar menuBar; // the menu bar private JMenu FileMenu; // the file menu private JMenu PhoneMenu; // the phone menu private JMenu PackageMenu; // the package menu private JMenu OptionMenu; // the option menu private JMenuItem exitItem; // the to exit private JRadioButtonMenuItem Package1; //to select 300minutes private JRadioButtonMenuItem Package2; // to select 800minutes private JRadioButtonMenuItem Package3; // to select 1500minutes private JRadioButtonMenuItem Model_100; // to select phone option1 private JRadioButtonMenuItem Model_110 ; // to select phone option2 private JRadioButtonMenuItem Model_200; // to select phone option3 private JCheckBoxMenuItem VoiceMail; // to select option1 private JCheckBoxMenuItem TextMessage; // to select option2 private JLabel messageLabel; public Package_Selector_GUI() { //to display a title setTitle("Anthony's GetItGotIt Phone Service"); // specifying an action for the close button setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // creating borderlayout manager setLayout(new BorderLayout()); //command to build the button panel buildPackagePanel(); add(packagePanel); //command to build the MenuBar buildMenuBar(); //packing all the contents of the window in the display and setting it visible pack(); setVisible(true); } //the build MenuBar method starts building the MenuBar private void buildMenuBar() { // creating the menu bar menuBar = new JMenuBar(); //creating the four menu tabs buildFileMenu(); buildPhoneMenu(); buildPackageMenu(); buildOptionMenu(); // adding the menu tabs to the menu bar menuBar.add(FileMenu); menuBar.add(PhoneMenu); menuBar.add(PackageMenu); menuBar.add(OptionMenu); // setting the windows menu bar setJMenuBar(menuBar); } //the build FileMenu method starts building the FileMenu private void buildFileMenu() { //creating an exit item for the file menu exitItem = new JMenuItem("Exit"); exitItem.setMnemonic(KeyEvent.VK_X); exitItem.addActionListener(new ExitListener()); //creating the Jmenu object for the file menu FileMenu = new JMenu("File"); FileMenu.setMnemonic(KeyEvent.VK_F); //adding the exit item to the the file menu FileMenu.add(exitItem); } //the build PhoneMenu method starts building the PhoneMenu private void buildPhoneMenu() { //creating the radio buttons for user to choose what phone they desire Model_100 = new JRadioButtonMenuItem ("Model_100",true); Model_100.setMnemonic(KeyEvent.VK_P); Model_110 = new JRadioButtonMenuItem ("Model_110"); Model_110.setMnemonic(KeyEvent.VK_H); Model_200 = new JRadioButtonMenuItem ("Model_200"); Model_200.setMnemonic(KeyEvent.VK_O); //grouping radio buttons together ButtonGroup bg = new ButtonGroup(); bg.add(Model_100); bg.add(Model_110); bg.add(Model_200); //creating the Jmenu object for the Phone menu PhoneMenu = new JMenu("Phone"); PhoneMenu.setMnemonic(KeyEvent.VK_N); //adding the menu items to the the phone menu PhoneMenu.add(Model_100); PhoneMenu.add(Model_110); PhoneMenu.add(Model_200); } //the build PackageMenu method starts building the PackageMenu private void buildPackageMenu() { //creating the radio buttons for user to choose what Package they desire Package1 = new JRadioButtonMenuItem ("300minutes",true); Package1.setMnemonic(KeyEvent.VK_A); Package2 = new JRadioButtonMenuItem ("800minutes"); Package2.setMnemonic(KeyEvent.VK_G); Package3 = new JRadioButtonMenuItem ("1500minutes"); Package3.setMnemonic(KeyEvent.VK_E); //grouping radio buttons together ButtonGroup bg = new ButtonGroup(); bg.add(Package1); bg.add(Package2); bg.add(Package3); //creating the Jmenu object for the Package Menu PackageMenu = new JMenu("Package"); PackageMenu.setMnemonic(KeyEvent.VK_S); //adding the menu items to the the Package Menu PackageMenu.add(Package1); PackageMenu.add(Package2); PackageMenu.add(Package3); } //the build OptionMenu method starts building the OptionMenu private void buildOptionMenu() { //creating the radio buttons for user to choose what Package they desire VoiceMail = new JCheckBoxMenuItem ("VoiceMail",true); VoiceMail.setMnemonic(KeyEvent.VK_V); TextMessage = new JCheckBoxMenuItem ("TextMessaging"); TextMessage.setMnemonic(KeyEvent.VK_T); //creating the Jmenu object for the Option Menu OptionMenu = new JMenu("Options"); OptionMenu.setMnemonic(KeyEvent.VK_R); //adding the menu items to the the Option Menu OptionMenu.add(VoiceMail); OptionMenu.add(TextMessage); } private void buildPackagePanel() { double Package1_rate = 45.00; double Package2_rate = 65.00; double Package3_rate = 99.00; String input; input = PackageTextField.getText(); messageLabel = new JLabel("Package desired"); PackageTextField = new JTextField(10); if (Package1.isSelected()) Package1_rate = Double.parseDouble(input); else if (Package2.isSelected()) Package2_rate = Double.parseDouble(input); else if (Package3.isSelected()) Package3_rate = Double.parseDouble(input); packagePanel = new JPanel(); packagePanel.add(messageLabel); packagePanel.add(PackageTextField); } /* private inner class that handles the event when the exit button is clicked */ private class ExitListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } /* this is the method header which is defined as the main method */ public static void main(String[] args) { Package_Selector_GUI psGUI = new Package_Selector_GUI(); } }