servermainframe.java

来自「一个用java实现 的飞机订票系统,超级好用....」· Java 代码 · 共 144 行

JAVA
144
字号
package com.zhu.server;

import java.awt.*;
import javax.swing.*;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zhu.entity.*;
import com.zhu.util.HbnUtil;








import java.awt.event.*;


import java.io.*;
import java.net.*;
import java.util.*;
import java.util.List;
/*
 *  @author zhutingfa
 */
public class ServerMainFrame extends JFrame implements ActionListener{
	private JMenuBar jmb;
	private JMenu flight,agent,order,info;
	public ServerMainFrame(){
		super("航班机票预定系统--服务器端主界面");
		jmb=new JMenuBar();
		flight=new JMenu("航班管理");
		agent=new JMenu("代理商管理");
		order=new JMenu("订单管理");
		info=new JMenu("系统信息");
		init();
	}
	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);
		flight.add(item=new JMenuItem("删除航班"));item.addActionListener(this);
		flight.add(item=new JMenuItem("退出"));item.addActionListener(this);
		
		agent.add(item=new JMenuItem("添加代理商"));item.addActionListener(this);
		agent.add(item=new JMenuItem("删除代理商"));item.addActionListener(this);	
		agent.add(item=new JMenuItem("在线代理商信息"));item.addActionListener(this);
		agent.add(item=new JMenuItem("注册代理商信息"));item.addActionListener(this);
		
		order.add(item=new JMenuItem("查询订单"));item.addActionListener(this);
		order.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(agent);
		jmb.add(order);
		jmb.add(info);
		this.setJMenuBar(jmb);
	}
	public void showMe(){
		this.setLocation(50, 50);
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				askQuit();
			}	
		});
		this.setSize(900,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("查询航班计划")){
			new SearchFlightSch(this);
		}	
		if(command.equals("添加飞机型号")){
			new AddPlaneModelDialog(this).showMe();
		}
		if(command.equals("删除飞机型号")){
			new RemovePlaneModelDialog(this).showMe();
		}
		if(command.equals("添加航班")){
			new AddFlight(this);
		}if(command.equals("查询航班")){
			new SearchFlight(this);
		}if(command.equals("删除航班")){
			new RemoveFilhtDialog(this);
		}
		if(command.equals("退出")){
			askQuit();
		}if(command.equals("添加代理商")){
			new AddAgentDialog(this).showMe();
		}if(command.equals("删除代理商")){
			new RemoveAgentDialog(this).showMe();
		}if(command.equals("在线代理商信息")){
			this.setContentPane(new AgentPanel("在线代理商信息:",new ArrayList(ServerMainClass.currentAgents)));
			this.setVisible(true);
		}if(command.equals("注册代理商信息")){
			Session s=HbnUtil.getCurrentSession();
			Transaction tt=s.beginTransaction();
			Set set=ServerMainClass.agentDao.getAllAgent();
			tt.commit();
			this.setContentPane(new AgentPanel("注册代理商信息:",new ArrayList(set)));
			this.setVisible(true);
		}if(command.equals("查询订单")){
			new SearchOrder(this).showMe();
		}if(command.equals("业绩统计")){
			Session s=HbnUtil.getCurrentSession();
			Transaction t=s.beginTransaction();
			List list=ServerMainClass.orderDao.getOrders();
			t.commit();
			this.setContentPane(new AllOrderListPane(new ArrayList(list)));
			this.setVisible(true);
		}
		

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?