Results 1 to 2 of 2
  1. #1
    LogicBrix is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Post Problem in Buttons ...

    there's a little problem in my code ... But theres n

    when i click the buttons i got this message ....

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:994)
    at java.lang.Double.parseDouble(Double.java:510)
    at HotelBill.actionPerformed(HotelBill.java:265)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6038)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3260)
    at java.awt.Component.processEvent(Component.java:580 3)
    at java.awt.Container.processEvent(Container.java:205 8)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4410)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2116)
    at java.awt.Component.dispatchEvent(Component.java:42 40)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429 )
    at java.awt.Component.dispatchEvent(Component.java:42 40)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)



    here my whole code



    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class HotelBill extends JFrame implements ActionListener{
    	
    
    		
          
            JButton btn = new JButton();
            JButton b = new JButton("Check the room?");
            	
            JButton btn2 = new JButton();
            JButton b2 = new JButton("Check the room?");
            	
            JButton btn3 = new JButton();
            JButton b3 = new JButton("Check the room?");
            
            JButton btn4 = new JButton();
            JButton b4 = new JButton("Check the room?");		
            
            JButton btn5 = new JButton();
            JButton b5 = new JButton("Check the room?");	
       		
       		JButton btn6 = new JButton();
            JButton b6 = new JButton("Check the room?");
       
       		JButton btn7 = new JButton();
            JButton b7 = new JButton("Check the room?");
            	
            JButton btn8 = new JButton();
            JButton b8 = new JButton("Check the room?");
            		
       		JButton btn9 = new JButton();
            JButton b9 = new JButton("Check the room?");
            
            
            
            	
            JTextField txt = new JTextField();//Hotel Name
            JTextField txt2 = new JTextField();//Price
        //    JTextField txt3 = new JTextField();//Total
            JTextField DoN = new JTextField();//Day or night
            JTextField txt5 = new JTextField();//Quantity
           
           
           
           
           //Buttons Images ////////////////////
           Icon ic = new ImageIcon("image2/Economy Room.jpg  ");
           Icon i = new ImageIcon("image2/Economy Room2.jpg   ");
           
           Icon ic2 = new ImageIcon("image2/Stan.jpg  ");
           Icon i2 = new ImageIcon("image2/Stan2.jpg  ");
           
           Icon ic3 = new ImageIcon("image2/Deluxe.jpg  ");
           Icon i3 = new ImageIcon("image2/Deluxe2.jpg  ");
           
           Icon ic4 = new ImageIcon("image2/Suit.jpg  ");
           Icon i4 = new ImageIcon("image2/Suit2.jpg");
           
           Icon ic5 = new ImageIcon("image2/VIP.jpg  ");
           Icon i5 = new ImageIcon("image2/VIP2.jpg ");
           
           Icon ic6 = new ImageIcon("image2/Pres.jpg  ");
           Icon i6 = new ImageIcon("image2/Pres2.jpg ");
           
           Icon ic7 = new ImageIcon("image2/Hos.jpg  ");
           Icon i7 = new ImageIcon("image2/Hos2.jpg ");
           
           Icon ic8 = new ImageIcon("image2/Pent.jpg  ");
           Icon i8 = new ImageIcon("image2/Pent2.jpg");
           
           Icon ic9 = new ImageIcon("image2/Per.jpg  ");
           Icon i9 = new ImageIcon("image2/Per2.jpg  ");
           
           //////////////////////////////////////////////////////
           
           ImageIcon icon = new ImageIcon("image2/HotelBill.jpg");
            JLabel BG = new JLabel(icon);
            
            Font font = new Font("Times New Roman",Font.BOLD,14);
            
            	
            	
            	
       		
        public HotelBill() {
        	setLayout(null);
        	
        	//Bounds///////////////////////
        	btn.setBounds(50,200,200,40);
        	b.setBounds(50,250,200,20);
        	
        	btn2.setBounds(250,200,200,40);
        	b2.setBounds(250,250,200,20);
       	
        	btn3.setBounds(450,200,200,40);
        	b3.setBounds(450,250,200,20);
         
        	btn4.setBounds(50,300,200,40);
        	b4.setBounds(50,350,200,20);
        		
        	btn5.setBounds(250,300,200,40);
        	b5.setBounds(250,350,200,20);
        	
        	btn6.setBounds(450,300,200,40);
        	b6.setBounds(450,350,200,20);
        	
        	btn7.setBounds(50,400,200,40);
        	b7.setBounds(50,450,200,20);
        	
        	btn8.setBounds(250,400,200,40);
        	b8.setBounds(250,450,200,20);
        	
        	btn9.setBounds(450,400,200,40);
        	b9.setBounds(450,450,200,20);
        	
        	DoN.setBounds(720,500,100,25);
        	
       		txt.setBounds(720,200,200,40);
        	txt2.setBounds(720,280,200,40);
        //	txt3.setBounds(720,463,200,40);
        //	txt4.setBounds(720,537,200,40);
        	txt5.setBounds(720,388,150,25);
        	
        	
        	BG.setBounds(0,0,1000,700);
        	
        	////////////////////////////////
        	
        	//Buttons iCons ///////////
        	
        	btn.setIcon(ic);
        	btn.setRolloverIcon(i);
        	
        	btn2.setIcon(ic2);
        	btn2.setRolloverIcon(i2);
        	
        	btn3.setIcon(ic3);
        	btn3.setRolloverIcon(i3);
        	
        	btn4.setIcon(ic4);
        	btn4.setRolloverIcon(i4);
        	
        	btn5.setIcon(ic5);
        	btn5.setRolloverIcon(i5);
        	
        	btn6.setIcon(ic6);
        	btn6.setRolloverIcon(i6);
        	
        	btn7.setIcon(ic7);
        	btn7.setRolloverIcon(i7);
        	
        	btn8.setIcon(ic8);
        	btn8.setRolloverIcon(i8);
        	
        	btn9.setIcon(ic9);
        	btn9.setRolloverIcon(i9);
        	
        	
        	///////////////////////////////////////////
        	
        	
       
        	
        	
        	
        	
        	
        	
        	
        	//////////////////////////////////////
        	
        	//Layout///////////////
        	add(btn);
        	add(b);
        	add(btn2);
        	add(b2);
        	add(btn3);
        	add(b3);
        	add(btn4);
        	add(b4);
        	add(btn5);
        	add(b5);
        	add(btn6);
        	add(b6);
        	add(btn7);
        	add(b7);
        	add(btn8);
        	add(b8);
        	add(btn9);
        	add(b9);
        	
        	
        	add(DoN);
        	
        	
        	
        	add(BG);
        	
        	add(txt);
        	txt.setFont(font);
        	add(txt2);
        	txt2.setFont(font);
        //	add(txt3);
        //	txt3.setFont(font);
        //	add(txt4);
        //	txt4.setFont(font);
        	add(txt5);
        	txt5.setFont(font);
        	/////////////////////////
        	
        	
        	//Handler///////////////
        	btn.addActionListener(this);
        	b.addActionListener(this);
        	
        	btn2.addActionListener(this);
        	b2.addActionListener(this);
        	
        	btn3.addActionListener(this);
        	b3.addActionListener(this);
        	
        	btn4.addActionListener(this);
        	b4.addActionListener(this);
        	
        	btn5.addActionListener(this);
        	b5.addActionListener(this);
        	
        	btn6.addActionListener(this);
        	b6.addActionListener(this);
        	
        	btn7.addActionListener(this);
        	b7.addActionListener(this);
        	
        	btn8.addActionListener(this);
        	b8.addActionListener(this);
        	
        	btn9.addActionListener(this);
        	b9.addActionListener(this);
        	
        	
        	/////////////////////////////
        	
        	setSize(1000,700);
        	setVisible(true);
        	setResizable(false);
        	setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
        
         public void actionPerformed (ActionEvent e ){
         	
         	double Eco = 39000;
         	double Stand = 27000;
         	double DL = 54000;
         	double Sui = 25000;
         	double vi = 65000;
         	double pres = 75000;
         	double hosp = 50000;
         	double ph = 80000;
         	double perf = 55000;
         	
         	
         	double num1 = Double.parseDouble(txt.getText());                 //  if i erase this code.. 
    		double num2 = Double.parseDouble(txt2.getText());       //   i dont get that message and my program run properly ,, i think the problem is in here
    		
          
         	
         	if(e.getSource() == btn){
         		txt.setText("Economy Room");
         		txt2.setText("39,000");
         		
         		
         	}
         	else if(e.getSource() == btn2){
         		txt.setText("Standard Room");
         		txt2.setText("27,000");
         		
         	}
         	else if(e.getSource() == btn3){
         		txt.setText("De Luxe");
         		txt2.setText("54,000");
         		
         	}
         	else if(e.getSource() == btn4){
         		txt.setText("Suite Room");
         		txt2.setText("25,000");
         		
         	}
         	else if(e.getSource() == btn5){
         		txt.setText("V.I.P Room");
         		txt2.setText("65,000");
         		
         	}
         	else if(e.getSource() == btn6){
         		txt.setText("Presidential Room");
         		txt2.setText("75,000");
         		
         	}
         	else if(e.getSource() == btn7){
         		txt.setText("Hospitality Suite");
         		txt2.setText("50,000");
         		
         	}
         	else if(e.getSource() == btn8){
         		txt.setText("Pent House");
         		txt2.setText("80,000");
         		
         	}
         	else if(e.getSource() == btn9){
         		txt.setText("Perfected Room");
         		txt2.setText("55,000");
         		
         	}
         	
       //////////////////////////////////////////
       
       			
         	
         	
         	
         	
         	
         	
         	
         	
         	
         	
         	
         }
       
       
       
        public static void main(String[] args) {
            HotelBill hb = new HotelBill();
        }
    }


  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem in Buttons ...

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:994)
    at java.lang.Double.parseDouble(Double.java:510)
    at HotelBill.actionPerformed(HotelBill.java:265)
    At line 265 you need to test if the String you are trying to parse is empty before trying to parse it.
    See the String class for methods for testing it.

Similar Threads

  1. problem pressing buttons
    By mike28 in forum Java Applets
    Replies: 10
    Last Post: 10-30-2011, 03:19 AM
  2. Problem in assigning randomed buttons
    By thesonyuh in forum New To Java
    Replies: 8
    Last Post: 09-18-2011, 03:30 AM
  3. Buttons Problem
    By Coold0wn in forum New To Java
    Replies: 3
    Last Post: 08-25-2011, 06:02 PM
  4. Renaming Buttons Problem
    By Huskies in forum New To Java
    Replies: 11
    Last Post: 07-29-2011, 12:53 AM
  5. [B]Tab Sequence problem with radio buttons[/B]
    By shobha2k8 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-25-2008, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •