Show Balance

Ads

 
 

Share on Google+Share on Google+

Andrew Jackson
Show Balance
2 Answer(s)      6 years and 3 months ago
Posted in : Java Beginners

Hi I have a simple program I put together and it runs ok but I want it to "store the console input" from the first number, and subtract the second number from it showing the balance... JOptionPane comeup just fine and everything else works fine I just want it to store the numbers in the buffer and subtract num2 from num1 and show the remaining balance.... any help in this little problem is greatly appreciated.. NewGuy...

Ads
View Answers

July 11, 2011 at 11:17 AM


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  SubtractionOfNumbers{

    public static void main(String[] args){
    JFrame f=new JFrame();
    JLabel label1=new JLabel("First Number: ");
    JLabel label2=new JLabel("Second Number: ");
    JLabel label3=new JLabel("Result: ");
    final JTextField text1=new JTextField(20);
    final JTextField text2=new JTextField(20);
    final JTextField text3=new JTextField(20);
    JButton button=new JButton("Calculate");
        button.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
               int num1=Integer.parseInt(text1.getText());
               int num2=Integer.parseInt(text2.getText());
               int result=0;
               if(num1>num2){
                   result=num1-num2;
               text3.setText(Integer.toString(result));
               }
               else{
                    result=num2-num1;
               text3.setText(Integer.toString(result));
               }

               }
            });
        JPanel p=new JPanel(new GridLayout(4,2));
        p.add(label1);
        p.add(text1);
        p.add(label2);
        p.add(text2);
        p.add(label3);
        p.add(text3);
        p.add(button);

        f.add(p);
        f.setVisible(true);
        f.pack();
    }
}


July 11, 2011 at 11:17 AM


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  SubtractionOfNumbers{

    public static void main(String[] args){
        String number1=JOptionPane.showInputDialog(null,"Enter Number1: ");
        int num1=Integer.parseInt(number1);
        String number2=JOptionPane.showInputDialog(null,"Enter Number2: ");
        int num2=Integer.parseInt(number2);
        int result=0;
         if(num1>num2){
                   result=num1-num2;
              JOptionPane.showMessageDialog(null,"Result is: "+Integer.toString(result));
               }
               else{
                    result=num2-num1;
              JOptionPane.showMessageDialog(null,"Result is: "+Integer.toString(result));
               }
    }
}

Ads









Related Tutorials/Questions & Answers:
Show Balance
and subtract num2 from num1 and show the remaining balance.... any help...Show Balance  Hi I have a simple program I put together and it runs..., and subtract the second number from it showing the balance... JOptionPane comeup just fine
leave balance
called emp-leave_balanced(leave-id,leave balance,etc are column),in leave balance column each employee has some leave balance (like 4,5,8 etc)i need to add this leave-balance to another column(that also have common value like 25) i need
Advertisements
Version of com.generallycloud>baseio-balance dependency
List of Version of com.generallycloud>baseio-balance dependency
Maven Dependency baseio-balance >> 3.1.8-Alpha2
You should include the dependency code given in this page to add Maven Dependency of com.generallycloud >> baseio-balance version3.1.8-Alpha2 in your project
Maven Dependency baseio-balance >> 3.1.8-Alpha3
You should include the dependency code given in this page to add Maven Dependency of com.generallycloud >> baseio-balance version3.1.8-Alpha3 in your project
Maven Dependency baseio-balance >> 3.1.8-RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.generallycloud >> baseio-balance version3.1.8-RELEASE in your project
Balance multi-way tree implimentation reating database - Java Beginners
Balance multi-way tree implimentation reating database  I am doning... database like Access,MySQL.As we know database is based on Balance multi-way tree..so we have to implement that Balance multi-way-Tree..Simple data(integer,char
to show graph
to show graph  by clicking on submit button how to show the graph by fetching data in mysql?   Please visit the following link: JSP graph by fetching data in mysql
show codes of this
show codes of this  search for the number of occurrence of "and" and "the" in the following sentence by writing a codes. the student like the best teacher at the end of the lessons and others
how to show popup in javascript
how to show popup in javascript  How to show popup in javascript
hide show keyboard iphone
hide show keyboard iphone  How to hide show keyboard in iPhone programmatically
HTML title show up
HTML title show up  Why doesn't my title show up when I click "check it out
iPhone show activity indicator
iPhone show activity indicator  Hi, How to show activity indicator in iPhone application? Thanks
hide show keyboard iphone
hide show keyboard iphone  How to hide show keyboard in iPhone programmatically
hide show keyboard iphone
hide show keyboard iphone  How to hide show keyboard in iPhone programmatically
php show last query
php show last query  How to show the last updated record from the database in PHP? Is there any query that i need to write in the php script
how to show data in database ?
how to show data in database ?  how to show the data in the database to the user in the textbox so that user can modify it and save it again
UITableview show more
UITableview show more  How to fetch more records from the sql database in UITableview using show more option when there is a large amount of data? Thanks
php show list of files
php show list of files  How can i pull the limited number of files in PHP
Show me the code for that
Show me the code for that  JVM on my machine? And how do I know whether its working
HOW TO SHOW TIME SERIES
HOW TO SHOW TIME SERIES  hi................ i require a small code in java swings to display the output as time series. Can u plz help???????? Reply....... thanks in advance
Show results in HTML
Show results in HTML  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram... as one value, trichy as one value. and i have to show it in html. how to do
Problem in show card in applet.
Problem in show card in applet.  The following link contained... but Not show card in the applet, then I add a code in paintComponent method like... can I show all the card in the applet. Work I have done:- 1) Create Dynamic web
show_source() example.
show_source() The show_source() function works similar to highlight_file... Syntax show_source (filename, return) Note: This function displays the entire...;?php if ( isset( $file ) ) show_source( $file ) or print "can not be open
Countdown timer to show a link
Countdown timer to show a link  Hi to everyone! I have this code, which is basically a countdown widget...what I want is that when the countdown finish, a link appears. The thing is that my musical group will be presenting an EP
show my plain HTML source
show my plain HTML source  Why does the browser show my plain HTML source
diff betn show n visible
diff betn show n visible  what is difference between show() & visible method in java
show the database values graphical represantation
show the database values graphical represantation   show the database values graphical represantation and auto refresh for every 30 secand displaying in webpage
hide and show result in jsp
hide and show result in jsp  what codes do i have to change to make my result display if only i enter the correct value? suppose if i click search,then the result will be display at the bottom.. if not.. only the header
show data - Servlet Interview Questions
show data   firstly, how can call a class in servlet . and show multiple user data in Servlet with the help of Arraylist . and add or remove data in servlet without database
How you will Show unique records.
How you will Show unique records.  How you will Show unique records.   Hi, Here is the query which shows the unique records- SELECT DISTINCT columnname FROM tablename; Thanks

Ads

 
Advertisement null

Ads