📄 servermainframe.java
字号:
package com.tarena.abs.view.server;
import java.awt.*;
import javax.swing.*;
import com.tarena.abs.controller.*;
import java.awt.event.*;
import com.tarena.abs.dao.*;
import com.tarena.abs.model.*;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
public class ServerMainFrame extends JFrame implements ActionListener{
JLabel message;
JMenuBar jmb;
JMenu flight,info;
HashSet allPlane;
DAOInterface dao;
public ServerMainFrame(String fileName){
super("航班机票预定系统--服务器端主界面");
message=new JLabel("");
jmb=new JMenuBar();
flight=new JMenu("航班计划");
info=new JMenu("统计信息");
createDao(fileName);//得到DAO
allPlane=(HashSet)dao.getAllPlane();
init();
}
private void createDao(String fileName){
try {
FileInputStream fis=new FileInputStream(fileName);
Properties p=new Properties();
p.load(fis);
DAOFactory factory=DAOFactory.newInstance();
factory.setType(DAOFactory.TYPE_FILE);
factory.setProperties(p);
dao=factory.createDAO();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void init(){
JMenuItem item;
flight.add(item=new JMenuItem("添加航班计划"));item.addActionListener(this);
flight.add(item=new JMenuItem("删除航班计划"));item.addActionListener(this);
flight.add(item=new JMenuItem("查询航班计划"));item.addActionListener(this);
flight.add(item=new JMenuItem("添加飞机型号"));item.addActionListener(this);
flight.add(item=new JMenuItem("删除飞机型号"));item.addActionListener(this);
flight.add(item=new JMenuItem("系统维护"));item.addActionListener(this);
flight.add(item=new JMenuItem("退出"));item.addActionListener(this);
info.add(item=new JMenuItem("在线用户信息"));item.addActionListener(this);
info.add(item=new JMenuItem("注册用户信息"));item.addActionListener(this);
jmb.add(flight);
jmb.add(info);
this.setJMenuBar(jmb);
}
public void showMe(){
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
askQuit();
}
});
this.setSize(800,600);
this.setVisible(true);
}
private void askQuit(){
int choice=JOptionPane.showConfirmDialog(this,"退出服务器将中断网络连接,是否确定退出?","确定退出?",
JOptionPane.YES_NO_CANCEL_OPTION);
switch(choice){
case JOptionPane.OK_OPTION : System.exit(0);
case JOptionPane.NO_OPTION :return;
case JOptionPane.CANCEL_OPTION : return;
}
}
public void actionPerformed(ActionEvent e) {
String command=e.getActionCommand();
if(command.equals("添加航班计划")){
new AddFlightSchedularDialog(this).showMe();
}
if(command.equals("删除航班计划")){
new RemoveFlightSchedularDialog(this).showMe();
}
if(command.equals("查询航班计划")){
PlaneModel p1=new PlaneModel(12000,2,"BOIN 747-300");
FlightSchedular fs=new FlightSchedular("CZ1202","上海","北京",
new MyDate(2007,1,1),new MyDate(2007,6,30),
new MyTime(12,30),new MyTime(14,5),1200,p1,0x54,1210);
FlightSchedular fs2=new FlightSchedular("CZ1203","北京","上海",
new MyDate(2007,1,1),new MyDate(2007,6,30),
new MyTime(9,30),new MyTime(11,25),1200,p1,0x7f,1210);
ArrayList ar=new ArrayList();
ar.add(fs);
ar.add(fs2);
this.setContentPane(new FlightSchedularListPanel("上海","北京",ar));
this.setVisible(true);
}
if(command.equals("系统维护")){
}
if(command.equals("退出")){
askQuit();
}
}
public static void main(String[] args){
ServerMainFrame server=new ServerMainFrame("."+File.separator+"airline"+File.separator+"configFromFile.txt");
server.showMe();
//此处将要添加服务器端服务代码。
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -