The Artima Developer Community
Sponsored Link

Java Answers Forum
adding text fields

2 replies on 1 page. Most recent reply: Apr 22, 2005 6:41 AM by Thomas Eichberger

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
steven low

Posts: 1
Nickname: st20
Registered: Apr, 2005

adding text fields Posted: Apr 20, 2005 11:01 AM
Reply to this message Reply
Advertisement
Hi guys im new to java and I wanna know how I got about adding a few text boxes togther. in the same calss I have designed the gui and have the button showing now i wanna method for example

textbox 1 + texbox2 / textbox3 = textbox4

how would that be done within the button listener


below example is my button method

views.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

//Adding text feilds togther here how


}
});

Thank you


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: adding text fields Posted: Apr 20, 2005 10:49 PM
Reply to this message Reply
You can't add Objects. That would be like adding one chair to another.
What's a TextBox by the way? In Java we have TextFields, TextAreas, ... but no TextBox.
You probably mean JTextField.

Should this be a mathematical operation?

The methods you need are getText(), Double.parseDouble(), setText().

Use getText() to get the content of the other fields.
Use parseDouble() to convert the String to a number. Then calculate your new value, at the end use setText() to set the content of the new "TextBox"

Thomas Eichberger

Posts: 4
Nickname: xtraclass
Registered: Aug, 2003

Re: adding text fields Posted: Apr 22, 2005 6:41 AM
Reply to this message Reply
String s = textbox1.getText() + textbox2.getText();

Flat View: This topic has 2 replies on 1 page
Topic: PDA Programming using J2ME Previous Topic   Next Topic Topic: Get insert record OID after inserting a record

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use