hi, can u help me.when i click at the checkbox,the data in the checkbox should appear in the number ofperson textbox..but i cannot pass the data to the textbox.any solution...thanx in advance..here's the codes:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
public class Cinema extends JFrame implements ItemListener, ActionListener
{
private JLabel lblName,lblIC, lblPN, lblPerson, lblTicket, lblTP;
private JTextField txtName, txtIC, txtPN, txtPerson, txtTicket, txtTP;
private JRadioButton btnA, btnB, btnC, btnD, btnE, btnF;
private ButtonGroup radioGroup;
private JCheckBox cbxA1, cbxA2, cbxA3, cbxA4, cbxA5, cbxA6, cbxA7, cbxA8, cbxB1, cbxB2, cbxB3, cbxB4, cbxB5, cbxB6, cbxB7, cbxB8, cbxC1, cbxC2, cbxC3, cbxC4, cbxC5, cbxC6, cbxC7, cbxC8, cbxD1, cbxD2, cbxD3, cbxD4, cbxD5, cbxD6, cbxD7, cbxD8, cbxE1, cbxE2, cbxE3, cbxE4, cbxE5, cbxE6, cbxE7, cbxE8;
private JButton btnCalc, btnClear, btnP, btnExit;
private JPanel pnlMovie, pnl1, pnlSits, pnl2, pnlDetail, pnl3, pnlTicket, pnl4, pnlCalculate, pnlCalc, pnlP, pnlPrint;
public Cinema()
{
super ("Movie Cinema");
Container cont = getContentPane();
lblName = new JLabel ("Customer Name : ");
lblIC = new JLabel ("IC Number. : ");
lblPN = new JLabel ("Phone Number : ");
lblTicket = new JLabel ("Ticket Price : ");
lblPerson = new JLabel ("Number Of Person : ");
lblTP = new JLabel ("Total Price : ");
txtName = new JTextField (10);
txtIC = new JTextField (10);
txtPN = new JTextField (10);
txtTicket = new JTextField (7);
txtTicket.setEditable(false);
txtPerson = new JTextField (3);
txtPerson.setEditable(false);
txtTP = new JTextField (7);
txtTP.setEditable(false);
btnA = new JRadioButton("Karate Kid");
btnB = new JRadioButton("Terminator 3");
btnC = new JRadioButton("The Fast And The Furious");
btnD = new JRadioButton("MR & MRS Smith");
btnE = new JRadioButton("Universal Soldier");
btnF = new JRadioButton("Night At The Museum");
radioGroup = new ButtonGroup();
radioGroup.add(btnA);
radioGroup.add(btnB);
radioGroup.add(btnC);
radioGroup.add(btnD);
radioGroup.add(btnE);
radioGroup.add(btnF);
cbxA1 = new JCheckBox ("A-1");
cbxA2 = new JCheckBox ("A-2");
cbxA3 = new JCheckBox ("A-3");
cbxA4 = new JCheckBox ("A-4");
cbxA5 = new JCheckBox ("A-5");
cbxA6 = new JCheckBox ("A-6");
cbxA7 = new JCheckBox ("A-7");
cbxA8 = new JCheckBox ("A-8");
cbxB1 = new JCheckBox ("B-1");
cbxB2 = new JCheckBox ("B-2");
cbxB3 = new JCheckBox ("B-3");
cbxB4 = new JCheckBox ("B-4");
cbxB5 = new JCheckBox ("B-5");
cbxB6 = new JCheckBox ("B-6");
cbxB7 = new JCheckBox ("B-7");
cbxB8 = new JCheckBox ("B-8");
cbxC1 = new JCheckBox ("C-1");
cbxC2 = new JCheckBox ("C-2");
cbxC3 = new JCheckBox ("C-3");
cbxC4 = new JCheckBox ("C-4");
cbxC5 = new JCheckBox ("C-5");
cbxC6 = new JCheckBox ("C-6");
cbxC7 = new JCheckBox ("C-7");
cbxC8 = new JCheckBox ("C-8");
cbxD1 = new JCheckBox ("D-1");
cbxD2 = new JCheckBox ("D-2");
cbxD3 = new JCheckBox ("D-3");
cbxD4 = new JCheckBox ("D-4");
cbxD5 = new JCheckBox ("D-5");
cbxD6 = new JCheckBox ("D-6");
cbxD7 = new JCheckBox ("D-7");
cbxD8 = new JCheckBox ("D-8");
cbxE1 = new JCheckBox ("E-1");
cbxE2 = new JCheckBox ("E-2");
cbxE3 = new JCheckBox ("E-3");
cbxE4 = new JCheckBox ("E-4");
cbxE5 = new JCheckBox ("E-5");
cbxE6 = new JCheckBox ("E-6");
cbxE7 = new JCheckBox ("E-7");
cbxE8 = new JCheckBox ("E-8");
btnCalc = new JButton("Calculate");
btnClear = new JButton("Clear");
btnP = new JButton("Print");
btnExit = new JButton("Exit");
pnlMovie = new JPanel();
pnlMovie.setLayout(new GridLayout(1, 1));
pnlMovie.setBorder(new TitledBorder(new EtchedBorder(),("Type Of Movies")));
pnl1 = new JPanel();
pnl1.setLayout(new GridLayout(2, 3));
pnlSits = new JPanel();
pnlSits.setLayout(new GridLayout(1, 1));
pnlSits.setBorder(new TitledBorder(new EtchedBorder(),("Please Choose Your Sits")));
pnl2 = new JPanel();
pnl2.setLayout(new GridLayout(5, 8));
pnlDetail = new JPanel();
pnlDetail.setLayout(new GridLayout(1, 1));
pnlDetail.setBorder(new TitledBorder(new EtchedBorder(),("Fill In Your Details")));
pnl3 = new JPanel();
pnl3.setLayout(new GridLayout(3, 2));
pnlTicket = new JPanel();
pnlTicket.setLayout(new GridLayout(1, 1));
pnlTicket.setBorder(new TitledBorder(new EtchedBorder(),("Ticket Details")));
pnl4 = new JPanel();
pnl4.setLayout(new GridLayout(4,2));
pnlP = new JPanel();
pnlP.setLayout(new FlowLayout());
pnlP.setBorder(new TitledBorder(new EtchedBorder(),("Print ticket")));
pnlPrint = new JPanel();
pnlPrint.setLayout(new FlowLayout());
pnlMovie.add(pnl1);
pnlSits.add(pnl2);
pnlDetail.add(pnl3);
pnlTicket.add(pnl4);
pnlP.add(pnlPrint);
pnl1.add(btnA);
pnl1.add(btnB);
pnl1.add(btnC);
pnl1.add(btnD);
pnl1.add(btnE);
pnl1.add(btnF);
pnl2.add(cbxA1);
pnl2.add(cbxA2);
pnl2.add(cbxA3);
pnl2.add(cbxA4);
pnl2.add(cbxA5);
pnl2.add(cbxA6);
pnl2.add(cbxA7);
pnl2.add(cbxA8);
pnl2.add(cbxB1);
pnl2.add(cbxB2);
pnl2.add(cbxB3);
pnl2.add(cbxB4);
pnl2.add(cbxB5);
pnl2.add(cbxB6);
pnl2.add(cbxB7);
pnl2.add(cbxB8);
pnl2.add(cbxC1);
pnl2.add(cbxC2);
pnl2.add(cbxC3);
pnl2.add(cbxC4);
pnl2.add(cbxC5);
pnl2.add(cbxC6);
pnl2.add(cbxC7);
pnl2.add(cbxC8);
pnl2.add(cbxD1);
pnl2.add(cbxD2);
pnl2.add(cbxD3);
pnl2.add(cbxD4);
pnl2.add(cbxD5);
pnl2.add(cbxD6);
pnl2.add(cbxD7);
pnl2.add(cbxD8);
pnl2.add(cbxE1);
pnl2.add(cbxE2);
pnl2.add(cbxE3);
pnl2.add(cbxE4);
pnl2.add(cbxE5);
pnl2.add(cbxE6);
pnl2.add(cbxE7);
pnl2.add(cbxE8);
pnl3.add(lblName);
pnl3.add(txtName);
pnl3.add(lblIC);
pnl3.add(txtIC);
pnl3.add(lblPN);
pnl3.add(txtPN);
pnl4.add(lblPerson);
pnl4.add(txtPerson);
pnl4.add(lblTicket);
pnl4.add(txtTicket);
pnl4.add(lblTicket);
pnl4.add(txtTicket);
pnl4.add(btnCalc);
pnl4.add(btnClear);
pnlP.add(btnP);
pnlP.add(btnExit);
btnA.addItemListener(this);
btnB.addItemListener(this);
btnC.addItemListener(this);
btnD.addItemListener(this);
btnE.addItemListener(this);
btnF.addItemListener(this);
cbxA1.addItemListener(this);
cbxA2.addItemListener(this);
cbxA3.addItemListener(this);
cbxA4.addItemListener(this);
cbxA5.addItemListener(this);
cbxA6.addItemListener(this);
cbxA7.addItemListener(this);
cbxA8.addItemListener(this);
cbxB1.addItemListener(this);
cbxB2.addItemListener(this);
cbxB3.addItemListener(this);
cbxB4.addItemListener(this);
cbxB5.addItemListener(this);
cbxB6.addItemListener(this);
cbxB7.addItemListener(this);
cbxB8.addItemListener(this);
cbxC1.addItemListener(this);
cbxC2.addItemListener(this);
cbxC3.addItemListener(this);
cbxC4.addItemListener(this);
cbxC5.addItemListener(this);
cbxC6.addItemListener(this);
cbxC7.addItemListener(this);
cbxC8.addItemListener(this);
cbxD1.addItemListener(this);
cbxD2.addItemListener(this);
cbxD3.addItemListener(this);
cbxD4.addItemListener(this);
cbxD5.addItemListener(this);
cbxD6.addItemListener(this);
cbxD7.addItemListener(this);
cbxD8.addItemListener(this);
cbxE1.addItemListener(this);
cbxE2.addItemListener(this);
cbxE3.addItemListener(this);
cbxE4.addItemListener(this);
cbxE5.addItemListener(this);
cbxE6.addItemListener(this);
cbxE7.addItemListener(this);
cbxE8.addItemListener(this);
btnCalc.addActionListener(this);
btnClear.addActionListener(this);
btnP.addActionListener(this);
btnExit.addActionListener(this);
cont.add(pnlMovie, BorderLayout.NORTH);
cont.add(pnlSits, BorderLayout.WEST);
cont.add(pnlDetail, BorderLayout.CENTER);
cont.add(pnlTicket, BorderLayout.EAST);
cont.add(pnlP, BorderLayout.SOUTH);
setSize (1084, 284);
setVisible(true);
}
public void itemStateChanged(ItemEvent i)
{
double Total = 0.0, Person = 0;
double A = 5.00;
double B = 6.00;
double C = 5.00;
double D = 7.00;
double E = 6.00;
double F = 5.00;
if(i.getSource() == btnA)
{
if(btnA.isSelected())
Total = A * Person ;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(i.getSource() == btnB)
{
if(btnA.isSelected())
Total = B * Person;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(i.getSource() == btnC)
{
if(btnA.isSelected())
Total = C * Person;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(i.getSource() == btnD)
{
if(btnA.isSelected())
Total = D * Person;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(i.getSource() == btnE)
{
if(btnA.isSelected())
Total = E * Person;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(i.getSource() == btnF)
{
if(btnA.isSelected())
Total = F * Person;
else
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
txtTP.setText(" " + Total);
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource() == btnCalc)
{
double Total = Double.parseDouble(txtTP.getText());
double total = 0.0;
int Person = 0;
if(a.getSource() == btnA)
Total = 6.00 * Person;
if(a.getSource() == btnB)
Total = 5.00 * Person;
if(a.getSource() == btnC)
Total = 5.00 * Person;
if(a.getSource() == btnD)
Total = 7.00 * Person;
if(a.getSource() == btnE)
Total = 6.00 * Person;
if(a.getSource() == btnF)
Total = 5.00 * Person;
txtTP.setText(" " + Total);
}
else if (a.getSource() == btnClear)
{
txtName.setText(" ");
txtIC.setText(" ");
txtPN.setText(" ");
txtTicket.setText(" ");
txtPerson.setText(" ");
}
else if(a.getSource() == btnP)
{
System.out.println("Name : "+txtName.getText()+"\n\nIC Number : "+txtIC.getText()+"\n\nTicket Price : "+txtTicket.getText()+"\n\nNo.Of Person : "+txtPerson.getText());
System.out.println("Sits Number : "+cbxA1.getText()+cbxA2.getText()+cbxA3.getText()+cbxA4.getText()+cbxA5.getText()+cbxA6.getText()+cbxA7.getText()+cbxA8.getText()+cbxB1.getText()+cbxB2.getText()+cbxB3.getText()+cbxB4.getText()+cbxB5.getText()+cbxB6.getText()+cbxB7.getText()+cbxB8.getText()+cbxC1.getText()+cbxC2.getText()+cbxC3.getText()+cbxC4.getText()+cbxC5.getText()+cbxC6.getText()+cbxC7.getText()+cbxC8.getText()+cbxD1.getText()+cbxD2.getText()+cbxD3.getText()+cbxD4.getText()+cbxD5.getText()+cbxD6.getText()+cbxD7.getText()+cbxD8.getText()+cbxE1.getText()+cbxE2.getText()+cbxE3.getText()+cbxE4.getText()+cbxE5.getText()+cbxE6.getText()+cbxE7.getText()+cbxE8.getText());
System.out.println("Movies : "+btnA.isSelected()+""+btnB.isSelected()+btnC.isSelected()+btnD.isSelected()+btnE.isSelected()+btnF.isSelected());
System.out.println("Please show this ticket on the way in");
}
else
System.exit(0);
}
}
class MovieCinema
{
public static void main(String[] args)
{
Cinema c = new Cinema();
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}