hello, i am making a hall pass program for my computer programming class. i am having issues with my jcheckboxes. first off. this file reads from a .txt that just has
greg
john
joe
54343
45777
33444
in it. after the user puts in a correct id number, it displays 4 checkboxes to where they want to go. bathroom, office, nurse, and other. once the user clicks one of the checkboxes, it will remove all the stuff from the panel, and add the name of the person and the time they left. the problem i am having is when the user clicks the checkbox , nothing happens. run this for yourself and see for yourself what happens (if you want of course) this is my final assignment for computer programming and i need help bad lol. i have added an itemlistener, that when the checkbox is selected a boolean = true, then in the actionevents, when the "submit" button is pressed, and the id is correct, and the checkbox boolean is true, it removes all the stuff and puts in all the new elements. i want to say that only the bathroom checkbox has the stuff that it should have to make it work , like added the name and time to the second screen after the 4 checkboxes. also i would like to add that this program compiles just fine, just nothing happens when i click the checkboxes. THANKS IN ADVANCED
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.lang.Object;
import java.io.*;
import javax.swing.event.*;
import javax.swing.JCheckBox;
public class main implements ActionListener
{
JFrame f1,f2;
JPanel p1,p2,p3,p4;
String id,enterstring,name,namestring,idstring,str;
GP g1;
JRadioButton bathroom,office,nurse,other;
JButton submit,returnbutton;
JTextField idnumber;
JLabel idprompt,what,time,namelabel;
boolean show,bathroomb,officeb,nurseb,otherb;
int idnum,counter;
SimpleDateFormat sdf;
String[] namearray;
int[] idarray;
int a,b,idint,enter,teacher;
public main()
{
teacher = 1234567890;
bathroomb = false;
officeb = false;
nurseb = false;
otherb = false;
namearray = new String[3];
idarray = new int[3];
sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");
show=true;
a=0;
b=0;
namelabel = new JLabel("");
bathroom = new JRadioButton("Bathroom");
bathroom.setMnemonic(KeyEvent.VK_C);
bathroom.setSelected(false);
bathroom.addActionListener(this);
counter = 1;
office = new JRadioButton("Office");
office.setMnemonic(KeyEvent.VK_C);
office.setSelected(false);
office.addActionListener(this);
nurse = new JRadioButton("Nurse");
nurse.setMnemonic(KeyEvent.VK_C);
nurse.setSelected(false);
nurse.addActionListener(this);
other = new JRadioButton("Other");
other.setMnemonic(KeyEvent.VK_C);
other.setSelected(false);
other.addActionListener(this);
idprompt = new JLabel("Enter ID Number");
idnumber = new JTextField(14);
f1 = new JFrame("Hall Pass");
f1.setSize(550,200);
Container c1 = f1.getContentPane();
time = new JLabel("left at "+sdf.format(new java.util.Date(System.currentTimeMillis())));
id = "123";
p1 = new JPanel();
p1.setSize(500,150);
p1.setLayout(new BorderLayout());
what = new JLabel("");
bathroom.addItemListener(new Item());
other.addItemListener(new Item());
nurse.addItemListener(new Item());
office.addItemListener(new Item());
returnbutton = new JButton("Return");
returnbutton.addActionListener(this);
submit = new JButton("Submit");
submit.addActionListener(this);
p2 = new JPanel(); //panel to add JLabel and TextField
g1 = new GP();
p1.add(g1,BorderLayout.CENTER);
//g1.setBackground(new RGB(255, 255, 255));
g1.add(idprompt);
g1.add(idnumber);
p2.add(submit);
g1.add(what);
p1.add(p2,BorderLayout.SOUTH); //adds p2 to south (Bottom) Graphics Panel will be added to Center
c1.add(p1);
f1.show();
}
public static void main(String[] args)
{
main m = new main();
}
public class Item implements ItemListener{
public void itemStateChanged(ItemEvent evt) {
if (evt.getStateChange() == ItemEvent.SELECTED) {
if (bathroom.isSelected()){
bathroomb = true;
System.out.println(bathroomb);
}
if (office.isSelected()){
officeb = true;
}
if (nurse.isSelected()){
nurseb = true;
}
if (other.isSelected()){
otherb = true;
}
}
}
}
public void actionPerformed (ActionEvent event)
{
try {
BufferedReader in = new BufferedReader(new FileReader("names.txt"));
if (event.getSource() == returnbutton)
{
f1.show();
}
//idnum = Integer.Parseint(enter);
if (event.getSource() == submit)
{
for(int i=0; i<6; i++){
str = in.readLine().trim() ;
if(i<3){
namearray[a] = str;
a++;
}else{
idarray[b] = Integer.parseInt(str);
b++;
}
}
in.close();
enterstring = idnumber.getText();
enter = Integer.parseInt(enterstring);
for(int b = 0; b< 3; b++)
{
//number 1
if (enter==idarray[0])
{
g1.remove(idnumber);
p1.remove(submit);
g1.remove(what);
g1.remove(idprompt);
p2.remove(submit);
namelabel.setText(namearray[0]);
g1.add(namelabel);
g1.add(bathroom);
g1.add(office);
g1.add(nurse);
g1.add(other);
f1.dispose();
f1.show();
// nurse.addItemListener(new ItemListener() {
if (bathroomb == true){
g1.remove(namelabel);
g1.remove(namelabel);
g1.remove(bathroom);
g1.remove(office);
g1.remove(nurse);
g1.remove(other);
g1.setBackground(Color.red);
p2.add(returnbutton);
namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
g1.add(namelabel);
g1.add(time);
f1.dispose();
f1.show();
}
else
if (officeb == true){
g1.remove(namelabel);
g1.remove(namelabel);
g1.remove(bathroom);
g1.remove(office);
g1.remove(nurse);
g1.remove(other);
g1.setBackground(Color.red);
p2.add(returnbutton);
namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
g1.add(namelabel);
g1.add(time);
f1.dispose();
f1.show();
}
if (nurseb == true){
g1.setBackground(Color.red);
p2.add(returnbutton);
namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
g1.add(namelabel);
g1.add(time);
}
if (otherb == true){
g1.setBackground(Color.red);
p2.add(returnbutton);
namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
g1.add(namelabel);
g1.add(time);
}
}
else{
what.setText("Incorrect Login");
}
//g1.setBackground(Color.red);
// p2.add(returnbutton);
// g1.add(time);
f1.dispose();
f1.show();
}
//number 2
if (enter==teacher)
{
f1.dispose();
}
if (enter == idarray[1])
{
g1.remove(idnumber);
p1.remove(submit);
g1.remove(what);
g1.remove(idprompt);
g1.setBackground(Color.red);
p2.remove(submit);
p2.add(returnbutton);
namelabel.setText(namearray[1]);
g1.add(namelabel);
g1.add(time);
f1.dispose();
f1.show();
}
else{
what.setText("Incorrect Login");
}
}
if (enter == idarray[2])
{
g1.remove(idnumber);
p1.remove(submit);
g1.remove(what);
g1.remove(idprompt);
g1.setBackground(Color.red);
p2.remove(submit);
p2.add(returnbutton);
namelabel.setText(namearray[2]);
g1.add(namelabel);
g1.add(time);
f1.dispose();
f1.show();
}
else{
what.setText("Incorrect Login");
}
idnumber.setText(null);
g1.repaint();
} catch (IOException e) {
}
}
}
class GP extends JPanel //graphics panel
{
public GP()
{
setBackground(Color.green);
}
public void paint(Graphics g)
{
super.paint(g);
}
}