Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Andrew Jackson
Show Balance
2 Answer(s)      3 years and a month 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...


Advertisement
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));
               }
    }
}


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
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
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
iPhone show activity indicator
iPhone show activity indicator  Hi, How to show activity indicator in iPhone application? Thanks
HTML title show up
HTML title show up  Why doesn't my title show up when I click "check it out
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
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
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
Show me the code for that
Show me the code for that  JVM on my machine? And how do I know whether its working
php show list of files
php show list of files  How can i pull the limited number of files in PHP
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
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
diff betn show n visible
diff betn show n visible  what is difference between show() & visible method in java
show my plain HTML source
show my plain HTML source  Why does the browser show my plain HTML source
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
JavaScript Show Date
JavaScript Show Date          In this section... the current date. Here is the code: <html> <h2>Show
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
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
Program in javascript to show the current location
Program in javascript to show the current location  Hi All, Actually in my application ..i wanted to updated the current location each time it gets loads...so, can you give me a simple program in javascript to show the current
Show Limited Data Using jquery
Show Limited Data Using jquery  How to show limited results in JQuery? For example i have 10 results but only 5 need to be displayed. How to achieve it using JQuery?   See the JQuery example to show the limited fetch
JavaScript Show Hide table
JavaScript Show Hide table...; In this section, we are going to show and hide table on clicking the button using.... On clicking the button 'Show', the function showTable() is called and the table
show selected date range in calender
show selected date range in calender  helo, i'm working in a project in jsp. suppose thier are 2 textbox 1.start date 2. end date whatever date selected in these textbox get highlighted in the calendar, please help
Show Clippings
Show Clippings       In this section, you will study how to show the clip. Clip is an art which... are providing you an example where we will show you the clippings. In the example
how to show random image in ASP.net?
how to show random image in ASP.net?  hello bros i saw in many websites..there is a programming of random image changing.... i want to use this in my ASP.NET websites, can any one suggest me code or any kind of help..so that i
How to show the maximum and the minimum in array...
How to show the maximum and the minimum in array...  I have a bookstore application, but I cannot show the maximum and the minimum price of the book. Please see my codes below. import java.util.*; public class Book{ public
How to show the maximum and the minimum in array...
How to show the maximum and the minimum in array...  I have a bookstore application, but I cannot show the maximum and the minimum price of the book. Please see my codes below. import java.util.*; public class Book{ public
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
how to show required fields indicate as * in struts2
how to show required fields indicate as * in struts2  how to show required fields indicate as * in struts2
Show Confirmation Dialog on Click the Command Link
Show Confirmation Dialog on Click the Command Link  How to show Confirmation Dialog when user Click the Command Link
browser show my plain HTML source.
browser show my plain HTML source.   Why does the browser show my plain HTML source
Show Hide Text Javascript - Java Beginners
Show Hide Text Javascript  Please tell me how to show hide text using Java Script
Jquery Hide and Show Div
Using jQuery effects one can perform lots of task such as Hide, Show, Toggle, Slide, Fade, and Animate the Text. In the article we have discussed Show and Hide methods in Java. .show() in jQuery is used to display the matched elements
How you will Show all data from a table.
How you will Show all data from a table.   How you will Show all data from a table.   Hi, following query is used to show all the data of the table- SELECT * FROM tablename; Thanks
Show a hidden frame previously from another from
Show a hidden frame previously from another from  How can i show a hidden frame previously by this code: jframe_name.hide(); and make it visible from another frame i'm waiting for the answer, and i'll be thankfull
What is a Fashion Show Designer?
What is a Fashion Show Designer? As the name suggests, the fashion show designer is the person that takes care of all the aspects of a fashion show... it takes to actually be a fashion show designer, stick with us and we'll make
Show Hibernate generated SQL statements on console
Show Hibernate generated SQL statements on console  How can i see Hibernate generated SQL statements on console?   In Hibernate configuration file add the following: <property name="show_sql">true</property>
Show mu;tiple DIV contents in a page
Show mu;tiple DIV contents in a page  Hi All; I want to show... boxes, i did that using function toggle(show... = 'none'; } if (show) { document.getElementById(show
combox value are not show in a JSP - JSP-Servlet
combox value are not show in a JSP  i have a combo box in a JSP after submit it does not show its value in logic.jsp Home.jsp: <... show null. please let me how i can find the value of combo box on logic.jsp.
show, hide, disable components on a page with struts - Struts
show, hide, disable components on a page with struts  disabling a textbox in struts.. in HTML its like disable="true/false" how can we do it in struts
Advertisements
 

 

 

DMCA.com