Forums Register Login

JButton and general swing problems

+Pie Number of slices to send: Send
//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
+Pie Number of slices to send: Send
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 ..
+Pie Number of slices to send: Send
how can i make the UI show .
In main, after instantiate a object of your class, call it's show() method.
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1094 times.
Similar Threads
GUI
Issue with repainting second frame
Java Rookie Programming Question
Java Rookie Help Requested
Concept of inheritance vs polymorphism
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:34:46.