File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JButton and general swing problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton and general swing problems" Watch "JButton and general swing problems" New topic

JButton and general swing problems

Thay Xianrong

Joined: Apr 12, 2004
Posts: 3
//it is an User Interface that
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class cashPayment extends JFrame implements ActionListener
//declaration of instance variables
JButton cashButton;
JButton cashCardButton;
JButton ATMbutton;
JTextComponent textfield;
JLabel testing;
JButton submit;
double price; // the price that the customer has to pay

public void cashPayment()


Container co = getContentPane();
co.setLayout(null); //using exact placing

cashButton = new JButton("Cash");
cashCardButton = new JButton("CashCard");
ATMbutton = new JButton("ATM");
submit = new JButton("Submit")'
testing = new JLabel("Please choose a mode of payment");
textfield = new JTextComponent();
price = 20;



cashButton.setBounds(30, 30, 50, 70);
cashCardButton.setBounds(30, 90, 50, 70);
ATMbutton.setBounds(30, 150, 50, 70);
submit.setBounds(30, 210, 50, 70);
testing.setBounds(30, 270, 50, 70);
textfield.setBounds(30, 330, 50, 120);

//feel free to correct my bounds, i jus whacked some random numbers into it

testing = new JLabel("testing");

public void actionPerformed(ActionEvent e)

JButton clickedButton = (JButton)e.getSource(); //is this correct?
if (clickedButton == cashButton)
testing.setText("Please enter the amount of cash that you have inserted")
// my compiler asks me to add a " ; " here .. i wonder why
else if (clickedButton == cashCardButton)
testing.setText("Please insert your cash card and enter the amount of money in ur cashcard");
else // is this the correct ending .. ?
testing.setText("Please insert ur ATM card and enter your PIN number");

if (textfield.getText == "")
testing.setText("Please do not leave it blank")
} // my compiler asks me to add a " ; " here too .. arghh
double cashInserted = Integer.parseInt(textfield.getText);

if(cashInserted > price)
testing.setText("Thank you for using our services");
testing.setText("The amount of money inserted is not sufficient, please either insert more cash or choose another method of payment. Thank you");

public static void main(String[] args)
cashPayment sample = new cashPayment(); //i think something's seriously wrong with this statement .. but i do not know what else can i do ..

how can i make the UI show ..
please help .. this is one small part of the overall file .. but i jus need one small sample .. (alot of) thanks in advance ..

btw .. my team have 5 .java files..
i was thinking of calling the .dispose() method of the JFrame (call .dipose(), then draw the next .java file ) .. but i'm extending it .. can super.dipose() work ?
TIA again .. =) , i luv u guys
Thay Xianrong

Joined: Apr 12, 2004
Posts: 3
2nd line .. i didn't complete it .. sorri
//it is an User Interface that allows u to choose ur food, choose a seat and pay for it..

well .. basically .. if u have any general swing tips, jus share .. everyone can benefit ..
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
how can i make the UI show .
In main, after instantiate a object of your class, call it's show() method.
I agree. Here's the link:
subject: JButton and general swing problems
jQuery in Action, 3rd edition