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

📄 allticket.java

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


public class AllTicket extends JFrame implements ActionListener {
	
	JButton _return;
	NotEditable _net;
	ScrollPane _sp;
	JTable _t;
	JTableHeader _th;
	JPanel _jp;
	Vector v = new Vector();
	RailwayVo rv = null;
	Conn conn = new Conn();
	String username,userpassword,userpopedom;
	
    public AllTicket(String name,String password,String popedom) {
    	super("总票一览");
    	username = name;
    	userpassword = password;
    	userpopedom = popedom;
    	if(conn.ifadmin(username,userpassword,userpopedom))
    	{
    	}else{
    		JOptionPane.showMessageDialog(this,"非法请求!");
    		System.exit(0);
    	}
    	Object[] _name = new Object [] {"车次","车厢","车厢类型","总票数","剩余票数"};
    	_net = new NotEditable(_name,100);
    	_t = new JTable(_net);
    	_th = _t.getTableHeader();
    	_sp = new ScrollPane();
    	_sp.add(_t);
    	
    	_jp = new JPanel();
    	
    	_return = new JButton("返回");
    	_return.addActionListener(this);
    	
    	_jp.add(_return);
    	
    	this.add(_th,"North");
    	this.add(_sp,"Center");
    	this.add(_jp,"South");
    	this.setSize(500,500);
    	this.setVisible(true);
    	this.setResizable(false);
    	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);
    	v = conn.getVectorRailway();
		Enumeration e = v.elements();//返回此向量的组件的枚举
		for(int i = 0;e.hasMoreElements();i++)//测试此枚举是否包含更多的元素
		{
			rv = (RailwayVo) e.nextElement();//返回的是nextElement()Object类型必须转换
			_t.setValueAt(rv.get_trainno(),i,0);
			_t.setValueAt(rv.get_railwayno(),i,1);
			_t.setValueAt(rv.get_railwaytype(),i,2);
			_t.setValueAt(rv.get_seatcount(),i,3);
			_t.setValueAt(rv.get_useable(),i,4);
		}
    }
    public void actionPerformed(ActionEvent e){
    	if(e.getSource()==_return)
    	{
    		dispose();
    		new Ticketmanage(username,userpassword,userpopedom);
    	}
    }
    public class NotEditable extends DefaultTableModel
	{
		public NotEditable(){
			super();
		}
		public NotEditable(Object[] columnNames, int rowCount) {
			super(columnNames,rowCount);	
		}
		/**
		 * 重写此方法是为了设定JTable的各行为不可编辑状态
		 */
		public boolean isCellEditable(int row,int column){
			return false;
		}
	}
}

⌨️ 快捷键说明

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