⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trainticket.java

📁 使用java弄的,实现铁路售票的各种功能,供大家学习使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package Java;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.awt.Toolkit;
import javax.swing.table.*;


public class Trainticket extends JFrame implements ActionListener,ItemListener{

	JTable _t = null;
	JLabel _jl1,_jl2,_jl3,_jl4,_jl5,_jl6,_jl7,_jl8,_jl9,_jl10,_jl11,_jl12,_jl31,_jl32,_jl33,_jl34,_jl35,_jl36,_jl37;
	JLabel _jl13,_jl14,_jl15,_jl16,_jl17,_jl18,_jl19,_jl20,_jl21,_jl22,_jl23,_jl24,_jl25,_jl26,_jl27,_jl28,_jl30,_jldj;
	JTextField _jt1,_jt2,_jt3,_jt4,_jt5,_jt6,_jt7,_jt8,_jt9;
	JButton _jb1,_jb2,_jb3,_jb4,_jb5;
	Checkbox _cb[] = new Checkbox[2];
	CheckboxGroup _cg;
	Choice _ch1,_ch2,_ch3,_ch4,_ch5;
	JPanel _jp1,_jp2,_jp3,_jp4,_jp5,_jp6,_jp7,_jp8,_jp9,_jp10,_jp11,_jp12,_jp13,_jp14;
	String username,userpassword,userpopedom = "admin";
	String tel,address,sex,name,id,runmileage,exittime,arrivetime,stagenameindex,stagename,
	charge,surrogatename,surrogateno,railwaytype,seatcount,useable,railwayno,seatno,salestage,
	startstage,arrivestage,changetrain,tickettype,starttime,saletime,tno;
	float ticketprice = 0;
	Conn conn = new Conn();
	TrainVo tv = new TrainVo();
	SaleTrainTicket stt = new SaleTrainTicket();
	Vector v = null;
	int typeno;

