import javax.swing.*;
import javax.swing.event.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.zip.DataFormatException;
public class PTS extends JTabbedPane {
/**
* @param args
*/
/* Standard error stream */
static private PrintWriter stdErr = new PrintWriter(System.err, true);
/* Window width in pixels */
static private int WIDTH = 900;
/* Window height in pixels */
static private int HEIGHT = 650;
/* Size of the customer list cell in pixels */
static private int CUSTOMER_CELL_SIZE = 110;
/* Visible rows in customer list */
static private int CUSTOMER_LIST_ROWS = 10;
/* Size of the prescription list cell in pixels */
static private int PRESCRIPTION_CELL_SIZE = 180;
/* Visible rows in prescription list */
static private int PRESCRIPTION_LIST_ROWS =13;
/* Size of the drug list cell in pixels */
static private int DRUG_CELL_SIZE = 100;
/* Visible rows in drug list */
static private int DRUG_LIST_ROWS = 14;
/* Size prescriptionInfo text Area */
static private int PRESCRIPTIONINFO_ROWS = 13;
static private int PRESCRIPTIONINFO_COLS = 20;
static private int TEXTFIELD_SIZE = 10;
/*第一个Tab控件引用的声明*/
private JList customerList;
private JList prescriptionList;
private JList drugList;
private JPanel inquiryPresciption;
private JPanel prescriptionInfoPanel;
private JPanel customerListPanel;
private JPanel prescriptionListPanel;
private JPanel buttonsPanel;
private JPanel drugListPanel;
private JPanel functionPanel;
private JPanel functionAndSideEffect;
private JButton refill;
private JButton append;
private JButton savePrescription;
private JTextArea prescriptionText;
private JTextArea functionText;
private JFileChooser fileChooser;
/*第二个Tab控件引用的声明*/
private JPanel addPrescription;
private JPanel addPrescriptionInfo;
private JPanel addCustomer;
private JPanel customerList2Panel;
private JList customerList2;
private JPanel presciptionInfoPanel2;
private JLabel prescriptionID;
private JLabel drugPrescribed;
private JLabel customerBelonged;
private JLabel nameOfPhysician;
private JLabel phoneOfPhysician;
private JLabel date;
private JLabel expriationDate;
private JLabel numberOfRefill;
private JLabel numberOfUnits;
private JLabel name;
private JLabel phone;
private JLabel birth;
private JLabel policyProvider;
private JLabel insurancePolicyNumber;
private JTextField nameText;
private JTextField phoneText;
private JTextField birthText;
private JTextField policyProviderText;
private JTextField insurancePolicyNumberText;
private JTextField prescriptionIDText;
private JTextField drugPrescribedText;
private JTextField customerBelongedText;
private JTextField nameOfPhysicianText;
private JTextField phoneOfPhysicianText;
private JTextField dateText;
private JTextField expriationDateText;
private JTextField numberOfRefillText;
private JTextField numberOfUnitsText;
private JButton add1;
private JButton add2;
/*关联属性的声明*/
private Pharmacy pharmacy;
private static PrescriptionHistory prescriptionHistory;
private CustomerDB customerDB;
public static void main(String[] args) throws IOException{
String filename = "";
if (args.length != 1) {
filename = "data.dat";
} else {
filename = args[0];
}
try {
Pharmacy pharmacy = (new FileDataLoader()).loadDrug(filename);
CustomerDB customerDB = (new FileDataLoader()).loadCustomer(filename);
pharmacy.initializationGenericDrug();
JFrame frame = new JFrame("PTS");
frame.setContentPane(new PTS(customerDB,pharmacy));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(true);
frame.setVisible(true);
}
catch (FileNotFoundException fnfe) {
stdErr.println("The file does not exist");
System.exit(1);
} catch (DataFormatException dfe) {
stdErr.println("The file contains malformed data: "
+ dfe.getMessage());
System.exit(1);
}
try
{
prescriptionHistory = (new FileDataLoader()).loadPrescription(filename);
}
catch(FileNotFoundException fnfe) {
stdErr.println("The file does not exist");
System.exit(1);
} catch (DataFormatException dfe) {
stdErr.println("The file contains malformed data: "
+ dfe.getMessage());
System.exit(1);
} catch (IOException e) {
stdErr.println("Error encounted when read the data: "
+ e.getMessage());
}
}
public PTS(CustomerDB initialCustomerDB,Pharmacy initialPharmacy)
{
/*控件的创建*/
//按钮
refill = new JButton("再次给药");
append = new JButton("将副作用附在当前处方");
savePrescription = new JButton("保存当前处方");
//装载按钮的Panel
buttonsPanel = new JPanel(new GridLayout(3,1));
buttonsPanel.add(refill);
buttonsPanel.add(append);
buttonsPanel.add(savePrescription);
buttonsPanel.setBorder(BorderFactory.createTitledBorder("Click"));
//显示药品疗效的文本区
functionText = new JTextArea(12,34);
functionText.setEditable(false);
//装载药品作用的Panel
functionPanel = new JPanel();
functionPanel.setBorder(BorderFactory.createTitledBorder("药物信息"));
functionPanel.add(functionText);
functionAndSideEffect = new JPanel();
functionAndSideEffect.add(functionPanel);
//显示药品列表的List
drugList = new JList();
drugList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
drugList.setVisibleRowCount(DRUG_LIST_ROWS);
drugList.setFixedCellWidth(DRUG_CELL_SIZE);
pharmacy = initialPharmacy;
drugList.setListData(pharmacy.getDrugs());
drugListPanel = new JPanel();
drugListPanel.add(
new JScrollPane(drugList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
drugListPanel.setBorder(BorderFactory.createTitledBorder("药品列表"));
customerList = new JList();
customerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
customerList.setVisibleRowCount(CUSTOMER_LIST_ROWS);
customerList.setFixedCellWidth(CUSTOMER_CELL_SIZE);
customerDB = initialCustomerDB;
customerList.setListData(customerDB.getCustomers());
customerListPanel = new JPanel();
customerListPanel.setBorder(BorderFactory.createTitledBorder("Customer"));
customerListPanel.add(
new JScrollPane(customerList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
prescriptionList = new JList();
prescriptionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
prescriptionList.setVisibleRowCount(PRESCRIPTION_LIST_ROWS);
prescriptionList.setFixedCellWidth(PRESCRIPTION_CELL_SIZE);
prescriptionListPanel = new JPanel();
prescriptionListPanel.setBorder(BorderFactory.createTitledBorder("Prescription"));
prescriptionListPanel.add(
new JScrollPane(prescriptionList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
prescriptionInfoPanel = new JPanel();
prescriptionText = new JTextArea(PRESCRIPTIONINFO_ROWS+3,PRESCRIPTIONINFO_COLS);
prescriptionText.setEditable(false);
prescriptionInfoPanel.setBorder(BorderFactory.createTitledBorder("Prescription Info"));
prescriptionInfoPanel.add(prescriptionText);
JPanel west = new JPanel();
west.setLayout(new GridLayout(2,1));
west.add(customerListPanel);
west.add(drugListPanel);
JPanel center = new JPanel(new GridLayout(2,1));
center.add(prescriptionListPanel);
center.add(functionAndSideEffect);
JPanel east = new JPanel();
JLabel showDate = new JLabel();
JLabel
- 1
- 2
前往页