Results 1 to 2 of 2
Thread: Help with Multiplication
- 12-06-2007, 01:32 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 1
- Rep Power
- 0
Help with Multiplication
i have a text box with the name jTextField1. and am trying to multiply the value that you enter in it by 0.12. im not sure at all of even where to start and what exactly i need to declare.
therfore if anybody can help me with some example code or formula then that would be a great help because im very new to the java language..
thanks
- 12-06-2007, 07:39 PM #2
In pseudo code:
Java 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.
Similar Threads
-
Help with multiplication table
By Albert in forum New To JavaReplies: 1Last Post: 07-10-2007, 04:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks