Hey everyone,
heard the people here are good so I thought u were the only ones to help me in this


i keep getting these runtime errors

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
    at java.lang.Double.parseDouble(Double.java:510)
    at MainClass.actionPerformed(MainClass.java:263)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6041)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5806)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4413)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4243)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2440)
    at java.awt.Component.dispatchEvent(Component.java:4243)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Here's my code

import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class MainClass extends JFrame implements ActionListener 
{

JTextField t1 = new JTextField(5);
JTextField t2 = new JTextField(5);
JTextField t3 = new JTextField(5);

JLabel oid = new JLabel("Please enter order ID");
JLabel numG = new JLabel("Please enter number of guests");
JLabel Cust = new JLabel("Please enter Customer Name");
JLabel type = new JLabel("Please select the tab of the food type.");
JButton calc = new JButton("Calculate");
JButton calc1 = new JButton("Calculate");
JButton calc2 = new JButton("Calculate");
JButton calc3 = new JButton("Calculate");


CheckboxGroup spcGroup = new CheckboxGroup();
Checkbox spy= new Checkbox("Yes",false,spcGroup);
Checkbox spn= new Checkbox("No",true,spcGroup);
CheckboxGroup serGroup=new CheckboxGroup();
Checkbox sery= new Checkbox("Yes",false,serGroup);
Checkbox sern= new Checkbox("No",true,serGroup);
CheckboxGroup thmGroup = new CheckboxGroup();
Checkbox thy= new Checkbox("Yes",false,thmGroup);
Checkbox thn= new Checkbox("No",true,thmGroup);


JTextField bary = new JTextField(4);
JTextField cury = new JTextField(4);
JTextField tand = new JTextField(4);
JTextField sam = new JTextField(4);
JTextField piz = new JTextField(4);
JTextField pas = new JTextField(4);
JTextField laz = new JTextField(4);
JTextField spg = new JTextField(4);
JTextField ssc = new JTextField(4);
JTextField shr = new JTextField(4);
JTextField nod = new JTextField(4);
JTextField vr = new JTextField(4);
JTextField shaw = new JTextField(4);
JTextField kbab = new JTextField(4);
JTextField shish = new JTextField(4);
JTextField tab = new JTextField(4);



JLabel total1= new JLabel();

JTabbedPane tabbedPane = new JTabbedPane();

JComboBox combo=new JComboBox();


public MainClass(){
	
	super ("Raja's Catering");


    Box first = Box.createVerticalBox();
    first.add(oid);
    first.add(t1);
    
    Box first1 = Box.createVerticalBox();
    first1.add(Cust);
    first1.add(t2);   
        
    Box first2 = Box.createVerticalBox();
    first2.add(numG);
    first2.add(t3);          
    
    Box all = Box.createVerticalBox();
    all.add(first);
    all.add(first1);
    all.add(first2);
    all.add(Box.createVerticalStrut(20));
    all.add(new JLabel ("Are you a special customer?"));
   	all.add(spy);
    all.add(spn);
   	all.add(new JLabel ("Would you like us to serve?"));
   	all.add(sery);
   	all.add(sern);
   	all.add(new JLabel ("Would you like to apply theme?"));
   	all.add(thy);
   	all.add(thn);
   	all.add(Box.createVerticalStrut(20));
    all.add(type);
    
    all.add(Box.createVerticalStrut(550));
           
    JPanel pan1 = new JPanel();
    pan1.setLayout(new BoxLayout (pan1, BoxLayout.Y_AXIS));   
    pan1.setBackground(Color.pink);
    pan1.setBorder(new TitledBorder(new EtchedBorder(), "Welcome"));
    pan1.add(all);
    tabbedPane.addTab("Welcome",null,pan1,"First Panel");
     	      
     Box second = Box.createVerticalBox();
   	 second.add(new JLabel ("Please note that 1 portion = 10 plates"));    	 
   	 second.add(Box.createVerticalStrut(10));  
   	 second.add(new JLabel ("Portions of Baryani:"));     	 
   	 second.add(bary);     	 
   	 second.add(new JLabel ("Portions of Curry Beef:"));     	 
   	 second.add(cury);
   	 second.add(new JLabel ("Portions of Tandoori Chicken:"));
   	 second.add(tand);
   	 second.add(new JLabel ("Portions of Samosa:"));
   	 second.add(sam);

   	 second.add(calc);
   	 second.add(Box.createVerticalStrut(30));  
   	 calc.addActionListener(this); 	 
     second.add(total1);
     second.add(Box.createVerticalStrut(550));     

     Box s2 = Box.createHorizontalBox();
   	 s2.add(new JLabel (""));
   	 s2.add(new JLabel (""));   	 
     s2.add(Box.createHorizontalStrut(800));
     
   	 JPanel pan2 = new JPanel();
   	 pan2.setLayout(new BorderLayout());
   	 pan2.setBackground(Color.yellow);
   	 pan2.setBorder(new TitledBorder(new EtchedBorder(), "Indian Food"));
   	 pan2.add(second, BorderLayout.WEST);
   	 pan2.add(s2,BorderLayout.EAST);
   	 tabbedPane.addTab("Indian",null,pan2,"Second Panel");
   	 
   	 Box third = Box.createVerticalBox();
   	 third.add(new JLabel ("Please note that 1 portion = 10 plates"));    	 
   	 third.add(Box.createVerticalStrut(10));  
   	 third.add(new JLabel ("Portions of Pizza:"));     	 
   	 third.add(piz);     	 
   	 third.add(new JLabel ("Portions of Pasta:"));     	 
   	 third.add(pas);
   	 third.add(new JLabel ("Portions of Lazagne:"));
   	 third.add(laz);
   	 third.add(new JLabel ("Portions of Speghetti:"));
   	 third.add(spg);
   	 third.add(calc1);
   	 third.add(Box.createVerticalStrut(30));  
   	 calc1.addActionListener(this); 	 
     third.add(total1);
     third.add(Box.createVerticalStrut(550));     

     Box s3 = Box.createHorizontalBox();
   	 s3.add(new JLabel (""));
   	 s3.add(new JLabel (""));   	 
     s3.add(Box.createHorizontalStrut(800));
     
   	 JPanel pan3 = new JPanel();
   	 pan3.setLayout(new BorderLayout());
   	 pan3.setBorder(new TitledBorder(new EtchedBorder(), "Indian Food"));
   	 pan3.setBackground(Color.pink);
   	 pan3.add(third, BorderLayout.WEST);
   	 pan3.add(s3,BorderLayout.EAST);
   	 tabbedPane.addTab("Italian",null,pan3,"third Panel");
   	 
   	 
   	 Box fourth = Box.createVerticalBox();
   	 fourth.add(new JLabel ("Please note that 1 portion = 10 plates"));    	 
   	 fourth.add(Box.createVerticalStrut(10));  
   	 fourth.add(new JLabel ("Portions of Vegetable Rice:"));     	 
   	 fourth.add(vr);     	 
   	 fourth.add(new JLabel ("Portions of Noodles:"));     	 
   	 fourth.add(nod);
   	 fourth.add(new JLabel ("Portions of Sweet & Sour Chicken:"));
   	 fourth.add(ssc);
   	 fourth.add(new JLabel ("Portions of Spicy Shrimp:"));
   	 fourth.add(shr);
   	 fourth.add(calc2);
   	 fourth.add(Box.createVerticalStrut(30));  
   	 calc2.addActionListener(this); 	 
     fourth.add(total1);
     fourth.add(Box.createVerticalStrut(550));     

     Box s4 = Box.createHorizontalBox();
   	 s4.add(new JLabel (""));
   	 s4.add(new JLabel (""));   	 
     s4.add(Box.createHorizontalStrut(800));
     
   	 JPanel pan4 = new JPanel();
   	 pan4.setLayout(new BorderLayout());
   	 pan4.setBackground(Color.yellow);
   	 pan4.setBorder(new TitledBorder(new EtchedBorder(), "Chinese Food"));
   	 pan4.add(fourth, BorderLayout.WEST);
   	 pan4.add(s4,BorderLayout.EAST);
   	 tabbedPane.addTab("Chinese",null,pan4,"fourth Panel");
   	 
   	 Box fifth = Box.createVerticalBox();
   	 fifth.add(new JLabel ("Please note that 1 portion = 10 plates"));    	 
   	 fifth.add(Box.createVerticalStrut(10));  
   	 fifth.add(new JLabel ("Portions of Kbab:"));     	 
   	 fifth.add(kbab);     	 
   	 fifth.add(new JLabel ("Portions of Shawerma:"));     	 
   	 fifth.add(shaw);
   	 fifth.add(new JLabel ("Portions of Shish Tawooq:"));
   	 fifth.add(shish);
   	 fifth.add(new JLabel ("Portions of Taboola:"));
   	 fifth.add(tab);
   	 fifth.add(calc3);
   	 fifth.add(Box.createVerticalStrut(30));  
   	 calc3.addActionListener(this); 	 
     fifth.add(total1);
     fifth.add(Box.createVerticalStrut(550));     

     Box s5 = Box.createHorizontalBox();
   	 s5.add(new JLabel (""));
   	 s5.add(new JLabel (""));   	 
     s5.add(Box.createHorizontalStrut(800));
     
   	 JPanel pan5 = new JPanel();
   	 pan5.setLayout(new BorderLayout());
   	 pan5.setBackground(Color.pink);
   	 pan5.setBorder(new TitledBorder(new EtchedBorder(), "Oriental Food"));
   	 pan5.add(fifth, BorderLayout.WEST);
   	 pan5.add(s5,BorderLayout.EAST);
   	 tabbedPane.addTab("Oriental",null,pan5,"fifth Panel");
    
    add (tabbedPane);
    
}
  public void actionPerformed(ActionEvent e)
    {
    	double bar1,sam1,tan1,cur1,stot1,tot1,guest,disc=0,servi=0,them=0;
    	       	if (spy.getState())
  		{
  			disc=0.3;
  		}
  		else if(spn.getState())
  		{
  		 disc=0;
 		}
 		
 		if(thy.getState())
  		{
  		them=150;
  		}
  		else if(thn.getState())
  		{
  		 them=0;
 		}
 		
 		
        if(sery.getState())
  		{
  		servi=300;
  		}
  		else if(sern.getState())
  		{
  		servi=0;
 		}
 		
    	if (e.getSource()==calc)
    	{
    		bar1=Double.parseDouble(bary.getText());
    		bar1=bar1*40;
    		sam1=Double.parseDouble(sam.getText());
    		sam1=sam1*5;
    		tan1=Double.parseDouble(tand.getText());
    		tan1=tan1*60;
    		cur1=Double.parseDouble(cury.getText()); 
    		cur1=cur1*60;
    		guest=Double.parseDouble(t3.getText());
    		guest=guest*15;
    		stot1=bar1+sam1+tan1+cur1+guest;
    		tot1=(stot1*disc)+servi+them;  		  		
    		total1.setText("Your total is " + stot1);    		
        }
        
        double laz1,pas1,piz1,spg1;
           	
    	if (e.getSource()==calc1)
    	{
    		laz1=Double.parseDouble(laz.getText());
    		laz1=laz1*60;
    		piz1=Double.parseDouble(piz.getText());
    		piz1=piz1*50;
    		pas1=Double.parseDouble(pas.getText());
    		pas1=pas1*60;
    		spg1=Double.parseDouble(spg.getText()); 
    		spg1=spg1*60;
    		guest=Double.parseDouble(t3.getText());
    		guest=guest*15;
    		stot1=spg1+pas1+piz1+laz1+guest;
    		
    		total1.setText("Your total is " + stot1);            
    }
    
    double vr1,ssc1,shr1,nod1;
    if (e.getSource()==calc2)
    	{
    		
    		vr1=Double.parseDouble(vr.getText());
    		vr1=vr1*30;
    		ssc1=Double.parseDouble(ssc.getText());
    		ssc1=ssc1*50;
    		nod1=Double.parseDouble(nod.getText());
    		nod1=nod1*30;
    		shr1=Double.parseDouble(shr.getText()); 
    		shr1=shr1*60;
    		guest=Double.parseDouble(t3.getText());
    		guest=guest*15;
    		stot1=vr1+ssc1+nod1+shr1+guest;
    		
    		total1.setText("Your total is " + stot1);
      
      
    }
    
    double shish1,kbab1,tab1,shaw1;
    if (e.getSource()==calc3)
    	{
    		
    		shish1=Double.parseDouble(shish.getText());
    		shish1=shish1*50;
    		kbab1=Double.parseDouble(kbab.getText());
    		kbab1=kbab1*50;
    		tab1=Double.parseDouble(tab.getText());
    		tab1=tab1*30;
    		shaw1=Double.parseDouble(shaw.getText()); 
    		shaw1=shaw1*40;
    		guest=Double.parseDouble(t3.getText());
    		guest=guest*15;
    		stot1=shish1+kbab1+tab1+shaw1+guest;
    		
    		total1.setText("Your total is " + stot1);
      
      
       }
       
    }
    
    
  
  
public static void main(String[] args) {

MainClass tabbedPaneFrame = new MainClass();  	
tabbedPaneFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tabbedPaneFrame.setSize(400,480);
tabbedPaneFrame.setVisible(true);
}
}

