• 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JButton and general swing problems  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//sample
//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.addActionListener(this);
cashCardButton.addActionListener(this);
ATMbutton.addActionListener(this);
submit.addActionListener(this);

co.add(cashButton);
co.add(cashCardButton);
co.add(ATMbutton);
co.add(submit);
co.add(testing);
co.add(textfield);

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
setSize(700,700);
setLocation(0,0);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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
else
{
double cashInserted = Integer.parseInt(textfield.getText);

if(cashInserted > price)
{
testing.setText("Thank you for using our services");
}
else
{
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
Greenhorn
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
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!