import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class AppointmentBookTester {
private static final int FWIDTH = 400;
private static final int FHEIGHT = 300;
public static void main(String[] args){
JFrame frame = new JFrame();
final int WIDTH = 10;
final int COLUMNS = 30;
final int ROWS = 10;
final JTextArea text = new JTextArea(ROWS, COLUMNS);
text.setEditable(false);
JScrollPane sPane = new JScrollPane(text);
JButton Add = new JButton("Add");
JButton Print = new JButton("Print");
JLabel day = new JLabel("Day:");
JLabel desc = new JLabel("Description:");
JLabel st = new JLabel("Start Time:");
JLabel et = new JLabel("End Time");
final JTextField dayField = new JTextField(WIDTH);
dayField.setText("");
final JTextField descField = new JTextField(WIDTH);
descField.setText("");
final JTextField stField = new JTextField(WIDTH);
stField.setText("");
final JTextField etField = new JTextField(WIDTH);
etField.setText("");
JPanel panelleft = new JPanel();
JPanel panelright = new JPanel();
panelleft.setLayout(new GridLayout(2,1));
panelleft.add(Add);
panelleft.add(Print);
panelright.setLayout(new GridLayout(2,4));
panelright.add(day);
panelright.add(dayField);
panelright.add(desc);
panelright.add(descField);
panelright.add(st);
panelright.add(stField);
panelright.add(et);
panelright.add(etField);
frame.add(panelright, BorderLayout.NORTH);
frame.add(panelleft, BorderLayout.CENTER);
frame.add(sPane, BorderLayout.SOUTH);
ArrayList<Appointment> anArray = new ArrayList<Appointment>();
final AppointmentBook Book = new AppointmentBook(anArray);
class AddActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
String DaY, DesC;
double St, Et;
DaY = dayField.getText();
DesC = descField.getText();
St = Double.parseDouble(stField.getText());
Et = Double.parseDouble(etField.getText());
Appointment appoint = new Appointment(DaY, DesC, St, Et);
text.append(Book.add(appoint)+ "\n");
}
}
class PrintActionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
String DaY = dayField.getText();
text.append(Book.print(DaY) + "\n");
}
}
ActionListener AddActionListener = new AddActionListener();
Add.addActionListener(AddActionListener);
ActionListener PrintActionListener = new PrintActionListener();
Print.addActionListener(PrintActionListener);
frame.setSize(FWIDTH, FHEIGHT);
frame.setTitle("Appointment Book");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}