?? btnshuang2dialog.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 + -