import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.lang.Object;
import java.io.*;
public class maincheck implements ActionListener {
JFrame f = new JFrame("Hall Pass");
Container c = f.getContentPane();
JLabel lblID = new JLabel("Enter ID Number :");
JTextField txtID = new JTextField(25);
JLabel lblNAME = new JLabel();
JLabel lblTIME = new JLabel();
ButtonGroup bg = new ButtonGroup();
JRadioButton rdbBATH = new JRadioButton("Bathroom");
JRadioButton rdbOFFC = new JRadioButton("Office");
JRadioButton rdbNURS = new JRadioButton("Nurse");
JRadioButton rdbOTHE = new JRadioButton("Others...");
boolean check = false;
JButton btnSUB = new JButton("Enter");
JButton btnRET = new JButton("Return");
//first page
JPanel pnl1 = new JPanel();
JPanel pnl2 = new JPanel();
JPanel pnl3 = new JPanel();
//second page
JPanel pnl4 = new JPanel();
JPanel pnl5 = new JPanel();
String[] namearray = new String[3];
int[] idarray = new int[3];
int INdex = 0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");
//body
public void create() {
f.setLayout(new BorderLayout());
createFirstPage();
btnSUB.addActionListener(this);
btnRET.addActionListener(this);
bg.add(rdbBATH);
bg.add(rdbOFFC);
bg.add(rdbNURS);
bg.add(rdbOTHE);
f.setSize(520,200);
f.setVisible(true);
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
//main
public static void main(String agr[]) {
maincheck m = new maincheck();
m.create();
}
//first page
public void createFirstPage() {
pnl1.add(lblID);
pnl1.add(txtID);
txtID.setText("");
f.add(pnl1, BorderLayout.NORTH);
pnl2.add(btnSUB);
f.add(pnl2, BorderLayout.SOUTH);
pnl1.setVisible(true);
pnl2.setVisible(true);
}
public void createRadioButton() {
pnl3.add(rdbBATH);
pnl3.add(rdbOFFC);
pnl3.add(rdbNURS);
pnl3.add(rdbOTHE);
f.add(pnl3, BorderLayout.CENTER);
pnl3.setVisible(true);
}
//second page
public void createSecondPage(String text) {
lblNAME.setText(namearray[INdex] + " goes to " + text + " At ");
lblTIME.setText(sdf.format(new java.util.Date(System.currentTimeMillis())));
pnl4.add(lblNAME);
pnl4.add(lblTIME);
f.add(pnl4, BorderLayout.NORTH);
pnl5.add(btnRET);
f.add(pnl5, BorderLayout.SOUTH);
pnl4.setVisible(true);
pnl5.setVisible(true);
//disable first page
pnl1.setVisible(false);
pnl2.setVisible(false);
pnl3.setVisible(false);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnSUB) {
String name = null;
int a = 0;
int b = 0;
if (check == false) {
try {
BufferedReader in = new BufferedReader(new FileReader("names.txt"));
for(int i=0; i<6; i++){
name = in.readLine().trim() ;
if(i<3){
namearray[a] = name;
a++;
}else{
idarray[b] = Integer.parseInt(name);
b++;
}
}
in.close();
}catch(Exception ex) {
System.err.println("reader error : " + ex.getMessage());
}
try {
for (int i = 0; i<3; i++) {
if ((Integer.parseInt(txtID.getText())) == idarray[i]){
INdex = i;
check = true;
btnSUB.setText("Submit");
createRadioButton();
}
}
}catch(Exception ex){
System.out.println("wrong input");
}
if (check == false) {
System.out.println("Wrong ID!");
}
}else{
if (rdbBATH.isSelected() == true) {
createSecondPage("Bathroom");
check = false;
}else if (rdbOFFC.isSelected() == true) {
createSecondPage("Office");
check = false;
}else if (rdbNURS.isSelected() == true) {
createSecondPage("Nurse");
check = false;
}else if (rdbOTHE.isSelected() == true) {
createSecondPage("Others place...");
check = false;
}else{
System.out.println("Please Select Where Are You Going.");
}
}
}
if (e.getSource() == btnRET) {
createFirstPage();
pnl4.setVisible(false);
pnl5.setVisible(false);
}
}
}
i make my own version of it, can't really stand ur indentation lol, if u still insist on ur version just take the related chunk and implement it urself
i don't quite understand what u want but the way i done is
>enter id
>check id from names.txt
>if exist ask to select where to go (bathroom, office, nurse, others)
>open next page showing the name of the ID, going to where and when