import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.text.*;
/**
* PTS System.
*
* @author iCarnegie
*/
public class PTSGUI extends JPanel {
static private PrintWriter stdErr = new PrintWriter(System.err, true);
static private int WIDTH = 755;
static private int HEIGHT = 638;
static private int MEDICINE_CELL_SIZE = 50;
static private int MEDICINE_LIST_ROWS = 12;
static private int PRESCRIPTION_CELL_SIZE = 50;
static private int PRESCRIPTION_LIST_ROWS = 6;
static private int TEXTFIELD_SIZE = 5;
static private int STATUS_ROWS = 10;
static private int STATUS_COLS = 40;
private JList medicineList;
private JList prescriptionList;
private JButton displayHOPButton;
private JButton saveButton;
private JButton diplayPrescriptionButton;
private JButton displayMedicineButton;
private JPanel medicinePanel;
private JPanel prescriptionPanel;
private JLabel IDLabel;
private JTextField IDTextField;
private JTextArea statusTextArea;
private JRadioButton plainRadioButton;
private JRadioButton HTMLRadioButton;
private JRadioButton XMLRadioButton;
private InfoFormatter infoFormatter;
private JFileChooser fileChooser;
private DrugsForYou drugsForYou;
private DrugsForYou drugsForYou1;
private HistoryOfPrescription historyOfPrescription;
private ClientDB clientDB;
public static void main(String[] args) throws IOException {
String filename = "";
if (args.length != 1) {
filename = "catalog.dat";
} else {
filename = args[0];
}
DrugsForYou drugsForYou =new DrugsForYou();
//(new FileCatalogLoader()).loadCatalog(filename);
HistoryOfPrescription historyOfPrescription = new HistoryOfPrescription();
JFrame j = new JFrame("PTS GUI");
Container contentPane = j.getContentPane();
j.setContentPane(new PTSGUI(drugsForYou, historyOfPrescription));
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setSize(WIDTH, HEIGHT);
j.setResizable(true);
j.setVisible(true);
}
public PTSGUI
(DrugsForYou initaldrugsForYou,HistoryOfPrescription initalhistoryOfPrescription) {
//create the components
medicineList = new JList();
prescriptionList = new JList();
medicineList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
medicineList.setVisibleRowCount(MEDICINE_LIST_ROWS);
medicineList.setFixedCellWidth(MEDICINE_CELL_SIZE);
prescriptionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//prescriptionList.setVisibleRowCount(PRESCRIPTION_LIST_ROWS);
prescriptionList.setFixedCellWidth(PRESCRIPTION_CELL_SIZE);
displayHOPButton = new JButton("Display HistoryOfPrescription");
saveButton =new JButton("Save Information");
IDLabel = new JLabel("Please input your ID code:");
IDTextField = new JTextField("",TEXTFIELD_SIZE );
statusTextArea = new JTextArea(STATUS_ROWS, STATUS_COLS);
statusTextArea.setEditable(false);
plainRadioButton = new JRadioButton("Plain", true);
HTMLRadioButton = new JRadioButton("HTML");
XMLRadioButton = new JRadioButton("XML");
ButtonGroup group = new ButtonGroup();
group.add(plainRadioButton);
group.add(HTMLRadioButton);
group.add(XMLRadioButton);
//Medicine AND Prescription Panel
medicinePanel = new JPanel();
medicinePanel.setBorder(
BorderFactory.createTitledBorder("Medicine Information"));
JPanel m = new JPanel();
JLabel m1 = new JLabel("Please input your Medicine code:");
JTextField m2 = new JTextField("", TEXTFIELD_SIZE );
m.add(m1);
m.add(m2);
displayMedicineButton = new JButton("Display Medicine");
JPanel left = new JPanel(new BorderLayout());
left.add(medicinePanel,BorderLayout.CENTER);
left.add(m,BorderLayout.NORTH);
left.add(displayMedicineButton,BorderLayout.SOUTH);
prescriptionPanel = new JPanel();
prescriptionPanel.setBorder(
BorderFactory.createTitledBorder("Prescription Information"));
JPanel p = new JPanel();
JLabel p1 = new JLabel("Please input your Prescription code:");
JTextField p2 = new JTextField("", TEXTFIELD_SIZE );
p.add(p1);
p.add(p2);
diplayPrescriptionButton = new JButton("Display Prescription");
JPanel right = new JPanel(new BorderLayout());
right.add(prescriptionPanel,BorderLayout.CENTER);
right.add(p,BorderLayout.NORTH);
right.add(diplayPrescriptionButton,BorderLayout.SOUTH);
JPanel InfoPanel = new JPanel(new BorderLayout());
InfoPanel.add(left,BorderLayout.WEST);
InfoPanel.add(right,BorderLayout.EAST);
//Status panel
JPanel centralPanel = new JPanel(new BorderLayout());
centralPanel.setBorder(BorderFactory.createTitledBorder("Client Status"));
JPanel IDPanel = new JPanel();
IDPanel.add(IDLabel);
IDPanel.add(IDTextField);
JPanel hopPanel = new JPanel(new BorderLayout());
hopPanel.add (new JScrollPane(statusTextArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
JPanel hopButtonsPanel = new JPanel(new GridLayout(1, 4));
hopButtonsPanel.add(plainRadioButton);
hopButtonsPanel.add(HTMLRadioButton);
hopButtonsPanel.add(XMLRadioButton);
hopButtonsPanel.add(displayHOPButton);
hopButtonsPanel.add(saveButton);
centralPanel.add(IDPanel, BorderLayout.NORTH);
centralPanel.add(hopPanel, BorderLayout.CENTER);
centralPanel.add(hopButtonsPanel, BorderLayout.SOUTH);
//prescriptionListPanel panel
JPanel prescriptionListPanel = new JPanel(new BorderLayout());
prescriptionListPanel.setBorder(BorderFactory.createTitledBorder("Prescription"));
prescriptionListPanel.add(new JScrollPane(prescriptionList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
//medicineListPanel panel
JPanel medicineListPanel = new JPanel();
medicineListPanel.setBorder(BorderFactory.createTitledBorder("Medicine"));
medicineListPanel.add (
new JScrollPane(medicineList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
//arrange panels in window
setLayout(new BorderLayout());
add(medicineListPanel, BorderLayout.WEST);
add(InfoPanel, BorderLayout.CENTER);
add(prescriptionListPanel, BorderLayout.EAST);
add(centralPanel, BorderLayout.SOUTH);
// start listening for list and buttons events
medicineList.addListSelectionListener(new DisplayMedicineListener());
prescriptionList.addListSelectionListener(new DisplayPrescriptionListener());
displayHOPButton.addActionListener(new DisplayHOPListener());
diplayPrescriptionButton.addActionListener((ActionListener) new DisplayPrescriptionListener());
displayMedicineButton.addActionListener((ActionListener) new DisplayMedicineListener());
plainRadioButton.addActionListener(new PlainListener());
HTMLRadioButton.addActionListener(new HTMLListener());
XMLRadioButton.addActionListener(new XMLListener());
Medicine N1,N2,m3,m4,m5,m6;
N1=new Medicine("m1","康必得","盒","轻度嗜睡、恶心、呕吐、腹胀","新康泰克");
N2=new Medicine("m2","青霉素","支","No","头孢霉素");
m3=new Medicine("m3","吗丁啉","片","神经过敏、嗜睡","三九胃泰颗粒");
m4=new Medicine("m4","降糖宁胶囊","盒","No","脂清胶囊");
m5=new Medicine("m5","健胃消食片","盒","No","大黄苏打");
m6=new Medicine("m6","阿莫西林胶囊","盒","恶心、呕吐","头孢氨苄胶囊");
drugsForYou =new DrugsForYou();
drugsForYou.addMedicine(N1);
drugsForYou.addMedicine(N2);
drugsForYou.addMedicine(m3);
drugsForYou.addMedicine(m4);
drugsForYou.addMedicine(m5);
drugsForYou.addMedicine(m6);
//drugsForYou1 = initaldrugsForYou;
medicineList.setListData(drugsForYou.getCodes());
Prescription p11,p22,p33;
HistoryOfPrescription hp1,hp2,hp3;
p11=new Prescription("p1","2007.9.1","2010.9.1","NO", 2,"Lee","024-24240001",N1);
p22=new Prescription("p2","2007.10
- 1
- 2
前往页