please please please
this is urgent
can anyone help me

Recommended Answers

All 3 Replies

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
at java.lang.Double.parseDouble(Double.java:510)
at MainClass.actionPerformed(MainClass.java:263)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)

Read carefully runtime errors!

By default your TextField-s are initialized with empty String ==> ""
Initialize them with String representation of zero ==> textFieldxxx.setText("0"); But this is only half of work. You need indicate to user, all inproper values in textField-s.

I'm a beginner in this stuff >.<
mmm
I didn't get you when u said

But this is only half of work. You need indicate to user, all inproper values in textField-s.

sorry for the not understanding much but I've been working on this all day the teacher didn't explain so this is all personal effort. my brain is just dry from thinking.

thanx

All TextField instances initialize with "0".
==> textFieldxxx.setText("0");
In constuctor of MainClass() add all the lines:

public MainClass(){
	
	super ("Raja's Catering");
// inserted lines
t1.setText("0"); 
t2.setText("0"); 
t3.setText("0"); 

bary.setText("0"); 
cury.setText("0"); 
tand.setText("0"); 
sam.setText("0"); 
piz.setText("0"); 
pas.setText("0"); 
laz.setText("0"); 
spg.setText("0"); 
ssc.setText("0"); 
shr.setText("0"); 
nod.setText("0"); 
vr.setText("0"); 
shaw.setText("0"); 
kbab.setText("0"); 
shish.setText("0");
tab.setText("0"); 
//...

In TextField you can write all chars, but in your case only numbers are valid.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.