    public Trainticket(String username,String userpassword) {
    	super("火车票");
    	this.username = username;
    	this.userpassword = userpassword;
    	if(conn.Login(username,userpassword))
    	{
    		JOptionPane.showMessageDialog(this,"欢迎登录!");
    	}else{
    		JOptionPane.showMessageDialog(this,"非法请求!");
    		System.exit(0);
    	}
    	_jl1 = new JLabel("   车次");
    	_jl2 = new JLabel("   始发站");
    	_jl3 = new JLabel("   终点站");
    	_jl4 = new JLabel("   剩余票数");
    	_jl5 = new JLabel("   车次");
    	_jl6 = new JLabel("   日期");
    	_jl7 = new JLabel("   起始站");
    	_jl8 = new JLabel("   到达站");
    	_jl9 = new JLabel("         车次");
    	_jl9.setForeground(Color.MAGENTA);
    	_jl10 = new JLabel("        类型");
    	_jl10.setForeground(Color.MAGENTA);
    	_jl11 = new JLabel("     始发站");
    	_jl11.setForeground(Color.MAGENTA);
    	_jl12 = new JLabel("   终点站");
    	_jl12.setForeground(Color.MAGENTA);
    	_jl13 = new JLabel("   始发时间");
    	_jl13.setForeground(Color.MAGENTA);
    	_jl14 = new JLabel("   始发日期");
    	_jl14.setForeground(Color.MAGENTA);
    	_jl15 = new JLabel("   运行时间");
    	_jl15.setForeground(Color.MAGENTA);
    	_jl16 = new JLabel("   全程行程");
    	_jl16.setForeground(Color.MAGENTA);
    	_jl17 = new JLabel("   车厢类别");
    	_jl18 = new JLabel("   车票数量");
    	_jl19 = new JLabel("   车票类别");
    	_jl20 = new JLabel("   总票价");
    	_jl21 = new JLabel("   实付");
    	_jl22 = new JLabel("   找零");
    	_jl23 = new JLabel("   请确认您所选择的车次 !   ");
    	_jl23.setFont(new Font("黑体",java.awt.Font.BOLD,18));
    	_jl23.setForeground(Color.RED);
    	_jl24 = new JLabel("");
    	_jl25 = new JLabel("");
    	_jl26 = new JLabel("单价:"+ticketprice);
    	_jl26.setForeground(Color.RED);
    	_jl27 = new JLabel("");
    	_jl28 = new JLabel("");
    	_jl30 = new JLabel("");
    	_jl31 = new JLabel("");
    	_jl32 = new JLabel("");
    	_jl33 = new JLabel("");
    	_jl34 = new JLabel("");
    	_jl35 = new JLabel("");
    	_jl36 = new JLabel("");
    	_jl37 = new JLabel("");
    	
    	_jt1 = new JTextField(3);
    	_jt1.setEditable(false);
    	_jt1.setBackground(Color.WHITE);
    	_jt2 = new JTextField(3);
    	_jt2.setBackground(Color.WHITE);
    	_jt2.setEditable(false);
    	_jt3 = new JTextField(3);
    	_jt3.setBackground(Color.WHITE);
    	_jt3.setEditable(false);
    	_jt4 = new JTextField(3);
    	_jt4.setEditable(false);
    	_jt4.setBackground(Color.WHITE);
    	_jt5 = new JTextField(3);
    	_jt6 = new JTextField(3);
    	_jt6.setText("0");
    	_jt7 = new JTextField(3);
    	_jt7.setText("0");
    	_jt7.setEditable(false);
    	_jt7.setBackground(Color.WHITE);
    	_jt8 = new JTextField(3);
    	_jt8.setText("0");
    	_jt9 = new JTextField(3);
    	_jt9.setText("0");
    	_jt9.setEditable(false);
    	_jt9.setBackground(Color.WHITE);
    	
    	_jb1 = new JButton("查询");
    	_jb1.addActionListener(this);
    	_jb2 = new JButton("详细查询");
    	_jb2.addActionListener(this);
    	_jb2.setEnabled(false);
    	_jb3 = new JButton("确定");
    	_jb3.addActionListener(this);
    	_jb3.setEnabled(false);
    	_jb4 = new JButton("打印");
    	_jb4.addActionListener(this);
    	_jb5 = new JButton("退出");
    	_jb5.addActionListener(this);
    	
    	_cg = new CheckboxGroup();
		_cb[0] = new Checkbox("按车次查询",_cg,true);
		_cb[0].addItemListener(this);
		_cb[1] = new Checkbox("按车站查询",_cg,false);
		_cb[1].addItemListener(this);
		
		_ch1 = new Choice();
		for(int i=1;i<=12;i++)
		{
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
			{
				for(int j=1;j<=31;j++)
				{_ch1.add(""+"2008"+"/"+i+"/"+j+"");}
			}else{
				for(int j=1;j<31;j++)
				{_ch1.add(""+"2008"+"/"+i+"/"+j+"");}
			}
			
		}
		_ch1.addItemListener(this);
		_ch2 = new Choice();
		_ch2.setEnabled(false);
		v = conn.getStageName();
		Enumeration e = v.elements();
		while(e.hasMoreElements())
		{
			tv = (TrainVo) e.nextElement();//返回的是nextElement()Object类型必须转换
			_ch2.add(tv.getTrainname());
		}
		_ch2.addItemListener(this);
		_ch3 = new Choice();
		_ch3.setEnabled(false);
		Enumeration ee = v.elements();
		while(ee.hasMoreElements())
		{
			tv = (TrainVo) ee.nextElement();//返回的是nextElement()Object类型必须转换
			_ch3.add(tv.getTrainname());
		}
		_ch3.addItemListener(this);
		_ch4 = new Choice();
		_ch4.add("硬座");
		_ch4.add("软座");
		_ch4.addItemListener(this);
		_ch5 = new Choice();
		_ch5.add("全票");
		_ch5.add("半票");
		_ch5.addItemListener(this);
		
		NotEditable _net = new NotEditable(100,8);
		_t = new JTable(_net);
		_t.setForeground(Color.GREEN);
		_t.setBackground(Color.WHITE);
		ScrollPane _sp = new ScrollPane();
		_sp.add(_t);
		
		_jp1 = new JPanel();
		_jp2 = new JPanel(new GridLayout(2,8));
		_jp3 = new JPanel(new GridLayout(2,1));
		_jp4 = new JPanel(new GridLayout(1,7));
		_jp5 = new JPanel(new GridLayout(1,7));
		_jp6 = new JPanel(new GridLayout(2,1));
		_jp7 = new JPanel(new GridLayout(1,8));
		_jp10 = new JPanel(new GridLayout(2,1));
		_jp11 = new JPanel(new GridLayout(1,6));
		_jp12 = new JPanel(new GridLayout(1,6));
		_jp13 = new JPanel(new GridLayout(1,6));
		_jp14 = new JPanel(new GridLayout(3,1));
		JPanel _allpanel = new JPanel(new GridLayout(4,1));
		
		_jp1.add(_jl23);
		_jp2.add(_jl1);
		_jp2.add(_jt1);
		_jp2.add(_jl2);
		_jp2.add(_jt2);
		_jp2.add(_jl3);
		_jp2.add(_jt3);
		_jp2.add(_jl4);
		_jp2.add(_jt4);
		_jp2.add(_jl30);
		_jp2.add(_jl31);
		_jp2.add(_jl32);
		_jp2.add(_jl33);
		_jp2.add(_jl34);
		_jp2.add(_jl35);
		_jp2.add(_jl36);
		_jp2.add(_jl37);
		_jp3.add(_jp1);
		_jp3.add(_jp2);
		
		_jp4.add(_cb[0]);
		_jp4.add(_jl5);
		_jp4.add(_jt5);
		_jp4.add(_jl6);
		_jp4.add(_ch1);
		_jp4.add(_jl24);
		_jp4.add(_jb1);
		
		_jp5.add(_cb[1]);
		_jp5.add(_jl7);
		_jp5.add(_ch2);
		_jp5.add(_jl8);
		_jp5.add(_ch3);
		_jp5.add(_jl25);
		_jp5.add(_jb2);
		
		_jp6.add(_jp4);
		_jp6.add(_jp5);
		
		_jp7.add(_jl9);
		_jp7.add(_jl10);
		_jp7.add(_jl11);
		_jp7.add(_jl12);
		_jp7.add(_jl13);
		_jp7.add(_jl14);
		_jp7.add(_jl15);
		_jp7.add(_jl16);
		

		_jp10.add(_jp6);
		_jp10.add(_jp7);
		
		_jp11.add(_jl17);
		_jp11.add(_ch4);
		_jp11.add(_jl18);
		_jp11.add(_jt6);
		_jp11.add(_jl26);
		_jp11.add(_jb3);
		
		_jp12.add(_jl19);
		_jp12.add(_ch5);
		_jp12.add(_jl20);
		_jp12.add(_jt7);
		_jp12.add(_jl27);
		_jp12.add(_jb4);
		
		_jp13.add(_jl21);
		_jp13.add(_jt8);
		_jp13.add(_jl22);
		_jp13.add(_jt9);
		_jp13.add(_jl28);
		_jp13.add(_jb5);
		
		_jp14.add(_jp11);
		_jp14.add(_jp12);
		_jp14.add(_jp13);
		
		_allpanel.add(_jp3);
		_allpanel.add(_jp10);
		_allpanel.add(_sp);
		_allpanel.add(_jp14);
	
		this.add(_allpanel);
		
		this.setSize(660,390);
		this.setResizable(false);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
		int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
		this.setLocation((W-this.getWidth())/2,(H-this.getHeight())/2);
		
    } 
    
    public void itemStateChanged(ItemEvent e)
    {
    	if(e.getSource()==_ch1)
    	{

⌨️ 快捷键说明

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