# Calculation1 its about ticketing machine

Page 1 of 1

## 4 Replies - 333 Views - Last Post: 03 October 2013 - 10:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=330631&amp;s=8524b1b943b642a35bc6d91e4add6f9e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Bilal22

Reputation: -1
• 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);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

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

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

## Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 06:12 AM

### #3 ChrisNt

• cute bug

Reputation: 251
• Posts: 811
• Joined: 31-July 13

## Re: Calculation1 its about ticketing machine

Posted 03 October 2013 - 06:25 AM

And which is the problem that occurs?

### #4 Bilal22

Reputation: -1
• 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

### #5 ChrisNt

• cute bug

Reputation: 251
• Posts: 811
• 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