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

📄 btnshuang2dialog.java

📁 长沙公交查询管理系统,主要实现对人员资料的管理以及车辆的分配路线。
💻 JAVA
字号:
package pro;
/*此类实现中转站的界面与功能*/
import java.awt.*;
import java.awt.Event;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class BtnShuang2Dialog extends JDialog implements java.awt.event.ActionListener 
{
  Vector vec=new Vector();
	//new出所需组键
  private DefaultTableModel mDtm;
  private JTable tabShow=new JTable();
  JLabel lblTitle = new JLabel();
  JScrollPane Spn = new JScrollPane();
  private JPanel pnlSouth=new JPanel();
  private Selebus sel = new Selebus();

  private PnlCha pnl;

  
  
  JButton btnClose = new JButton();
  JButton btnHuanHui=new JButton();
	public BtnShuang2Dialog(MainFrame mf,DefaultTableModel dtm)
	{
		/*为所有组件定位!*/
	  	super(mf,true);
  	mDtm=dtm;
  	vec.add(mDtm);
  	/*为组键定位*/
  	
  	this.getContentPane().setLayout(null);
  	//this.getContentPane().setLayout(new BorderLayout());
  	pnlSouth.setLayout(null);
  	lblTitle.setFont(new java.awt.Font("Dialog", Font.BOLD | Font.ITALIC, 18));
    lblTitle.setForeground(new Color(0, 210, 46));
    lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
    lblTitle.setText("站站查询结果");
    lblTitle.setBounds(new Rectangle(86, 7, 460, 33));
    Spn.setBounds(new Rectangle(15, 36, 710,450));
 	tabShow.setColumnSelectionAllowed(true);
	    
	   /*用匿名类实现监听器接口*/
	   this.tabShow.addMouseListener(new java.awt.event.MouseAdapter(){
	   public void mouseClicked(java.awt.event.MouseEvent me)
	   {
		   if(me.getClickCount()==1&&me.getButton()==me.BUTTON1)
		   {
		     
		      tabShow.setSelectionForeground(Color.red);
		      tabShow.setSelectionBackground(Color.GREEN);
	   		  if(tabShow.getSelectedColumn()==1||tabShow.getSelectedColumn()==3)
	   		  {
	   		  		String strSel=(String)(tabShow.getValueAt(tabShow.getSelectedRow(),tabShow.getSelectedColumn()));
		   		  	VoSumBus vsb=new VoSumBus();
		   		    vsb=sel.selectDataByXianName(strSel);
					System.out.println("is  bus name = "+vsb.getSBusName());
					TabShuangDialog tabShuangDialog=new TabShuangDialog(BtnShuang2Dialog.this,vsb);
				    
					//获得屏幕的大小
				    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
				    //获得窗体的大小
				    Dimension frameSize = tabShuangDialog.getSize();
				    /*以防窗体的大小超过屏幕的大小*/
				    if (frameSize.height > screenSize.height) {
				      frameSize.height = screenSize.height;
				    }
				    if (frameSize.width > screenSize.width) {
				      frameSize.width = screenSize.width;
				    }
				   	/*设置窗体在屏幕中间*/
				    tabShuangDialog.setLocation( (screenSize.width - frameSize.width) / 2,
				                      (screenSize.height - frameSize.height) / 2);
				   tabShuangDialog.setVisible(true);
			  }
	   		  else if(tabShow.getSelectedColumn()==0||tabShow.getSelectedColumn()==2||tabShow.getSelectedColumn()==4)
	   		  {
	   		     String strSel1=(String)(tabShow.getValueAt(tabShow.getSelectedRow(),tabShow.getSelectedColumn()));
	   		  	 javax.swing.table.DefaultTableModel dtm1=sel.selectZhan(strSel1);
	   		     Shuang2Pnl btncenter=new Shuang2Pnl(BtnShuang2Dialog.this, dtm1);
   		     	 //获得屏幕的大小
			     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			     //获得窗体的大小
			     Dimension frameSize = btncenter.getSize();

			   	 /*设置窗体在屏幕中间*/
			     btncenter.setLocation( (screenSize.width - frameSize.width) / 2,
			                      (screenSize.height - frameSize.height) / 2);
	
	             btncenter.setVisible(true); 
	         }
	   	 }
	  }
 });
		    
    tabShow.setBounds(20,40,480,430);
    pnlSouth.setBounds(0,496,540,50);
    Spn.getViewport().add(tabShow);
    this.add(lblTitle,BorderLayout.NORTH);
    this.add(Spn); 
    
    
 
    btnClose.setBounds(new Rectangle(350, 5, 120, 31));
    btnClose.setText("退出");
	btnClose.setForeground(new Color(0, 210, 46));
    btnClose.setFont(new java.awt.Font("Dialog", Font.BOLD | Font.ITALIC, 14));
    
    
    btnHuanHui.setBounds(new Rectangle(150, 5, 120, 31));
    btnHuanHui.setFont(new java.awt.Font("Dialog", Font.BOLD | Font.ITALIC, 14));
    btnHuanHui.setForeground(new Color(0, 210, 46));
    btnHuanHui.setToolTipText("点击即可返回上一页");
    btnHuanHui.setText("返回上页");
    //pnlSouth.setLayout(new FlowLayout());
    pnlSouth.add(btnHuanHui);
    pnlSouth.add(btnClose);
    
    this.add(pnlSouth);
 
    
    
    this.tabShow.setModel(mDtm);
    btnClose.setActionCommand("btnClose");
    btnHuanHui.setActionCommand("btnHuanHui");
   // this.tabShow.setAction
    
    btnClose.addActionListener(this);
    btnHuanHui.addActionListener(this);
    
  	
  	
  	setSize(new Dimension(740,590));
    setTitle("长沙公交查询管理系统");
  }
//////////////////////////////////////////////  
 	public int num;
   public void actionPerformed(java.awt.event.ActionEvent ae)
  {
  	String strCmd=ae.getActionCommand();
  	if(strCmd.equals("btnClose"))
  	{  	
  	   this.dispose();
    }
    else
    {
	    if(num>0)//实现返回上一页的功能
	    {
	    	System.out.println ("num="+num);
	    	tabShow.setModel((DefaultTableModel)vec.get(--num));
	    }
	    else
	    {
	    	javax.swing.JOptionPane.showMessageDialog(this,"已返回到第一页");
	    	btnHuanHui.setEnabled(false);
	    }
    	 	 
    }
   }
}

⌨️ 快捷键说明

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