Take result from adding 2 txtboxes 2gether then label.setText = result ?

I have 2 text boxes and I want to add [mathimatically +] their contents together then dispaly the result in a label when a button in clicked. I am using Net Beans 6. I have not found how to do this online so any help would be apriciated.
Code Follows:
* uconverter.java
* Created on January 12, 2008, 11:32 AM
package show_label;
* @author vb
public class uconverter extends javax.swing.JPanel {
/** Creates new form uconverter */
public uconverter() {
initComponents();
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
hellolb = new javax.swing.JLabel();
answer_btn = new javax.swing.JButton();
num1_txt = new javax.swing.JTextField();
num2_txt = new javax.swing.JTextField();
result_lb = new javax.swing.JLabel();
hellolb.setText(null);
answer_btn.setText("jButton1");
answer_btn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
answer_btnMouseClicked(evt);
num1_txt.setText("Hi");
num1_txt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num1_txtActionPerformed(evt);
num2_txt.setText("Hi");
num2_txt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
num2_txtActionPerformed(evt);
result_lb.setText("Result");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(num1_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(num2_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(hellolb)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(answer_btn)
.addGap(152, 152, 152))))
.addGroup(layout.createSequentialGroup()
.addGap(53, 53, 53)
.addComponent(result_lb)
.addContainerGap())))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(num1_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hellolb)
.addComponent(result_lb))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answer_btn)
.addComponent(num2_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(186, Short.MAX_VALUE))
}// </editor-fold>
private void num1_txtActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
private void answer_btnMouseClicked(java.awt.event.MouseEvent evt) {
answer_lb.setText("num1" + "num2");
private void num2_txtActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Variables declaration - do not modify
private javax.swing.JButton answer_btn;
private javax.swing.JLabel hellolb;
private javax.swing.JTextField num1_txt;
private javax.swing.JTextField num2_txt;
private javax.swing.JLabel result_lb;
// End of variables declaration
Code Ends
Thanks for any help

* Get text from a text field with JTextComponent's getText(). (A JTextField is a JTextComponent).
* Convert text->number with Integer.parseInt() or Double.parseDouble()
* Add with +
* Convert back number->text with String.valueOf()
* Set a label's text with JLabel's setText()
http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html#getText()
http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/Double.html#parseDouble(java.lang.String)
http://java.sun.com/javase/6/docs/api/javax/swing/JLabel.html#setText(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/String.html#valueOf(int)
Suppose I have a text field leftTF displaying "12" another, rightTF displaying "6" and a JButton called addBut. I want to put the answer in a JLabel called answerLabel. Then I use something like the following in my code:
import awt.event.ActionListener;
import awt.event.ActionEvent;
// In a method somewhere
addBut.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        updateAnswerLabel();
// Somewhere else - and this, finally is the answer to your question
    /** TODO: What if the user enters junk in the text fields? */
private void updateAnswerLabel() {
    int left = Integer.parseInt(leftTF.getText()); // left is now 12
    int right = Integer.parseInt(rightTF.getText()); // right is 6
    answerLabel.setText(String.valueOf(left + right)); // label displays "18"
        // or just
    //answerLabel.setText("" + left + right);
Class names in Java invariably begin with a capital letter, so UConverter not uconverter.
Use meaningful and readable variable and method names. I mean you should - Netbeans won't. This IDE seems to have a morbid fear of imports and an unnatural love of long but inexpressive names ending with a digit.
Indeed, consider putting NetBeans aside for a bit and using a plain text editor (possibly a syntax colouring one like TextPad). Folk will cite various reasons for this, but your post illustrates one that doesn't always get a mention: all that code, just to ask how to add things together? This IDE seems to make it very difficult to construct brief, minimal examples which illustrate a problem.
(And please use the code tags when you post: put {code} at the start of your code and again at the end. That way your code is readable when it's posted here.)
Also a little point about the event listener: I've used an ActionListener, not a MouseLIstener. That's because what's important is the button "firing", not a mouse being clicked. A mouse click is a common way of causing a button to fire. But so is a press of the space bar while the button has focus. Your code would miss this.

Similar Messages

  • I want to take files from my PC (using a Seagate external hard drive) then plug this Seagate External hard drive into my Mac Book Pro and move the files from the Seagate External Hard drive onto my Time Capsule. I do not want to put these files on my Mac

    I want to take files from my PC (using a Seagate external hard drive) then plug this Seagate External hard drive into my Mac Book Pro and move the files from the Seagate External Hard drive onto my Time Capsule. I do not want to put these files on my Mac. How do I do this? Where do I put these files on my Time Capsule? Will it affect the functioning of my Time Capsule?

    Mixing files with data is not always great idea.
    See info here.
    Q3 http://pondini.org/TM/Time_Capsule.html
    Why not just connect the PC directly to the TC by ethernet and copy the files over?
    It is hugely faster and much less mucking around.
    In windows load the airport utility for windows.. if you have not already as this will help you access the drive.
    There is more info here.
    http://support.apple.com/kb/HT1331

  • My 27" iMAC is less than 3 month old. Many times regardless of what application I am in the screen will start shifting  back and forth left to right. Then I can't do anything until the screen stabilizes. This takes anywhere from 5 to 25 secs. Any ideas?

    My 27" iMAC is less than 3 month old. Many times regardless of what application I am in the screen will start shifting  back and forth left to right. Then I can't do anything until the screen stabilizes. This takes anywhere from 5 to 25 secs. Any ideas?

    why don't you take advantage of the free 90 days of AppleCare and utilize the free, professional telephone support from Apple instead of asking in the forums?

  • I am tring to import files into Aperture, permanently, from files on  my desktop. Aperture will import them, but when I take those files away from the desktop they also then leave Aperture?    Help appreciated     thanks   joanlvh

    I am tring to import files into Aperture, permanently, from files on my desktop. Aperture will import them, but when I take those files away from the desktop they also then leave Aperture?    Help appreciated     thanks   joanlvh

    You can seelct to leace the files where they are, copy into Aperture or else put them someplace else on the HD.
    What is your setting?

  • ITunes Security - Keeping the babysitter from adding songs to iTunes Lib.

    This is a nube question, but is there a way to limit access to the iTunes program so that anyone can play from the library but not add to it? Password protection for additions perhaps?
    This question is the result of a babysitter who brought over her MP3 CD collection. I now see all of the songs she played in the iTunes Library.
    My main concern is to make sure that her songs are not anywhere on my computer (for the obvious legal reasons... and also because I don't enjoy that type of music).
    I currently have 6GB of legit music that I don't want to remove, so if there is an automatic way to remove all of her music (at once) by date entered it would also be helpful. I also do not see a folder for her music within the iTunes folder.
    Thank you,
    Decussation
    AMD Athlon 64   Windows XP  

    Well to remove her songs that were added to iTUnes. open iTunes in the main library, hit the "Date added" Header to organize the list by date. Then seect the first song of hers, hold down the ctrl key and selct each one of hers. after that let go of the key and rightclick then select "Clear". this will claer them off iTunes and if the songs are actually on your PC you will get a message asking if you want to move them to the recycle bin, click yes and then empty the recycle bin.
    I don't know how to stop iTunes from adding things, But if you allow the babysitter on your PC, you may want to consider setting up user accounts on your PC in windows. You can do this by going to the control panel and selecting "User Accounts". you can turn on the "Guest" account or set up a user account for him/her. This would allow you to lock or password protect folders, and lock the CD drive from being used.
    iTunes comes with a "Share" feature that will allow her to listen to your music on her account. you will have to move or copy your songs to the "Shared Documents" folder tho I think.

  • Preventing select-string from adding additional undesired strings in the output file

    Hi friends
    in PS 4.0 i am trying to write a function which
    step1: export the list of all eventlogs ----> wevtutil el > "$home\documents\\loglist1.txt"
    step2: deleted the following two lines from loglist1.txt
    DebugChannel
    Microsoft-RMS-MSIPC
    ( the reeson of deleting these two lines is wevtutil cl command, can't clear these two evenlogs among approximately 1000 logs)
    in fact via select-string with -pattern -notmatch parameters, we select anything except these two line
    step3:  pastes the select-string contents into the same file ("$home\documents\loglist1.txt") or into new text file (for example
    "$home\documents\loglist2.txt")
    here is my code:
    function MycleareventsAll {
    cls
    Wevtutil el > "$home\documents\loglist1.txt"
    $mycontents = select-string "$home\documents\loglist1.txt" -pattern DebugChannel, Microsoft-RMS-MSIPC -NotMatch
    cd "$home\documents\"
    $mycontents | out-file loglist2.txt"
    # also i tried ---> $mycontents | set-content "loglist2.txt"# also i tried ---> $mycontents | set-content "loglist1.txt"
    but the problem is, in addition of deletion, unfortunatelly additional strings (filepath, filename, line number) are added into the final text file so wevtutil will fail clearing logs listed in text file.
    here is contents of the final text file
    C:\Users\Administrator\documents\loglist.txt:1:Analytic
    C:\Users\Administrator\documents\loglist.txt:2:Application
    C:\Users\Administrator\documents\loglist.txt:4:DirectShowFilterGraph
    but i need the contents be the same as original file without that two specific line:
    Analytic
    Application
    DirectShowFilterGraph
    i searched but i didn't find a way to prevent select-string cmdlet from adding these edditional strings
    (filepath, filename, line number) into output file while keeping the original contents.
    note: -quiet parameter is not what i want. it removes all contents & simply inserts a true or false.
    any help? 

    don't forget that Guys here know the basics of security such as clearing event logs & ...
    how odd if you don't know this.
    clearing all events is useful in test environment for example when i ma teaching my students & need to see all newly created events & work on them
    Then you are teching your students how not to use an event log.  We use filters and queries to access event logs.  We also use event log CmdLets in PowerShell.  WEVTUTIL is ok but it does not marry wellwith PowerShell as you have seen.
    I have found very few people who are not certified in WIndows administration that know much about eventlogs when it should be a ver important part of administration.  PowerShell has mmade EL management much easier but few take the time to learn how
    to use the EL support in PowerShell.
    I see no point inclearing event logs.  It accomplishes nothing.
    ¯\_(ツ)_/¯
    oh your are introducing me filters & queries in event viewer !! please stop Laughing me this way.
    your problem is you judge about people's knowledge & you persist on your absurd judgments.
    look at your sentence:
    "Then you are teaching your students how not to use an event log" 
    where from you tell this? have you been present in my classes to see what i teach to my students?
    have you seen that i told to my students not to use event viewer?
    my goal of clearing events is related to myself. it's non of your businesses.
    people are not interested to here concurrent irrelevant advises from you like a grandmother. they are searching for a solution. their intent of doing tasks is not up to you.

  • Does anyone how to take music from ipod and put it on to my computer?

    does anyone how to take music from ipod and put it on to my computer? i desperatly need to do that so please help me!!!! i will download software if i need to

    If you are using iTunes version 7 or later, then you can transfer purchased iTunes store music from the iPod to an authorized computer by using the "file/transfer purchases from iPod" menu. Note that the maximum of 5 authorized computers applies here.
    For all other non purchased music (your own CDs etc) try this method which works on some Windows PCs.
    Enable your iPod for disk use.
    See: iPod Disk Use.
    Open iTunes and select edit/preferences/advanced/general. Put a check mark in the box marked "copy files to iTunes music folder when adding to library" and also "keep iTunes music folder organized", then click 'ok'.
    Connect the iPod whilst holding down the shift/ctrl keys to prevent any auto sync, and if you see the dialogue window asking if you want to sync to this itunes library, click 'no'.
    Then go to file/add folder, open 'my computer', select your iPod and click 'ok'.
    The music files should transfer to your iTunes.
    If this doesn't work (and it may not because officially it's not supposed to), check out the instructions/suggestions here.
    Music from iPod to computer (using option 2). This a manual method using "hidden folders" and although it works, it can be messy.
    Much easier ways are to use one of the many 3rd party programs that copy music from the iPod to the computer.
    One of the most recommended is Yamipod. This is a free program that transfers music and playlists etc from iPod back to the computer. However, it does not transfer playcounts/ratings etc.
    Another free program is Pod Player.

  • Good morning, i would like to know how to take pictures from iphoto and put them in a folder on desktop

    Good morning: would like to know how to take pictures from my iphoto and put them in a folder on my desktop

    To take photos from iPhoto and put them onto a folder on Desktop, first create a folder on Desktop. Right-click on Desktop and create a new folder.
    Then, open iPhoto, and you have two ways to export photos:
    1. Select the photos you want to copy to Desktop with Command key (or go to Edit menu > Select All, if you want to copy all photos), and then, drag them to the folder on Desktop.
    2. Select the photos you want to copy to Desktop with Command key, go to File menu > Export, and follow the steps.
    You can choose the one you prefer

  • How can I take text from a webpage that is in multiple rows and move it into a single row in Excel?

    I need help figuring out how to take data from internet pages and enter it into one single row in an excel, or numbers if that is the easier way to go.  I was also told access might be good to use.  Basically I am going to chamber of commerce page and wanting to extract the member listing and enter in a database in a single line.  The  data is in different numbers of lines as you will see below (info edited to take out personal info). So I want to take the  name of business, business owner, address, city, state, zip, and phone and put it into one line on a spreadsheet.  I want to do this many times over. I think there is a way to do it through apple script and automator, but I have not been successful after 2 weeks of trying and searching.  I have over 800 listings and I surely don't want to go through and do them one at a time.  Any suggestions?
    Data from website:
    Westrock Coffee
    Mr.
    Collins Industrial Place
    North Little Rock, AR 72113
    Phone:
    Send Email
    Member Since: 2011
    Sweet Creations by DJ
    Ms. J
    allace Bridge Road
    Perryville, AR 72126
    Phone:
    Fax:
    Send Email
    Member Since: 2013
    See Also Woman Owned and/or CEO
    Premium Refreshment Service
    Mr. E
    est Bethany Road
    North , AR 72117
    I want it to look like this
    Company name, owner name, address, city, state, zip, phone
    How can I get the extra data out of the way and remove the format so that it will go into excel?  Thanks for any help you can provide.  I am not to savvy with code, but I got a friend who is an IT guy that can help.  Thanks again

    So, basically, create 800 individual entries, each one containing everything from business name through the phone (not fax) number, add some commas and spaces to entries, and then put each entry on a separate line?
    1. Go to website page such as this one-- http://www.littlerockchamber.com/CWT/External/WCPages/WCDirectory/Directory.aspx ?ACTION=newmembers --which seems formatwise very close to what you're trying to scrape.
    2. Cmd-A to select all. Cmd-C to copy it to clipboard.
    3. Open freeware TextWrangler. Cmd-V to paste info from clipboard into a blank TW document.
    4. Remove lines from top and bottom so that only membership list remains.
    5. Process lines to remove everything from "Fax" line through "See Also" line. Only business name through phone number will remain in the file.
    --A. TW > Text > Process Lines containing . . .
    -----(check "Delete matched lines"; uncheck all others)
    -----Enter "Send Email" in the search box.
    -----Click Process.
    --B. Repeat 5A for other lines to be removed
    ------Member Since
    ------See Also
    ------Fax
    6. Insert markers to separate entries:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: \r\r\r\r
    ------in replace box: \r***
    ------Click Replace All
    7. Remove remaining blank lines:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: \r\r
    ------in replace box: \r
    ------Click Replace All
    8. Add comma and space at end of each line:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: $
    ------in replace box: ,  (comma space)
    ------Click Replace All
    9. Remove all returns:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: \r
    ------in replace box: (leave blank)
    ------Click Replace All
    10. Insert returns in place of markers:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: \*\*\*,  (backslash asterisk backslash asterisk backslash asterisk comma space)
    ------in replace box: \r
    ------Click Replace All
    11. Remove trailing comma and blank on each line:
    TW: Search > Find . . .
    ------(check "Wrap around" and "Grep")
    ------in Find box: , $ (comma space dollar sign)
    ------in replace box: (leave blank)
    ------Click Replace All
    Import this text file into Excel or Numbers.

  • Mac won't take power from the mains

    Hi,
    I just bought my MacBook two days back. I'm already finding a few things crashing, but my main headache is that its currently refusing to take power from the mains. I take out the power chord and put it back in... nothing. I've tried restarting - no go. I've changed socket, no difference (the sockets are working fine). I noticed that the MagSafe Power Adaptor was pretty hot when I first spotted this problem. Any ideas?
    Cheers,
    Robin

    Hi robin
    All I can offer is to keep doing what you're doing that's kept it going up till now - whatever that is? As soon as you've got time take it back.
    I find it slightly strange that you're prepared to risk 'some urgent work' using something that's clearly having a problem? However if it's all you have then I suppose you have no choice? If there's enough 'juice' to let you complete whatever it is you need to do and if you've a memory stick or can burn a CD/DVD then I would look at those options once you've done the work.
    You never know?
    Tony

  • I have an extensive aperture library on my computer's hard drive and I want to break it up into separate smaller libraries on external hard drives.  How do I take projects from one library and add them to another one?

    I have an extensive aperture library on my computer's hard drive and I want to break it up into separate smaller libraries on external hard drives.  How do I take projects from one library and add them to another one?

    Coastal,
    Frank gave you the exact answer to your question. 
    However, I would like to ask if you are indeed asking the right question.  Do you really want different libraries?  The implications are that you have to "switch" libraries to see what's in the others, and so that your searches don't work across all of your pictures?  If so, then you asked the right question.  If not, you may be more interested in relocating your masters to multiple hard drives so your library gets smaller, instead of breaking up the library.
    nathan

  • When i take a picture with my iphone and then forward the picture in an email (regardless of picture size) it will not send - any thoughts????? Thanks.

    When I take a picture with my iPhone and then forward the picture to an emaila ddress (regardless of picture size) it will not send the email with the pciture enclosed - any thoughts on how to fix ?????
    Thanks -

    The collum to the right listed similar problems.  The solution appears to be that under smtp outgoing settings the user name and password are listed as optional.  I have not plugged in the information and it seems to be working.  However from my office it always allowed the relaying.  The true test will be when I try to respond later from the road.
    Thank you for your help.

  • How do you take pictures from one library and put in another library??

    How do you take pictures from one library and put in another library??

    Options:
    1. Export from iPhoto A to the Finder, then import to iPhoto B
    This gets the photo over, but no versions, no edit history and not all the metadata
    2. Use iPhoto Library Manager
    This gets everything: versions, edit history and all the metadata.
    Regards
    TD

  • Hello and Thank You for your help!, I recently uninstalled malware from my computer. Since then I cannot open my gmail account and retrieve my email. ail.

    I removed the ASK tool bars from my computer and since then I keep being told the cookies is either enabled or disabled. I refreshed Firefox and that solved nothing it just erased somethings that I setup on my desktop. I'm not dump but I'm not that well versed in resolving this issue and I don't want to make matters worse.......please help! And thank you so much! One more thing......I can still retrieve my email using Explorer but chose not to because of the lack of support for XP which is what I have. Again Thank You

    Good afternoon and thank you John99!... for the reply and advice to my problem the other day. To give some insite to the issue I presented...the ASK toolbar was somehow downloaded onto my laptop and I not knowing that it was as malware and dangerous to my computer at first I left there. I did not like the fact that it was there and how it seemed to take over my setup. Well I looked into it which was fairly easy and found out what I did about Mindspark...not good! I also discovered while trying to solve the problem after receiving you responseto this problem that JAVA ORACLE can carry the Ask toolbar thru their updates. When OKed an update I found it wanting to add the ASK toolbar. I know that in the past I have not allowed other things that carry the ASK toolbar to download this because I liked what I had already setup. Well some where along the way it got downloaded. Anyway...I tried what you had suggested and nothing has changed. I receive email's thru Exployer and bring up my desktop to get onto Mozilla. This is not working!!! I just want to get onto Firefox, click into gmail and anything else I want and use it!..I can assure you that the one thing I cannot do is get into my gmail. It wants to tell my about my cookies...I have pressed all the right buttons and this is not solving anything at all. I was wandering that if I remove Firefox and download it again will this solve the problem. And will I be able to use all the same information or will I find it telling me that someone else already has that email, password, name, etc. because it did not clear everything when I removed Firefox from my computer? Remember, I'm not an expert on computers so any information you may have or suggestions you can give would be highly appreciated but step by step details are also welcome and needed! Again...Thank You so much, truly! Diana12

  • OM:Cost of Goods sold work flow customization to take it from concerned off

    OM:Cost of Goods sold work flow customization to take it from concerned office in the place of inventory org

    Yes FOX can be difficult to achieve things that are simpler than simple
    The way you described, it will only search fo a standard price on the same currency.
    Try to set the currency as changeable characteristic and then search prices for each possible currency.
    standard price value  = {standard price, currency1} +                 {standard price, currency2} etc..
    The possible currencies could also be filled in a variable which is read at runtime.
    Don't know an easier way!
    Regards,
    Beat

Maybe you are looking for