Display users input

Hi i have a text field where users enter a value between 1-9. When i input 3 for example and display it i get

You entered 51.

Code

publicvoid keyPressed(KeyEvent evt)

{

int temp = evt.getKeyCode();

if( m_nShapesToDraw == 0 )

{

JOptionPane.showMessageDialog(MainWindow.this,"First if.");

if(( temp >= KeyEvent . VK_0 ) && ( temp <= KeyEvent . VK_9 ) )

{

JOptionPane.showMessageDialog(MainWindow.this,"second if.");

m_nShapesToDraw = temp;

hasEnteredValue =true;

cPanel.repaint() ;

JOptionPane.showMessageDialog(MainWindow.this,"third if.");

JOptionPane.showMessageDialog(MainWindow.this,"you enterend" +" " + temp);

}

}

Can somone tell me why i get 51 instead of 3? Does that mean it isn't really 3? Thanks

Message was edited by:

nvidia1

[1350 byte] By [nvidia1a] at [2007-11-26 18:49:43]
# 1

Why are you still using a JOptionPane when all your other components are AWT components?

If you are allowed to use a Swing component in whatever you are building then you should be using all Swing components.

Your code would be much simpler using Swing components (JTextField, instead of a TextField...). The way you handle the entering of data is ugly and thats because you are using old techniques design for AWT. Its much easier in Swing and the code is cleaner.

> Can somone tell me why i get 51 instead of 3?

Read the KeyEvent API to see what the difference between the keyCode and keyChar is.

camickra at 2007-7-9 6:23:45 > top of Java-index,Java Essentials,Java Programming...