View Single Post
  #2 (permalink)  
Old 12-06-2007, 09:39 PM
hardwired hardwired is online now
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
In pseudo code:
Code:
JTextField textField = new JTextField(12); textField.addActionListener(new ActionListener() { double factor = 0.12; public void actionPerformed(ActionEvent e) { // User has pressed return/enter to get here: JTextField textField = (JTextField)e.getSource(); String text = textField.getText(); // Take care that text is parsable... double d = Double.parseDouble(text); d *= factor; textField.setText(String.valueOf(d)); } }); // Add textField to your gui... // Or, test with something like: JOptionPane.showMessageDialog(null, textField, "", -1); // Pretend the user has typed in the value "25" // Programmatically we could do it with: textField.setText(25); // User presses the "return/enter" key while // textField has the focus (blinking caret) // which generates an ActionEvent which is // reported to all listeners registered to // recieve ActionEvents from/on this textField.
Reply With Quote