Results 1 to 2 of 2
  1. #1
    phil028 is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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

  1. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 04:44 PM

Posting Permissions

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