Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Applet Help: Parsing and displaying labels

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Red face Applet Help: Parsing and displaying labels

    /**
     * @(#)chixmenu.java
     *
     * chixmenu Applet application
     *
     * @author 
     * @version 1.00 2010/9/10
     */
     
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.font.*;
     
    public class chixmenu extends Applet implements ActionListener
    {
    	CheckboxGroup mainmenu;
    	Checkbox optChx, optPrk, optBef;
    	Checkbox chkChx1,chkChx2,chkChx3,chkPrk1,chkPrk2,chkPrk3,chkBef1,chkBef2,chkBef3;
    	Button setMenu, setOrder;
    	int trueTotal = 0;
    	Label lblOrderInit, lblOrder1, lblOrder2, lblOrder3, lblOrderTotal, lblOrderTotalInit;
    	String order1 = " ", order2 = " ", order3 = " ";
    	String strTotal;
     
    	Font bigFont = new Font("Serif",Font.BOLD,25);
    	Font smallFont = new Font("Arial",Font.PLAIN,14);
     
    	public void init()
    	{
    		setLayout(null);
     
    		mainmenu = new CheckboxGroup();
     
    		optChx = new Checkbox("Chicken",false,mainmenu);
    		optPrk = new Checkbox("Pork",false,mainmenu);
    		optBef = new Checkbox("Beef",false,mainmenu);
     
    		chkChx1 = new Checkbox("Chicken Adobo - 35");
    		chkChx2 = new Checkbox("Fried Chicken - 30");
    		chkChx3 = new Checkbox("Chicken Teriyaki - 35");
    		chkPrk1 = new Checkbox("Lechong Baboy - 40");
    		chkPrk2 = new Checkbox("Dinuguan - 35");
    		chkPrk3 = new Checkbox("Porkchop - 30");
    		chkBef1 = new Checkbox("Beef Steak - 35");
    		chkBef2 = new Checkbox("Nilagang Baka - 40");
    		chkBef3 = new Checkbox("Beef Caldereta - 35");
     
    		setMenu = new Button("See Menu!");
    		setOrder = new Button("Order!");
     
    		lblOrderInit = new Label("Your order:");
    		lblOrder1 = new Label(order1);
    		lblOrder2 = new Label(order2);
    		lblOrder3 = new Label(order3);
    		lblOrderTotal = new Label(strTotal);
    		lblOrderTotalInit = new Label ("Total:");
     
    		setMenu.addActionListener(this);
    		setOrder.addActionListener(this);
     
    		optChx.setBounds(10,10,100,25);
    		optPrk.setBounds(130,10,100,25);
    		optBef.setBounds(260,10,100,25);
    		setMenu.setBounds(130,50,100,25);
     
    		chkChx1.setBounds(10,90,300,25);
    		chkChx2.setBounds(10,120,300,25);
    		chkChx3.setBounds(10,150,300,25);
     
    		chkPrk1.setBounds(10,90,300,25);
    		chkPrk2.setBounds(10,120,300,25);
    		chkPrk3.setBounds(10,150,300,25);
     
    		chkBef1.setBounds(10,90,300,25);
    		chkBef2.setBounds(10,120,300,25);
    		chkBef3.setBounds(10,150,300,25);
     
    		setOrder.setBounds(10,180,100,25);
     
    		lblOrderInit.setBounds(10,220,100,25);
    		lblOrder1.setBounds(130,220,100,25);
    		lblOrder2.setBounds(130,250,100,25);
    		lblOrder3.setBounds(130,280,100,25);
    		lblOrderTotal.setBounds(250,250,50,80);
    		lblOrderTotal.setFont(bigFont);
    		lblOrderTotalInit.setBounds(250,220,50,25);
     
    		add(optChx);
    		add(optPrk);
    		add(optBef);
     
    		add(setMenu);
    	}
     
    	public void paint(Graphics g)
    	{
    	}
     
    	public void actionPerformed (ActionEvent objEvent)
    	{
    		if (objEvent.getSource() == setMenu)
    		{
     
    			if (optChx.getState())
    			{
     
    				add(chkChx1);
    				add(chkChx2);
    				add(chkChx3);
     
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				order1 = " ";
    				order2 = " ";
    				order3 = " ";
    				trueTotal = 0;
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
     
    				if (objEvent.getSource() == setOrder)
    				{
    					if(chkChx1.getState() == true)
    					{
    						trueTotal = trueTotal + 35;
    					}
    					if(chkChx2.getState() == true)
    					{
    						trueTotal = trueTotal + 30;
    					}
    					if(chkChx3.getState() == true)
    					{
    						trueTotal = trueTotal + 35;
    					}
     
    					if(chkChx1.getState() == true)
    					{
    						order1 = "Chicken Adobo";
    					}
    					if(chkChx2.getState() == true)
    					{
    						if (order1 == " ")
    							order1 = "Fried Chicken";
    						else
    							order2 = "Fried Chicken";
    					}
    					if(chkChx3.getState() == true)
    					{
    						if (order1 == " " & order2 == " ")
    							order3 = "Chicken Teriyaki";
    						else if ((order1 == "Chicken Adobo"|order1 == "Fried Chicken") & order2 == " ")
    							order2 = "Chicken Teriyaki";
    						else
    							order1 = "Chicken Teriyaki";
    					}
     
    				trueTotal = Integer.parseInt(strTotal);
     
    				add(lblOrder1);
    				add(lblOrder2);
    				add(lblOrder3);
    				add(lblOrderTotal);
    				}
    			}
     
    			if (optPrk.getState())
    			{
     
    				add(chkPrk1);
    				add(chkPrk2);
    				add(chkPrk3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				order1 = " ";
    				order2 = " ";
    				order3 = " ";
    				trueTotal = 0;
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
     
    				if (objEvent.getSource() == setOrder)
    				{
    					if(chkPrk1.getState() == true)
    					{
    						trueTotal = trueTotal + 35;
    					}
    					if(chkPrk2.getState() == true)
    					{
    						trueTotal = trueTotal + 40;
    					}
    					if(chkPrk3.getState() == true)
    					{
    						trueTotal = trueTotal + 30;
    					}
     
    					if(chkPrk1.getState() == true)
    					{
    						order1 = "Lechong Baboy";
    					}
    					if(chkPrk2.getState() == true)
    					{
    						if (order1 == " ")
    							order1 = "Dinuguan";
    						else
    							order2 = "Dinuguan";
    					}
    					if(chkPrk3.getState() == true)
    					{
    						if (order1 == " " & order2 == " ")
    							order3 = "Porkchop";
    						else if ((order1 == "Lechong Baboy"|order1 == "Dinuguan") & order2 == " ")
    							order2 = "Porkchop";
    						else
    							order1 = "Porkchop";
    					}
     
    				trueTotal = Integer.parseInt(strTotal);
     
    				add(lblOrder1);
    				add(lblOrder2);
    				add(lblOrder3);
    				add(lblOrderTotal);
    				}
    			}
     
    			if (optBef.getState())
    			{
     
    				add(chkBef1);
    				add(chkBef2);
    				add(chkBef3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
     
    				order1 = " ";
    				order2 = " ";
    				order3 = " ";
    				trueTotal = 0;
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
     
    				if (objEvent.getSource() == setOrder)
    				{
    					if(chkBef1.getState() == true)
    					{
    						trueTotal = trueTotal + 40;
    					}
    					if(chkBef2.getState() == true)
    					{
    						trueTotal = trueTotal + 35;
    					}
    					if(chkBef3.getState() == true)
    					{
    						trueTotal = trueTotal + 30;
    					}
     
    					if(chkBef1.getState() == true)
    					{
    						order1 = "Beef Steak";
    					}
    					if(chkBef2.getState() == true)
    					{
    						if (order1 == " ")
    							order1 = "Nilagang Baka";
    						else
    							order2 = "Nilagang Baka";
    					}
    					if(chkBef3.getState() == true)
    					{
    						if (order1 == " " & order2 == " ")
    							order3 = "Beef Caldereta";
    						else if ((order1 == "Beef Steak"|order1 == "Nilagang Baka") & order2 == " ")
    							order2 = "Beef Caldereta";
    						else
    							order1 = "Beef Caldereta";
    					}
     
    				trueTotal = Integer.parseInt(strTotal);
     
    				add(lblOrder1);
    				add(lblOrder2);
    				add(lblOrder3);
    				add(lblOrderTotal);
    				}
    			}
    		}
    	}
    }

    There are no errors in my code. But a problem arises when I run the program.

    Here's what the program is supposed to do:

    Program shows 3 radio buttons: Chicken, Pork and Beef. User chooses 1, then clicks the See Menu! button.

    Let's say the user chose beef. It will then show 3 menu items under it. And when the user chose a different one, it will show 3 different menu items.

    Up to this point, there are no problems.

    Now, the user will choose up to 3 items in the menu. When the user clicks the Order! button, the program should display the user's orders, and show the total cost of items.

    My program does not display the user's orders and the cost of items. I presume I made an error in parsing somewhere, but I can't find it..

    Also, I tried changing lblOrder1 = new Label(order1); or 2 or 3 to lblOrder1 = new Label("order1"); or 2 or 3, to see if it would display "order1" in its respective labels, but the applet still doesn't display anything pertaining to their coordinates.

    Please help..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet Help: Parsing and displaying labels

    I don't see any debugging print outs in your code.

    Have you tried debugging the code by adding print outs of the variables as they change and to show logic flow?

    Start by adding print out first thing in the actionPerformed method
    and the add more for each if test in that method.

    Print out the event object
    Last edited by Norm; September 10th, 2010 at 07:46 AM.

  3. The Following User Says Thank You to Norm For This Useful Post:

    katyprim (September 11th, 2010)

  4. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Applet Help: Parsing and displaying labels

    System.out.print? Like S.o.p(objEvent)? Sorry, I'm a beginner..

    And I tried putting in S.o.p(trueTotal) for each time trueTotal changes but I see no general output.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet Help: Parsing and displaying labels

    I see no general output.
    If you don't see any output, then the System.out.print("hi frm method": + YOURMETHODNAMEHERE) statement is NOT being executed. That should tell you something about how and where your program is executing. Keep adding System.out.print statements until you see something being printed out. More is better.

    Also put ids on all your prints so you can tell them apart:
    S.o.p("trueTotal after Chicken=" + trueTotal);

    S.o.p("trueTotal after Beef=" + trueTotal);
    Last edited by Norm; September 10th, 2010 at 03:14 PM.

  6. The Following User Says Thank You to Norm For This Useful Post:

    katyprim (September 11th, 2010)

  7. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Applet Help: Parsing and displaying labels

    I got the s.o.ps to work. I cut off the three if statements of objEvent.getSource()==setOrder to one by taking them out of each if objEvent.getSource = optChx, optPrk and optBef statement. Here's my new code:

    /**
     * @(#)chixmenu.java
     *
     * chixmenu Applet application
     *
     * @author 
     * @version 1.00 2010/9/10
     */
     
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.font.*;
     
    public class chixmenubackup extends Applet implements ActionListener
    {
    	CheckboxGroup mainmenu;
    	Checkbox optChx, optPrk, optBef;
    	Checkbox chkChx1,chkChx2,chkChx3,chkPrk1,chkPrk2,chkPrk3,chkBef1,chkBef2,chkBef3;
    	Button setMenu, setOrder;
    	int trueTotal;
    	Label lblOrderInit, lblOrder1, lblOrder2, lblOrder3, lblOrderTotal, lblOrderTotalInit;
    	String order1,order2,order3;
    	String strTotal;
     
    	Font bigFont = new Font("Serif",Font.BOLD,25);
    	Font smallFont = new Font("Arial",Font.PLAIN,14);
     
    	public void init()
    	{
    		setLayout(null);
     
    		mainmenu = new CheckboxGroup();
     
    		optChx = new Checkbox("Chicken",false,mainmenu);
    		optPrk = new Checkbox("Pork",false,mainmenu);
    		optBef = new Checkbox("Beef",false,mainmenu);
     
    		chkChx1 = new Checkbox("Chicken Adobo - 35");
    		chkChx2 = new Checkbox("Fried Chicken - 30");
    		chkChx3 = new Checkbox("Chicken Teriyaki - 35");
    		chkPrk1 = new Checkbox("Lechong Baboy - 40");
    		chkPrk2 = new Checkbox("Dinuguan - 35");
    		chkPrk3 = new Checkbox("Porkchop - 30");
    		chkBef1 = new Checkbox("Beef Steak - 35");
    		chkBef2 = new Checkbox("Nilagang Baka - 40");
    		chkBef3 = new Checkbox("Beef Caldereta - 35");
     
    		setMenu = new Button("See Menu!");
    		setOrder = new Button("Order!");
     
    		lblOrderInit = new Label("Your order:");
    		lblOrder1 = new Label(order1);
    		lblOrder2 = new Label(order2);
    		lblOrder3 = new Label(order3);
    		lblOrderTotal = new Label(strTotal);
    		lblOrderTotalInit = new Label ("Total:");
     
    		setMenu.addActionListener(this);
    		setOrder.addActionListener(this);
     
    		optChx.setBounds(10,10,100,25);
    		optPrk.setBounds(130,10,100,25);
    		optBef.setBounds(260,10,100,25);
    		setMenu.setBounds(130,50,100,25);
     
    		chkChx1.setBounds(10,90,300,25);
    		chkChx2.setBounds(10,120,300,25);
    		chkChx3.setBounds(10,150,300,25);
     
    		chkPrk1.setBounds(10,90,300,25);
    		chkPrk2.setBounds(10,120,300,25);
    		chkPrk3.setBounds(10,150,300,25);
     
    		chkBef1.setBounds(10,90,300,25);
    		chkBef2.setBounds(10,120,300,25);
    		chkBef3.setBounds(10,150,300,25);
     
    		setOrder.setBounds(10,180,100,25);
     
    		lblOrderInit.setBounds(10,220,100,25);
    		lblOrder1.setBounds(130,220,100,25);
    		lblOrder2.setBounds(130,250,100,25);
    		lblOrder3.setBounds(130,280,100,25);
    		lblOrderTotal.setBounds(250,250,50,80);
    		lblOrderTotal.setFont(bigFont);
    		lblOrderTotalInit.setBounds(250,220,50,25);
     
    		add(optChx);
    		add(optPrk);
    		add(optBef);
     
    		add(setMenu);
     
    		trueTotal = 0;
    		order1 = " ";
    		order2 = " ";
    		order3 = " ";
    	}
     
    	public void paint(Graphics g)
    	{
    	}
     
    	public void actionPerformed (ActionEvent objEvent)
    	{
    		if (objEvent.getSource() == setMenu)
    		{
     
    			if (optChx.getState())
    			{
    				add(chkChx1);
    				add(chkChx2);
    				add(chkChx3);
     
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
     
    			if (optPrk.getState())
    			{
    				add(chkPrk1);
    				add(chkPrk2);
    				add(chkPrk3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
     
    			if (optBef.getState())
    			{
     
    				add(chkBef1);
    				add(chkBef2);
    				add(chkBef3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
    		}
     
     
    		if (objEvent.getSource() == setOrder)
    		{
    			trueTotal = 0;
    			order1 = " ";
    			order2 = " ";
    			order3 = " ";
     
    			if(chkChx1.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkChx2.getState() == true)
    			{
    				trueTotal = trueTotal + 30;
    			}
    			if(chkChx3.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkPrk1.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkPrk2.getState() == true)
    			{
    				trueTotal = trueTotal + 40;
    			}
    			if(chkPrk3.getState() == true)
    			{
    				trueTotal = trueTotal + 30;
    			}
    			if(chkBef1.getState() == true)
    			{
    				trueTotal = trueTotal + 40;
    			}
    			if(chkBef2.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkBef3.getState() == true)
    			{
    				trueTotal = trueTotal + 30;
    			}
     
    			if (optChx.getState() == true)
    			{
    				if(chkChx1.getState() == true)
    				{
    					order1 = "Chicken Adobo";
    				}
    				if(chkChx2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Fried Chicken";
    					else
    						order2 = "Fried Chicken";
    				}
    				if(chkChx3.getState() == true)
    				{
    					if (order1 == "Chicken Adobo" & order2 == "Fried Chicken")
    						order3 = "Chicken Teriyaki";
    					else if ((order1 == "Chicken Adobo"|order1 == "Fried Chicken") & order2 == " ")
    						order2 = "Chicken Teriyaki";
    					else
    						order1 = "Chicken Teriyaki";
    				}
    			}
    			else if (optPrk.getState() == true)
    			{
    				if(chkPrk1.getState() == true)
    				{
    					order1 = "Lechong Baboy";
    				}
    				if(chkPrk2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Dinuguan";
    					else
    						order2 = "Dinuguan";
    				}
    				if(chkPrk3.getState() == true)
    				{
    					if (order1 == "Lechong Baboy" & order2 == "Dinuguan")
    						order3 = "Porkchop";
    					else if ((order1 == "Lechong Baboy"|order1 == "Dinuguan") & order2 == " ")
    						order2 = "Porkchop";
    					else
    						order1 = "Porkchop";
    				}
    			}
    			else if (optBef.getState() == true)
    			{
    				if(chkBef1.getState() == true)
    				{
    					order1 = "Beef Steak";
    				}
    				if(chkBef2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Nilagang Baka";
    					else
    						order2 = "Nilagang Baka";
    				}
    				if(chkBef3.getState() == true)
    				{
    					if (order1 == "Beef Steak" & order2 == "Nilagang Baka")
    						order3 = "Beef Caldereta";
    					else if ((order1 == "Beef Steak"|order1 == "Nilagang Baka") & order2 == " ")
    						order2 = "Beef Caldereta";
    					else
    						order1 = "Beef Caldereta";
    				}
    			}
     
    			System.out.println("\n\ntrueTotal: "+trueTotal);
    			System.out.println("trueTotal Stringed: "+strTotal);
    			System.out.println("order1: "+order1);
    			System.out.println("order2: "+order2);
    			System.out.println("order3: "+order3+"\n\n");
     
    			trueTotal = Integer.parseInt(strTotal);
     
    			add(lblOrder1);
    			add(lblOrder2);
    			add(lblOrder3);
    			add(lblOrderTotal);
    		}
     
    	}
    }

    The s.o.ps I put in are working properly but I'm still not seeing the labels at the bottom that's supposed to show the orders and the total.

    I finally see some general output. But now it shows me all this:

    Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Integer.java:417)
        at java.lang.Integer.parseInt(Integer.java:499)
        at chixmenubackup.actionPerformed(chixmenubackup.java:307)
        at java.awt.Button.processActionEvent(Button.java:392)
        at java.awt.Button.processEvent(Button.java:360)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Please help me.. I don't understand what all this means...

    EDIT: I have seen that my trueTotal = Integer.parseInt(strTotal); was under the S.o.Ps I put in. I tried putting it on top. The same exceptions as above was the same, but I also didn't see all my other S.o.Ps...

    I also tried putting the trueTotal = Integer.parseInt(strTotal); under the add(lblOrder1); and others, but the labels still didn't show.

    As of now, I turned the trueTotal = Integer.parseInt(strTotal); to a comment. All the exceptions stopped showing and my S.o.Ps are working except for strTotal (the supposed string of trueTotal) which is null, but my labels still aren't showing up. I'm really confused now..

    So I'm guessing that I have an error on converting the integer to string and displaying the label.. Please help... I'm supposed to pass this in 7 hours..

    EDIT2: I surfed the internet for how to turn an integer to a string and found a solution. So now,

    strTotal = Integer.toString(trueTotal);
    System.out.println("\n\ntrueTotal: "+trueTotal);
    System.out.println("trueTotal Stringed: "+strTotal);
    System.out.println("order1: "+order1);
    System.out.println("order2: "+order2);
    System.out.println("order3: "+order3+"\n\n");

    There are no more exceptions. My general output is only showing the correct S.o.Ps:

    trueTotal: 105
    trueTotal Stringed: 105
    order1: Beef Steak
    order2: Nilagang Baka
    order3: Beef Caldereta
     
    trueTotal: 75
    trueTotal Stringed: 75
    order1: Beef Steak
    order2: Nilagang Baka
    order3:  
     
    trueTotal: 30
    trueTotal Stringed: 30
    order1: Beef Caldereta
    order2: 
    order3:

    All of this is working but my labels still aren't showing up on the applet.. Please help...

    EDIT3:

    I got it all working! Thanks for the debugging tip, Norm!

    /**
     * @(#)chixmenu.java
     *
     * chixmenu Applet application
     *
     * @author 
     * @version 1.00 2010/9/10
     */
     
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.font.*;
     
    public class chixmenu extends Applet implements ActionListener
    {
    	CheckboxGroup mainmenu;
    	Checkbox optChx, optPrk, optBef;
    	Checkbox chkChx1,chkChx2,chkChx3,chkPrk1,chkPrk2,chkPrk3,chkBef1,chkBef2,chkBef3;
    	Button setMenu, setOrder;
    	int trueTotal;
    	Label lblOrderInit, lblOrder1, lblOrder2, lblOrder3, lblOrderTotal, lblOrderTotalInit;
    	String order1,order2,order3;
    	String strTotal;
     
    	Font bigFont = new Font("Serif",Font.BOLD,50);
    	Font smallFont = new Font("Arial",Font.PLAIN,14);
     
    	public void init()
    	{
    		setLayout(null);
     
    		mainmenu = new CheckboxGroup();
     
    		optChx = new Checkbox("Chicken",false,mainmenu);
    		optPrk = new Checkbox("Pork",false,mainmenu);
    		optBef = new Checkbox("Beef",false,mainmenu);
     
    		chkChx1 = new Checkbox("Chicken Adobo - 35");
    		chkChx2 = new Checkbox("Fried Chicken - 30");
    		chkChx3 = new Checkbox("Chicken Teriyaki - 35");
    		chkPrk1 = new Checkbox("Lechong Baboy - 40");
    		chkPrk2 = new Checkbox("Dinuguan - 35");
    		chkPrk3 = new Checkbox("Porkchop - 30");
    		chkBef1 = new Checkbox("Beef Steak - 35");
    		chkBef2 = new Checkbox("Nilagang Baka - 40");
    		chkBef3 = new Checkbox("Beef Caldereta - 35");
     
    		setMenu = new Button("See Menu!");
    		setOrder = new Button("Order!");
     
    		lblOrderInit = new Label("Your order:");
    		lblOrderTotalInit = new Label ("Total:");
     
    		setMenu.addActionListener(this);
    		setOrder.addActionListener(this);
     
    		optChx.setBounds(10,10,100,25);
    		optPrk.setBounds(130,10,100,25);
    		optBef.setBounds(260,10,100,25);
    		setMenu.setBounds(130,50,100,25);
     
    		chkChx1.setBounds(10,90,300,25);
    		chkChx2.setBounds(10,120,300,25);
    		chkChx3.setBounds(10,150,300,25);
     
    		chkPrk1.setBounds(10,90,300,25);
    		chkPrk2.setBounds(10,120,300,25);
    		chkPrk3.setBounds(10,150,300,25);
     
    		chkBef1.setBounds(10,90,300,25);
    		chkBef2.setBounds(10,120,300,25);
    		chkBef3.setBounds(10,150,300,25);
     
    		setOrder.setBounds(10,180,100,25);
     
    		lblOrderInit.setBounds(10,220,100,25);
    		lblOrderTotalInit.setBounds(250,220,50,25);
     
    		lblOrder1 = new Label(order1);
    		lblOrder2 = new Label(order2);
    		lblOrder3 = new Label(order3);
    		lblOrderTotal = new Label(strTotal);
     
    		lblOrder1.setBounds(130,220,100,25);
    		lblOrder2.setBounds(130,250,100,25);
    		lblOrder3.setBounds(130,280,100,25);
    		lblOrderTotal.setBounds(250,220,80,80);
    		lblOrderTotal.setFont(bigFont);
     
    		add(lblOrder1);
    		add(lblOrder2);
    		add(lblOrder3);
    		add(lblOrderTotal);
     
    		add(optChx);
    		add(optPrk);
    		add(optBef);
     
    		add(setMenu);
     
    		trueTotal = 0;
    		order1 = " ";
    		order2 = " ";
    		order3 = " ";
    	}
     
    	public void paint(Graphics g)
    	{
    	}
     
    	public void actionPerformed (ActionEvent objEvent)
    	{
    		if (objEvent.getSource() == setMenu)
    		{
     
    			if (optChx.getState())
    			{
    				add(chkChx1);
    				add(chkChx2);
    				add(chkChx3);
     
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
     
    			if (optPrk.getState())
    			{
    				add(chkPrk1);
    				add(chkPrk2);
    				add(chkPrk3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkBef1.setState(false);
    				chkBef2.setState(false);
    				chkBef3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkBef1);
    				remove(chkBef2);
    				remove(chkBef3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
     
    			if (optBef.getState())
    			{
     
    				add(chkBef1);
    				add(chkBef2);
    				add(chkBef3);
     
    				chkChx1.setState(false);
    				chkChx2.setState(false);
    				chkChx3.setState(false);
    				chkPrk1.setState(false);
    				chkPrk2.setState(false);
    				chkPrk3.setState(false);
     
    				remove(chkChx1);
    				remove(chkChx2);
    				remove(chkChx3);
    				remove(chkPrk1);
    				remove(chkPrk2);
    				remove(chkPrk3);
     
    				add(setOrder);
    				add(lblOrderInit);
    				add(lblOrderTotalInit);
    			}
    		}
     
     
    		if (objEvent.getSource() == setOrder)
    		{
    			trueTotal = 0;
    			order1 = " ";
    			order2 = " ";
    			order3 = " ";
     
    			remove(lblOrder1);
    			remove(lblOrder2);
    			remove(lblOrder3);
    			remove(lblOrderTotal);
     
    			if(chkChx1.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkChx2.getState() == true)
    			{
    				trueTotal = trueTotal + 30;
    			}
    			if(chkChx3.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkPrk1.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkPrk2.getState() == true)
    			{
    				trueTotal = trueTotal + 40;
    			}
    			if(chkPrk3.getState() == true)
    			{
    				trueTotal = trueTotal + 30;
    			}
    			if(chkBef1.getState() == true)
    			{
    				trueTotal = trueTotal + 40;
    			}
    			if(chkBef2.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
    			if(chkBef3.getState() == true)
    			{
    				trueTotal = trueTotal + 35;
    			}
     
    			if (optChx.getState() == true)
    			{
    				if(chkChx1.getState() == true)
    				{
    					order1 = "Chicken Adobo";
    				}
    				if(chkChx2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Fried Chicken";
    					else
    						order2 = "Fried Chicken";
    				}
    				if(chkChx3.getState() == true)
    				{
    					if (order1 == "Chicken Adobo" & order2 == "Fried Chicken")
    						order3 = "Chicken Teriyaki";
    					else if ((order1 == "Chicken Adobo"|order1 == "Fried Chicken") & order2 == " ")
    						order2 = "Chicken Teriyaki";
    					else
    						order1 = "Chicken Teriyaki";
    				}
    			}
    			else if (optPrk.getState() == true)
    			{
    				if(chkPrk1.getState() == true)
    				{
    					order1 = "Lechong Baboy";
    				}
    				if(chkPrk2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Dinuguan";
    					else
    						order2 = "Dinuguan";
    				}
    				if(chkPrk3.getState() == true)
    				{
    					if (order1 == "Lechong Baboy" & order2 == "Dinuguan")
    						order3 = "Porkchop";
    					else if ((order1 == "Lechong Baboy"|order1 == "Dinuguan") & order2 == " ")
    						order2 = "Porkchop";
    					else
    						order1 = "Porkchop";
    				}
    			}
    			else if (optBef.getState() == true)
    			{
    				if(chkBef1.getState() == true)
    				{
    					order1 = "Beef Steak";
    				}
    				if(chkBef2.getState() == true)
    				{
    					if (order1 == " ")
    						order1 = "Nilagang Baka";
    					else
    						order2 = "Nilagang Baka";
    				}
    				if(chkBef3.getState() == true)
    				{
    					if (order1 == "Beef Steak" & order2 == "Nilagang Baka")
    						order3 = "Beef Caldereta";
    					else if ((order1 == "Beef Steak"|order1 == "Nilagang Baka") & order2 == " ")
    						order2 = "Beef Caldereta";
    					else
    						order1 = "Beef Caldereta";
    				}
    			}
     
    			//trueTotal = Integer.parseInt(strTotal);
     
    			strTotal = Integer.toString(trueTotal);
     
    			System.out.println("\n\ntrueTotal: "+trueTotal);
    			System.out.println("trueTotal Stringed: "+strTotal);
    			System.out.println("order1: "+order1);
    			System.out.println("order2: "+order2);
    			System.out.println("order3: "+order3+"\n\n");
     
    			lblOrder1 = new Label(order1);
    			lblOrder2 = new Label(order2);
    			lblOrder3 = new Label(order3);
    			lblOrderTotal = new Label(strTotal);
     
    			lblOrder1.setBounds(130,220,100,25);
    			lblOrder2.setBounds(130,250,100,25);
    			lblOrder3.setBounds(130,280,100,25);
    			lblOrderTotal.setBounds(250,220,80,80);
    			lblOrderTotal.setFont(bigFont);
     
    			add(lblOrder1);
    			add(lblOrder2);
    			add(lblOrder3);
    			add(lblOrderTotal);
    		}
     
    	}
    }
    Last edited by katyprim; September 11th, 2010 at 04:07 AM. Reason: Update

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet Help: Parsing and displaying labels

    Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Integer.java:417)
    at java.lang.Integer.parseInt(Integer.java:499)
    at chixmenubackup.actionPerformed(chixmenubackup.java :307)
    At line 307 in the actionPerformed method, your code called parseInt with a null argument which the JVM did not like and so thru this exception. You need either catch the exception and handle it or test if the String is null before trying to convert it to an int.

    Just saw the "Got it all working"
    Does that mean you have solved your problems?

  9. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Applet Help: Parsing and displaying labels

    Quote Originally Posted by Norm View Post
    At line 307 in the actionPerformed method, your code called parseInt with a null argument which the JVM did not like and so thru this exception. You need either catch the exception and handle it or test if the String is null before trying to convert it to an int.

    Just saw the "Got it all working"
    Does that mean you have solved your problems?
    Yup! Thanks!

Similar Threads

  1. Displaying things in gui
    By KrisTheSavage in forum AWT / Java Swing
    Replies: 2
    Last Post: March 29th, 2010, 12:21 PM
  2. Need help understanding GUI screen layouts and labels
    By Bill_H in forum AWT / Java Swing
    Replies: 3
    Last Post: December 2nd, 2009, 11:50 PM
  3. Need help with String Trimming.. and displaying Keys on maps.
    By bh-chobo in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 9th, 2009, 01:15 PM
  4. [SOLVED] displaying sum of harmonic series
    By sriraj.kundan in forum Algorithms & Recursion
    Replies: 2
    Last Post: June 15th, 2009, 11:42 PM

Tags for this Thread