📄 jiemian.java
字号:
package Jiemian;
import javax.swing.*;
import train.paint;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;
import true_false.*;
import Manager.TrainTable.*;
import Manager.*;
import javax.swing.JWindow;
import java.awt.Dimension;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JWindow;
import java.awt.event.KeyEvent;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.border.EtchedBorder;
public class Jiemian extends JWindow {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTabbedPane jTabbedPane = null;
private JPanel jPanel = null;
private JPanel jPanel1 = null;
private JPanel jPanel2 = null;
private JPanel jPanel3 = null;
private JPanel jPanel4=null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JComboBox jComboBox = null;
private JComboBox jComboBox1 = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel jLabel2 = null;
private JComboBox jComboBox2 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JLabel jLabel3 = null;
//private JLabel jLabel4 = null;
//private JTextField jTextField;
private JButton jButton6 = null;
//private JButton jButton7 = null;
private JScrollPane jScrollPane = null;
private TrainTable jTable = null;
private JScrollPane jScrollPane1 = null;
private TrainTable jTable2 = null;
private JScrollPane jScrollPane2 = null;
private TrainTable jTable1 = null;
private JButton jButton9 = null;
private JButton jButton8 = null;
private JLabel jLabel5 = null;
private JComboBox jComboBox3 = null;
private JComboBox jComboBox4 = null;
private JLabel jLabel6 = null;
private String checi="P001";
private String date="2月24日";
private String start="北京";
private String zhongdian="南京";
private TrainTable tt=null;
//private boolean ding=true;
private boolean ce=false;
public Jiemian() {
super();
//paint p=new paint();
//p.initialize();
initialize();
}
public Jiemian(GraphicsConfiguration arg0) {
super(arg0);
initialize();
}
public Jiemian(Frame arg0) {
super(arg0);
// TODO Auto-generated constructor stub
initialize();
}
public Jiemian(Window arg0) {
super(arg0);
// TODO Auto-generated constructor stub
initialize();
}
public Jiemian(Window arg0, GraphicsConfiguration arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
initialize();
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(51, 204, 255), 5), "\u706b \u8f66 \u7968 \u8ba2 \u7968 \u7cfb \u7edf", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("\u9ed1\u4f53", Font.BOLD, 24), new Color(0, 102, 204)));
jContentPane.setName("");
jContentPane.setToolTipText("");
jContentPane.setPreferredSize(new Dimension(1, 1));
jContentPane.setBackground(new Color(204, 204, 255));
jContentPane.add(getJTabbedPane(), null);
jContentPane.add(getJButton9(), null);
jContentPane.add(getJButton8(), null);
}
return jContentPane;
}
/**
* This method initializes jTabbedPane
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.setBounds(new Rectangle(26, 53, 593, 513));
jTabbedPane.setToolTipText("");
jTabbedPane.setFont(new Font("\u96b6\u4e66", Font.BOLD, 18));
jTabbedPane.setForeground(Color.blue);
jTabbedPane.setBackground(new Color(204, 204, 255));
jTabbedPane.addTab("车 次 查 询", null, getJPanel1(), null);
jTabbedPane.addTab(" 退 票 ", null, getJPanel3(), null);
jTabbedPane.addTab("站 站 查 询", null, getJPanel(), null);
jTabbedPane.addTab("已 售 票 显 示", null, getJPanel2(), null);
}
return jTabbedPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(278, 14, 66, 34));
jLabel5.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel5.setText(" 时间:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(139, 14, 69, 32));
jLabel1.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel1.setText(" 终点:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(1, 14, 69, 32));
jLabel.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel.setHorizontalTextPosition(SwingConstants.TRAILING);
jLabel.setText(" 起点:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
jPanel.setBackground(new Color(204, 204, 255));
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getJComboBox(), null);
jPanel.add(getJComboBox1(), null);
jPanel.add(getJButton(), null);
jPanel.add(getJButton1(), null);
jPanel.add(getJScrollPane(), null);
jPanel.add(jLabel5, null);
jPanel.add(getJComboBox3(), null);
}
return jPanel;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(201, 14, 66, 36));
jLabel6.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel6.setText(" 时 间:");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(21, 14, 80, 32));
jLabel2.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel2.setText(" 车 次 :");
jPanel1 = new JPanel();
jPanel1.setLayout(null);
jPanel1.setBackground(new Color(204, 204, 255));
jPanel1.add(jLabel2, null);
jPanel1.add(getJComboBox2(), null);
jPanel1.add(getJButton2(), null);
jPanel1.add(getJButton3(), null);
jPanel1.add(getJScrollPane2(), null);
jPanel1.add(getJComboBox4(), null);
jPanel1.add(jLabel6, null);
}
return jPanel1;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(14, 14, 186, 32));
jLabel3.setBackground(Color.blue);
jLabel3.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jLabel3.setText("显 示 已 售 出 的 票:");
jPanel2 = new JPanel();
jPanel2.setLayout(null);
jPanel2.setBackground(new Color(204, 204, 255));
jPanel2.add(jLabel3, null);
jPanel2.add(getJScrollPane1(), null);
/*jPanel2.addFocusListener(new java.awt.event.FocusListener(){
}*/
}
return jPanel2;
}
/**
* This method initializes jPanel3
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel3() {
if (jPanel3 == null) {
//jLabel4 = new JLabel();
//jLabel4.setBounds(new Rectangle(7, 14, 80, 32));
//jLabel4.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
//jLabel4.setText(" 票 号 :");
jPanel3 = new JPanel();
jPanel3.setLayout(null);
jPanel3.add(getjPanel4(),null);
jPanel3.setBackground(new Color(204, 204, 255));
//jPanel3.add(jLabel4, null);
//jPanel3.add(getJTextField(), null);
jPanel3.add(getJButton6(), null);
//jPanel3.add(getJButton7(), null);
}
return jPanel3;
}
private JPanel getjPanel4() {
if (jPanel4 == null) {
jPanel4 = new JPanel();
jPanel4.setLayout(null);
jPanel4.setName("");
jPanel4.setToolTipText("");
jPanel4.setBackground(Color.red);
jPanel4.setSize(50,60);
Dimension screen =jPanel3.getSize();
jPanel4.setBounds(new Rectangle(0, 60, 600, 500));
ImageIcon icon=new ImageIcon("train.jpg");
JLabel j=new JLabel("",icon,SwingConstants.LEFT);
j.setBounds(new Rectangle(0, 0, 600, 500));
jPanel4.add(j,null);
}
return jPanel4;
}
private JComboBox getJComboBox() {
if (jComboBox == null) {
String jc_start[]={"北京","南京"};
jComboBox = new JComboBox(jc_start);
jComboBox.setBounds(new Rectangle(42, 14, 98, 32));
jComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
start=(String)e.getItem();
System.out.print((String)e.getItem());
}
});
}
return jComboBox;
}
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
String end[]={"上海","广州"};
jComboBox1 = new JComboBox(end);
jComboBox1.setBounds(new Rectangle(180, 14, 98, 32));
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
zhongdian=(String)e.getItem();
System.out.print((String)e.getItem());
}
});
}
return jComboBox1;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(430, 14, 74, 32));
jButton.setMnemonic(KeyEvent.VK_UNDEFINED);
jButton.setHorizontalTextPosition(SwingConstants.CENTER);
jButton.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jButton.setText("查 询");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
String sql=null;
sql="select * from chapiao where 起点站=" + "'" + start +"'" + " and " + "日期=" + "'" + date + "'" + " and " + "终点站=" + "'" + zhongdian + "'" ;
System.out.print(sql);
jTable.refresh(sql);
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(513, 14, 71, 32));
jButton1.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 12));
jButton1.setText("订 票");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
System.out.println();
//int i;
//String s[];
if(ce==true)
{
TrainManager tm=new TrainManager();
String sql=null;
sql="insert into yishoupiao values(" + "'" + jTable.getValueAt(jTable.getSelectedRow(),0)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),1)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),2)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),3)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),4)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),5)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),6)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),7)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),8)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),9)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),10)
+"','" + jTable.getValueAt(jTable.getSelectedRow(),11)+"')";
tm.insertBj(sql);
sql="delete from chapiao where 票号="+jTable.getValueAt(jTable.getSelectedRow(),0);
//sql="delete from chapiao where 票号=2";
tm.deleteBj(sql);
jTable.refresh(tm);
jTable1.refresh(tm);
jTable2.refresh("select * from yishoupiao");
}
else
{
JOptionPane.showMessageDialog(null,"请 插 卡");
}
/*for(i=0;i<jTable.getSelectedRows().length;i++)
{
System.out.println(jTable.getSelectedRow());
System.out.println(jTable.getSelectedRowCount());
System.out.println(jTable.getSelectedRows().length);
}*/
}
});
/*Train bj=new Train();
TrainManager aa=new TrainManager();
if(ding==true)
{
aa.updateBj(bj);
//ubj.refresh(bjm);
JOptionPane.showInternalMessageDialog("记录修改成功!");
//this.dispose();
return;
}*/
}
return jButton1;
}
/**
* This method initializes jComboBox2
*
* @return javax.swing.JComboBox
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -