Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: JOptionPane Help

    so this should all take place within my NumbersToWords class?

  2. #22
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: JOptionPane Help

    Sure, it can really happen anywhere.

  3. #23
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: JOptionPane Help

    okay, so I got it working, and now everytime I use it, it works fine, however I keep getting errors.
    this is the error I keep getting, it happens when I remove the text in the box:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "4Type Here"
    	at java.lang.NumberFormatException.forInputString(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at NumbersToWords$LiveListener.keyReleased(NumbersToWords.java:33)
    	at java.awt.Component.processKeyEvent(Unknown Source)
    	at javax.swing.JComponent.processKeyEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    here are my methods:
    Java Code:
    JTextField input, output;
    	
    	public void LivePrint()
    	{
    		JFrame window = new JFrame("Live Printer");
    		JPanel livePanel = new JPanel();
    		input = new JTextField("Type Here", 30);
    		input.addKeyListener(new LiveListener());
    		output = new JTextField("Output happens here live!", 30);
    		
    		livePanel.add(input);
    		livePanel.add(output);
    		
    		window.add(livePanel);
    		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		window.pack();
    		window.setLocationRelativeTo(null);
    		
    		window.setVisible(true);
    	}
    	
    	class LiveListener implements KeyListener
    	{
    		public void keyType(KeyEvent keyEvent){}
    		public void keyPressed(KeyEvent keyEvent){}
    		public void keyReleased(KeyEvent keyEvent)
    		{
    			int number = Integer.parseInt(input.getText());
    			output.setText(input(number));
    		}
    		@Override
    		public void keyTyped(KeyEvent arg0) {
    			// TODO Auto-generated method stub
    			
    		}
    	}

  4. #24
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: JOptionPane Help

    NumberformatException happens when you try to convert letters into a number. You should do a try/catch block so when that happens, you can pop up a message to the user and tell then to enter only numbers.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. JOptionPane
    By louiedogg418 in forum New To Java
    Replies: 3
    Last Post: 07-03-2011, 06:04 PM
  2. Help with JOptionPane
    By sanctishit in forum New To Java
    Replies: 1
    Last Post: 03-10-2010, 10:20 AM
  3. Help with JOptionPane
    By SwEeTAcTioN in forum New To Java
    Replies: 12
    Last Post: 11-03-2009, 04:12 AM
  4. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 02:04 AM
  5. JOptionPane
    By whosadork in forum New To Java
    Replies: 2
    Last Post: 10-23-2008, 02:17 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
  •