Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008, 02:18 AM
Member
 
Join Date: Mar 2008
Posts: 1
jesicapalma is on a distinguished road
jTextField Simpe Addition - how to ? - Netbeans 6.0
Hello everybody,

i have a problem that for many people who know Java may 'll seems funny .

In NetBeans 6.0, i have three jTextFields and one Button1 .

jTextField1, jTextField2, jTextField3, Button1 .

to the jTextField1 and jTextField2 i gave for text value the number of 30 so that we have that jTextField1 =30 and jTextField2 = 30 .

I want when i click on the button1 (jButton1MouseClicked) addition to start and to get the sum of the first and second jTextField, so 30+30 = 60 .

This 60, i want to be written into jTextField3 .

I tried lot of ways but no success

..please help

waiting for your answers , thankx in advance !
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-25-2008, 06:02 AM
sylvpan's Avatar
Member
 
Join Date: Mar 2008
Location: beijing,China
Posts: 5
sylvpan is on a distinguished road
Send a message via MSN to sylvpan
you can handled this by javascript
<script>
function button_click(){
var text1 = document.getElmentById('txt1');
var value1 = text1.value.parseInt();
var text2 = document.getElmentById('txt1');
var value2 = text2.value.parseInt();
var text3 = document.getElmentById('txt2');
text3.value = value1+value2;
}
</script>
I hope this answer can fit for you requirement!
__________________
one for all,all for one!
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-25-2008, 01:07 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga

Welcome jesicapalma... to Java Forums.

If you are working on Netbeans it is much easy. You no need to worry about the design of GUI at all. I think it is ok for you.

As you said add three jTextFields and a button. To get the button event simply double-click on the button. You may comes with a method like this.

Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }
Then move to the functionality. Simply add following code segment in that method.

Code:
int valueOne = Integer.parseInt(jTextField1.getText()); int valueTwo = Integer.parseInt(jTextField2.getText()); int sum = valueOne + valueTwo; jTextField3.setText(String.valueOf(sum));
Hope it is help to you.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to focus to another JTextfield? birdofprey AWT / Swing 2 04-09-2008 03:08 PM
Addition program that displays the sum of two numbers Java Tip Java Tips 0 03-28-2008 10:46 PM
Using Columns With JTextField The Evil Genius AWT / Swing 1 03-17-2008 03:01 AM
Varargs – Java 5.0 addition JavaForums Java Blogs 0 11-13-2007 06:40 PM
help with JTextfield gary New To Java 4 07-11-2007 03:58 PM


All times are GMT +3. The time now is 02:26 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org