calculation in GUI problem  | |
November 5th, 2009, 11:46 AM
|
#1 (permalink)
| | Junior Member
Join Date: Nov 2009
Posts: 1
| calculation in GUI problem
hye..i'm newbie...plz help me..i have problem with calculation in this subclass
what problem i counter is the result i want appear in receipt was not appear..that is 8 field in the receipt..Name,address,Hp.no,Pizza type,size,Quantity,side order and total price..for now what just appear is name,address and hp no..the other i don't know why not appear..and the big problem is about total price..i have insert the price side of the item but that not appear also..thank so much if somebody can help me..this a subclass code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionListener.*;
public class Form extends JFrame implements ActionListener{
private JTextField jtfname,jtfaddress,jtfnotel,jtfquan,jlabName,jlabA dd,jlabtel,jlabtype,jlabquan,jlabsize,jlabside,jla bprice;
private JButton jbtconfirm,jbtmainmenu;
private JCheckBox jcbCW,jcbMS,jcbS,jcbCL,jcbC,jcbB;
private JRadioButton jrbSmall,jrbRegular,jrbLarge,jrbex,jrbalo;
public Form(){
//Create a new panel to hold label and text field
JPanel p1 = new JPanel(new FlowLayout());
p1.setBorder(new TitledBorder("CUSTOMER'S DETAILS"));
p1.setLayout(new GridLayout(5,2));
p1.add(new JLabel("Name:"));
p1.add(jtfname= new JTextField(3));
p1.add(new JLabel("Address:"));
p1.add(jtfaddress= new JTextField(3));
p1.add(new JLabel("No Tel:"));
p1.add(jtfnotel= new JTextField(3));
//Receipt
JPanel receipt = new JPanel(new FlowLayout());
receipt.setBorder(new TitledBorder("YOUR RECEIPT"));
receipt.setLayout(new GridLayout(8,2));
receipt.add(new JLabel("Name:"));
receipt.add(jlabName = new JTextField(8));
receipt.add(new JLabel("Address:"));
receipt.add(jlabAdd = new JTextField(8));
receipt.add(new JLabel("HP.No:"));
receipt.add(jlabtel = new JTextField(8));
receipt.add(new JLabel("Pizza's type:"));
receipt.add(jlabtype = new JTextField(8));
receipt.add(new JLabel("Size:"));
receipt.add(jlabsize = new JTextField(8));
receipt.add(new JLabel("Quantity:"));
receipt.add(jlabquan = new JTextField(8));
receipt.add(new JLabel("Side Order:"));
receipt.add(jlabside = new JTextField(8));
receipt.add(new JLabel("Total price:"));
receipt.add(jlabprice = new JTextField(8));
/*jlabName.setHorizontalAlignment(JTextField.RIGHT) ;
jlabAdd.setHorizontalAlignment(JTextField.RIGHT);
jlabtel.setHorizontalAlignment(JTextField.RIGHT);
jlabtype.setHorizontalAlignment(JTextField.RIGHT);
jlabsize.setHorizontalAlignment(JTextField.RIGHT);
jlabquan.setHorizontalAlignment(JTextField.RIGHT);
jlabside.setHorizontalAlignment(JTextField.RIGHT);
jlabprice.setHorizontalAlignment(JTextField.RIGHT) ;*/
jlabName.setEditable(false);
jlabAdd.setEditable(false);
jlabtel.setEditable(false);
jlabtype.setEditable(false);
jlabsize.setEditable(false);
jlabquan.setEditable(false);
jlabside.setEditable(false);
jlabprice.setEditable(false);
receipt.setBackground(Color.orange);
//add the component
Container container = getContentPane();
container.add(p1,BorderLayout.NORTH);
container.add(receipt,BorderLayout.SOUTH);
//add radio button
JPanel p2= new JPanel();
p2.setBorder(new TitledBorder("TYPE OF PIZZA"));
p2.setLayout(new GridLayout(8,2));
ButtonGroup sizeGroup=new ButtonGroup();
jrbex=new JRadioButton("Extravaganza RM23.80");
jrbex.setSelected(true);
p2.add(jrbex);
sizeGroup.add(jrbex);
jrbalo=new JRadioButton("Aloha Chicken RM23.80");
p2.add(jrbalo);
sizeGroup.add(jrbalo);
container.add(p2,BorderLayout.WEST);
//put check box
JPanel p3 = new JPanel(new FlowLayout());
p3.setLayout(new GridLayout(8,2));
p3.add(jcbCW=new JCheckBox("Chicken Wings RM2.99"));
p3.add(jcbMS=new JCheckBox("Mushroom Soup RM2.99"));
p3.add(jcbS=new JCheckBox("Spaghetti RM5.00"));
p3.add(jcbCL=new JCheckBox("Chicken Lasagna RM3.00"));
p3.add(jcbC=new JCheckBox("Coleslaw RM2.00"));
p3.add(jcbB=new JCheckBox("Breadstick RM2.00"));
p3.setBorder(new TitledBorder("SIDE ORDER"));
getContentPane().add(p3,BorderLayout.EAST);
//Set mnemonic keys for ceck box and radio button
jcbCW.setMnemonic('W');
jcbMS.setMnemonic('M');
jcbS.setMnemonic('S');
jcbCL.setMnemonic('L');
jcbC.setMnemonic('C');
jcbB.setMnemonic('B');
//add radio button
JPanel p4= new JPanel();
p4.setBorder(new TitledBorder("SIZE OF PIZZA"));
p4.setLayout(new GridLayout(7,2));
ButtonGroup sizeGroup2=new ButtonGroup();
jrbSmall=new JRadioButton("Small");
jrbSmall.setSelected(true);
p4.add(jrbSmall);
sizeGroup2.add(jrbSmall);
jrbRegular=new JRadioButton("Regular");
p4.add(jrbRegular);
sizeGroup2.add(jrbRegular);
jrbLarge=new JRadioButton("Large");
p4.add(jrbLarge);
sizeGroup2.add(jrbLarge);
jrbSmall.setSelected(true);
p4.add(new JLabel("QUANTITY:"));
p4.add(jtfquan= new JTextField(1));
jtfquan.setHorizontalAlignment(JTextField.RIGHT);
//ok and menu button
p4.add(jbtconfirm=new JButton("CONFIRM ORDER"));
p4.add(jbtmainmenu=new JButton("MAIN MENU"));
//Register button listener
jbtconfirm.addActionListener(this);
jbtmainmenu.addActionListener(this);
container.add(p4,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jbtconfirm)
{
String name = jtfname.getText();
jlabName.setText(String.valueOf(name));
String address = jtfaddress.getText();
jlabAdd.setText(String.valueOf(address));
String tel = jtfnotel.getText();
jlabtel.setText(String.valueOf(tel));
String type =jlabtype.getInputContext();
jlabtype.setText(String.valueOf(type));
}
if (e.getSource() == jbtmainmenu)
{
secondpage frame = new secondpage();
frame.setTitle("Main Menu");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(400,400);
frame.setLocation(450,170);
frame.setVisible(true);
this.dispose();
}
}
/* // Main method
public static void main(String[] args) {
Form frame = new Form();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setTitle("ORDER FORM");
frame.setSize(600, 600);
frame.setVisible(true);
}*/
} |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |