Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008, 01:18 AM
Member
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0
jesicapalma is on a distinguished road
Question 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
  #2 (permalink)  
Old 03-25-2008, 05:02 AM
sylvpan's Avatar
Member
 
Join Date: Mar 2008
Location: beijing,China
Posts: 5
Rep Power: 0
sylvpan is on a distinguished road
Send a message via MSN to sylvpan
Thumbs up 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, 12:07 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default

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.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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 02:08 PM
Addition program that displays the sum of two numbers Java Tip Java Tips 0 03-28-2008 09:46 PM
Using Columns With JTextField The Evil Genius AWT / Swing 1 03-17-2008 02:01 AM
Varargs – Java 5.0 addition JavaForums Java Blogs 0 11-13-2007 05:40 PM
help with JTextfield gary New To Java 4 07-11-2007 02:58 PM


All times are GMT +2. The time now is 05:11 PM.



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