• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JButton and general swing problems  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ..
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i make the UI show .
In main, after instantiate a object of your class, call it's show() method.
You may have just won ten million dollars! Or, maybe a tiny ad.
ScroogeXHTML - small and flexible RTF to HTML converter library
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!