Show Balance

Show Balance

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...

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
ModuleNotFoundError: No module named 'balance'
ModuleNotFoundError: No module named 'balance'  Hi, My Python... 'balance' How to remove the ModuleNotFoundError: No module named 'balance... to install padas library. You can install balance python with following command
Advertisements
Version of com.generallycloud>baseio-balance dependency
List of Version of com.generallycloud>baseio-balance dependency
ModuleNotFoundError: No module named 'boi-balance'
ModuleNotFoundError: No module named 'boi-balance'  Hi, My Python... 'boi-balance' How to remove the ModuleNotFoundError: No module named 'boi-balance' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'boi-balance'
ModuleNotFoundError: No module named 'boi-balance'  Hi, My Python... 'boi-balance' How to remove the ModuleNotFoundError: No module named 'boi-balance' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'mobile-balance'
ModuleNotFoundError: No module named 'mobile-balance'  Hi, My... named 'mobile-balance' How to remove the ModuleNotFoundError: No module named 'mobile-balance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'boi-balance'
ModuleNotFoundError: No module named 'boi-balance'  Hi, My Python... 'boi-balance' How to remove the ModuleNotFoundError: No module named 'boi-balance' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'color_balance'
ModuleNotFoundError: No module named 'color_balance'  Hi, My... 'color_balance' How to remove the ModuleNotFoundError: No module named 'color_balance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tallinja-balance'
ModuleNotFoundError: No module named 'tallinja-balance'  Hi, My... named 'tallinja-balance' How to remove the ModuleNotFoundError: No module named 'tallinja-balance' error? Thanks   Hi, In your
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
ModuleNotFoundError: No module named 'iota_balance_change_alert'
ModuleNotFoundError: No module named 'iota_balance_change_alert'  Hi...: No module named 'iota_balance_change_alert' How to remove the ModuleNotFoundError: No module named 'iota_balance_change_alert' error? Thanks  
ModuleNotFoundError: No module named 'iota_balance_change_alert'
ModuleNotFoundError: No module named 'iota_balance_change_alert'  Hi...: No module named 'iota_balance_change_alert' How to remove the ModuleNotFoundError: No module named 'iota_balance_change_alert' error? Thanks  
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting'
ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting...: ModuleNotFoundError: No module named 'odoo10-addon-account-balance-reporting' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-balance
ModuleNotFoundError: No module named 'odoo10-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo10-addon-account-tax-balance' ...: ModuleNotFoundError: No module named 'odoo10-addon-account-tax-balance' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance-report'
ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance...: ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance-report...;odoo10-addon-l10n-es-account-balance-report' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance-report'
ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance...: ModuleNotFoundError: No module named 'odoo10-addon-l10n-es-account-balance-report...;odoo10-addon-l10n-es-account-balance-report' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance' ...: ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance' ...: ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo11-addon-l10n-ro-report-trial-balance'
ModuleNotFoundError: No module named 'odoo11-addon-l10n-ro-report-trial-balance...: ModuleNotFoundError: No module named 'odoo11-addon-l10n-ro-report-trial-balance...-report-trial-balance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line' ...: ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-account-balance-line'
ModuleNotFoundError: No module named 'odoo12-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo12-addon-account-tax-balance' ...: ModuleNotFoundError: No module named 'odoo12-addon-account-tax-balance' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-account-tax-balance'
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance-report'
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance...: ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance-report...;odoo12-addon-l10n-it-account-balance-report' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance-report'
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance...: ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-account-balance-report...;odoo12-addon-l10n-it-account-balance-report' error? Thanks   Hi, In your

Ads