ok the following code , is the code for my program, basicly, i use bluej, so i can just copy and paste some code into the forums and someone else can copy it in to their editor, so basicly i want someone to show me how to make this set of code to be able to run itself, i have marked the main areas of the code like the main and graphics panel etc sorry about the load of code, but this is important to me that i get this all working together. thanks guys
Code:
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 static void main(String[] args) ]// main statement, i want it to goto { main m = new main(); } public class main implements ActionListener //this { 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(); // runs the graphics panel down there 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 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) { } } } public class GP extends JPanel //graphics panel { public GP() { setBackground(Color.green); } public void paint(Graphics g) { super.paint(g); } }
Comment