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

📄 trainticket.java

📁 使用java弄的,实现铁路售票的各种功能,供大家学习使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    		//System.out.println (_ch1.getSelectedItem());   输出所选择的!!!
    	}
    	if(e.getSource()==_cb[0])
    	{
    		_ch1.setEnabled(true);
    		_ch2.setEnabled(false);
    		_ch3.setEnabled(false);
    		_jt5.setEditable(true);
    		_jb2.setEnabled(false);
    	}
    	if(e.getSource()==_cb[1])
    	{
    		_jt5.setBackground(Color.WHITE);
    		_ch1.setEnabled(false);
    		_ch2.setEnabled(true);
    		_ch3.setEnabled(true);
    		_jt5.setEditable(false);
    		_jb2.setEnabled(true);
    	}
    	if(e.getSource()==_ch2)
    	{
    		//System.out.println (_ch2.getSelectedItem());
    	}
    	if(e.getSource()==_ch3)
    	{
    		//System.out.println (_ch3.getSelectedItem());
    	}
    	if(e.getSource()==_ch4)
    	{
    		//System.out.println (_ch4.getSelectedItem());
    	}
    	if(e.getSource()==_ch5)
    	{
    		Object tno = _t.getValueAt(_t.getSelectedRow(),0);
    		String trainno = (String)tno;
    		if(_ch5.getSelectedItem().equals("全票"))
    		{
    		ticketprice = Float.parseFloat(conn.getticketprice(trainno));
    		_jl26.setText("单价:"+ticketprice);
    		_jt7.setText("");
    		_jt9.setText("");	
    		}else{
    		ticketprice = Float.parseFloat(conn.getticketprice(trainno));
    		_jl26.setText("单价:"+(ticketprice/2));
    		_jt7.setText("");
    		_jt9.setText("");	
    		}
    		
    		//System.out.println (_ch5.getSelectedItem());
    	}
    }
    
    public void actionPerformed(ActionEvent e)
    {
    	if(e.getSource()==_jb1)// 判断是否点击按钮
    	{
    		_jt1.setText("");
    		_jt2.setText("");
    		_jt3.setText("");
    		_jt4.setText("");
    		String trainno = _jt5.getText().trim();
    		if(_cb[0].getState()==true) //判断第一个单选是否为真
    		{
    			if(conn.gettrainno(trainno)!=null)
    			{
    				for(int m = 0;m<100;m++)
    					{
    						for(int n = 0;n<8;n++)
    						{
    							_t.setValueAt("",m,n);
    						}
    					}
    				useable = conn.getuseable(trainno);
    				startstage = conn.getsalestage(trainno);
    				arrivestage = conn.getarrivestage(trainno);
    				saletime = conn.getsaletime(trainno);
    				exittime = conn.getexittime(trainno);
    				railwaytype = conn.getrailwaytype(trainno);
    				runmileage  = conn.getrunmileage(trainno);
    				starttime =  conn.getstarttime(trainno);
    				ticketprice = Float.parseFloat(conn.getticketprice(trainno));
    				_jt1.setText(trainno);
    				_jt2.setText(startstage);
    				_jt3.setText(arrivestage);
    				_jt4.setText(useable);
    				_jb3.setEnabled(true);
    				
    				_t.setValueAt(trainno,0,0);
    				_t.setValueAt(railwaytype,0,1);
    				_t.setValueAt(startstage,0,2);
    				_t.setValueAt(arrivestage,0,3);
    				_t.setValueAt(starttime,0,4);
    				_t.setValueAt(saletime,0,5);
    				_t.setValueAt(exittime+"小时",0,6);
    				_t.setValueAt(runmileage+"公里",0,7);
    				_jl26.setText("单价:"+ticketprice);
 
    			}else{
    				JOptionPane.showMessageDialog(this,"对不起,没有该信息!!!");
    			}
    		}
    		else{
    				v = conn._getAllStage(_ch2.getSelectedItem(),_ch3.getSelectedItem());
    				Enumeration eee = v.elements();
    				if(!eee.hasMoreElements())
    				{
    					JOptionPane.showMessageDialog(this,"对不起,没有该记录!!!");
    				}
    				else{
    					for(int m = 0;m<100;m++)
    					{
    						for(int n = 0;n<8;n++)
    						{
    							_t.setValueAt("",m,n);
    						}
    					}
    					for(int i = 0;eee.hasMoreElements();i++)
    				{
    						stt = (SaleTrainTicket) eee.nextElement();
    						_t.setValueAt(stt.getTtrainno(),i,0);
    						_t.setValueAt(conn.getrailwaytype(stt.getTtrainno()),i,1);
    						_t.setValueAt(stt.getStartstage(),i,2);
    						_t.setValueAt(stt.getArrivestage(),i,3);
    						_t.setValueAt(stt.getStarttime(),i,4);
    						_t.setValueAt(stt.getSaletime(),i,5);
    						_t.setValueAt(conn.getexittime(stt.getTtrainno())+"小时",i,6);
    						_t.setValueAt(conn.getrunmileage(stt.getTtrainno())+"公里",i,7);    					
    				}
    					_jb3.setEnabled(true);
    				}
    				
    		}
    	}
    	if(e.getSource()==_jb2)
    	{
    			if(_cb[1].getState()==true)
    		{
    			if(!_t.getValueAt(_t.getSelectedRow(),0).equals(""))
    			{
    			Object _useable =  _t.getValueAt(_t.getSelectedRow(),0);
    			Object _startstage =  _t.getValueAt(_t.getSelectedRow(),2);
    			Object _arrivestage =  _t.getValueAt(_t.getSelectedRow(),3);
    			String __useable = (String)_useable;
    			String __startstage = (String)_startstage;
    			String __arrivestage = (String)_arrivestage;
    			String _ticketprice = (String)_useable;
    			_jt1.setText(__useable);
    			_jt2.setText(__startstage);
    			_jt3.setText(__arrivestage);
    			_jt4.setText(conn.getuseable(_useable));
    			ticketprice = Float.parseFloat(conn.getticketprice(_ticketprice));
    			_jl26.setText("单价:"+ticketprice);
    			_jl26.setForeground(Color.red);	
    			}
    		}else{
    			if(!_t.getValueAt(_t.getSelectedRow(),0).equals(""))
    			{
    			String _ticketprice = (String)_t.getValueAt(_t.getSelectedRow(),0);
    			ticketprice = Float.parseFloat(conn.getticketprice(_ticketprice));
    			_jl26.setText("单价:"+ticketprice);	
    			}else{
    				JOptionPane.showMessageDialog(this,"你选择的是空值!");
    			}
    		}
    		if(_cb[0].getState()==true)
    		{
    			_jt1.setText("");
    			_jt2.setText("");
    			_jt3.setText("");
    			_jt4.setText("");
    			Object _useable =  _t.getValueAt(_t.getSelectedRow(),0);
    			Object _startstage =  _t.getValueAt(_t.getSelectedRow(),2);
    			Object _arrivestage =  _t.getValueAt(_t.getSelectedRow(),3);
    			String __useable = (String)_useable;
    			String __startstage = (String)_startstage;
    			String __arrivestage = (String)_arrivestage;
    			String _ticketprice = (String)_useable;
    			_jt1.setText(__useable);
    			_jt2.setText(__startstage);
    			_jt3.setText(__arrivestage);
    			_jt4.setText(conn.getuseable(_useable));
    			//ticketprice = Integer.parseInt(conn.getticketprice(_ticketprice));
    		if(_ch5.getSelectedItem().equals("全票"))
    		{
    			ticketprice = ticketprice;
    		}else{
    			ticketprice = ticketprice/2;
    		}
    			
    			_jl26.setText("单价:"+ticketprice);
    			_jl26.setForeground(Color.red);
    		}else{
    			if(!_t.getValueAt(_t.getSelectedRow(),0).equals(""))
    			{
    			String _ticketprice = (String)_t.getValueAt(_t.getSelectedRow(),0);
    			ticketprice = Float.parseFloat(conn.getticketprice(_ticketprice));
    			_jl26.setText("单价:"+ticketprice);
    			_jl26.setForeground(Color.red);
    			}else{
    				JOptionPane.showMessageDialog(this,"你选择的是空值!");
    			}
    		}
    	}
    	if(e.getSource()==_jb3)
    	{
    		String trainno = _jt5.getText().trim();
    		if(_t.getSelectedRow()==-1)//取行
    			{}
    		else
   	{
    			if(_t.getValueAt(_t.getSelectedRow(),0).equals(""))
    	{
    			JOptionPane.showMessageDialog(this,"你选择的行是空的!");
    		}else
    			{
    							Object i = _t.getValueAt(_t.getSelectedRow(),0);
    							trainno = (String)i;
    							String _ticketprice = (String)_t.getValueAt(_t.getSelectedRow(),0);
    							int ticketcount_;
    							float ticketprice_,pay_;
    							String ticketcount = _jt6.getText().trim();
    							String pay = _jt8.getText().trim();
    							String ticketprice__ = conn.getticketprice(_ticketprice);
    							ticketcount_ = Integer.parseInt(ticketcount);
    							pay_ = Float.parseFloat(pay);	
    							ticketprice_ = 	Float.parseFloat(ticketprice__);
    						if(_ch5.getSelectedItem().equals("全票"))
    							{//_jl26.setText("单价:"+ticketprice_);
    							_jt7.setText(""+(ticketprice_*ticketcount_)+"");
    							}
    							else
    								ticketprice_ = ticketprice_/2;
    							{//_jl26.setText("单价:"+ticketprice_);
    							_jt7.setText(""+(ticketprice_*ticketcount_)+"");
    							}
    							_jt9.setText(""+(pay_-ticketprice_*ticketcount_)+"");
   							   new Ticket(username,userpassword,trainno,ticketcount,pay,ticketprice_);
/*    							_jt6.setText("票数");
    							_jt7.setText("总票价");
    							_jt8.setText("实付");
    							_jt9.setText("找零");
    							System.out.println (ticketcount_+"   "+pay_+"    "+ticketprice_);   */
    			}
    		}
    	}
    	if(e.getSource()==_jb4)
    	{
    		String _jtrainno,_jstartstage,_jarrivestage,_jbuyticket,_jstagetype,_jstarttime,_jarrivetime,
			_jruntime,_jrunmileage,_jstageno;
			float _jticketprice;
    		Object i = _t.getValueAt(_t.getSelectedRow(),0);
    		_jtrainno = (String)i;
    		_jstartstage = conn.getsalestage(_jtrainno);
    		_jarrivestage = conn.getarrivestage(_jtrainno);
    		_jstarttime = conn.getarrivetime(_jtrainno);
    		_jruntime = conn.getexittime(_jtrainno);
    		_jstagetype = conn.getrailwaytype(_jtrainno);
    		_jrunmileage  = conn.getrunmileage(_jtrainno);
    		_jstarttime =  conn.getstarttime(_jtrainno);
    		_jarrivetime = conn.getarrivetime(_jtrainno);
    		_jbuyticket = _jt6.getText().trim();
    		_jstageno = conn.getstageno(_jtrainno);
    		
    		if(_ch5.getSelectedItem().equals("全票"))
    		{
    		_jticketprice = Float.parseFloat(conn.getticketprice(_jtrainno));	
    		}else{
    		_jticketprice = Float.parseFloat(conn.getticketprice(_jtrainno))/2;	
    		}
    		
    		new Ticketprint(username,userpassword,_jtrainno,_jstartstage,_jarrivestage,_jbuyticket,_jstagetype,_jstarttime,_jarrivetime,
			_jruntime,_jrunmileage,_jstageno,_jticketprice);
    	}
    	if(e.getSource()==_jb5)
    	{
    		dispose();
    		JOptionPane.showMessageDialog(this,"谢谢使用,您已经安全退出!");
    		new Login();
    	}
    }
public class NotEditable extends DefaultTableModel
	{
		public NotEditable(){
			super();
		}
		public NotEditable(int row, int column) {
			super(row,column);	
		}
		/**
		 * 重写此方法是为了设定JTable的各行为不可编辑状态
		 */
		public boolean isCellEditable(int row,int column){
			return false;
		}
	}
}

⌨️ 快捷键说明

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