4 Replies - 264 Views - Last Post: 03 October 2013 - 10:12 AM Rate Topic: -----

#1 Bilal22  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 03-October 13

Calculation1 its about ticketing machine

Posted 03 October 2013 - 05:58 AM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Calculation1 extends JFrame
        implements ActionListener {

   

    JLabel numTwoLabel = new JLabel("                                                                 HOW MUCH TICKETS YOU WANT                                                                        ");
   
    JTextField numTwoTxt = new JTextField(3);
    JTextField commentTxt = new JTextField(5);
    JButton sumBtn = new JButton("Get Total");
    JButton sumBtn3 = new JButton("Continue");
     
     JLabel sumBtn1= new JLabel("                                                                                    I N S E R T     M O N E Y                                                                                 ");
      JButton sumBtn2 = new JButton(                                "  G E T   B A L A N C E "                                        );
     	JTextField commentTxt1 = new JTextField(5);
        
        JTextField number = new JTextField(  5 );
    
    
    
   
    

    public static void main(String[] args) {
        Calculation1 jf = new Calculation1();
    }

    public Calculation1() {
        setLayout(new FlowLayout());
        setSize(600, 300);
        setTitle("Adding");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
      
        
        add(numTwoLabel);
        add(numTwoTxt);
        add(sumBtn);
        add(commentTxt);
        add(sumBtn1);
        add(number);
        add(sumBtn2);
        add(commentTxt1);
         add(sumBtn3);
        sumBtn.addActionListener(this);
        sumBtn2.addActionListener(this);
        sumBtn3.addActionListener(this);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        
        int numTwo = Integer.parseInt(numTwoTxt.getText());
        int sum = 10 * numTwo;
        String numTxt = Integer.toString(sum);
        String message = "  \n RM " +  numTxt;
        commentTxt.setText(message);
    	
    	int numTwo1 = Integer.parseInt(number.getText());
        int sum1 = message - numTwo1 ;
        String numTxt1 = Integer.toString(sum);
        String message1 = "  \n RM " +  numTxt1;
         commentTxt1.setText(message1);
    	
     	        }
    
      }
      
      
    



Actually, all things are working ok but , i want that the answer that we get after clicking "GET TOTAL" will get subtracted by any value that we right in the text box of insert money and the subtracted answer will come in the last text box when we click GET BALANCE

Is This A Good Question/Topic? 0
  • +

Replies To: Calculation1 its about ticketing machine

#2 Bilal22  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 03-October 13

Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 06:12 AM

replyy guyzzz
Was This Post Helpful? 0
  • +
  • -

#3 ChrisNt  Icon User is online

  • D.I.C Addict

Reputation: 201
  • View blog
  • Posts: 631
  • Joined: 31-July 13

Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 06:25 AM

And which is the problem that occurs?
Was This Post Helpful? 0
  • +
  • -

#4 Bilal22  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 03-October 13

Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 08:34 AM

the first calculation of multiply is orking but the subtraction one is not working .... I want to subtract the sum of the answer of multiplication with any number i type and get the answer when i click get blance
Was This Post Helpful? 0
  • +
  • -

#5 ChrisNt  Icon User is online

  • D.I.C Addict

Reputation: 201
  • View blog
  • Posts: 631
  • Joined: 31-July 13

Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 10:12 AM

Now all your JButtons have the same action ,in this method you have to check which button is pressed and do the appropriate action.

public void actionPerformed(ActionEvent e) {
       Object source = e.getSource();

       if (source == firstButton ) {
           doThis();
       }
       else if ( source == secondButton ) {
           doThat();
       }
       else if ( source == thirdButton ) {
           doSomethingElse();
       }     
}

This post has been edited by ChrisNt: 03 October 2013 - 10:14 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1