?? btncenter.java
字號:
/*此類實現站點查詢的界面與功能*/
package pro;
import java.awt.*;
import java.awt.Event;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class BtnCenter extends JDialog implements java.awt.event.ActionListener//,MouseListener
{
//new出所需組鍵
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 BtnCenter(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, 610,440));
tabShow.setColumnSelectionAllowed(true);
// tabShow.getIntercellSpacing(java.awt.Dimension.);
// tabShow.setcolumnwid
/*用匿名類實現監聽器接口*/
this.tabShow.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent me)
{
if(me.getClickCount()==1&&me.getButton()==me.BUTTON1)
{
String strSel=(String)(tabShow.getValueAt(tabShow.getSelectedRow(),tabShow.getSelectedColumn()));
tabShow.setSelectionForeground(Color.red);
tabShow.setSelectionBackground(Color.GREEN);
if(tabShow.getSelectedColumn()==0)
{
VoSumBus vsb=new VoSumBus();
vsb=sel.selectDataByXianName(strSel);
TabXianLuDialog tabXianLuDialog=new TabXianLuDialog(BtnCenter.this,vsb);
//獲得屏幕的大小
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//獲得窗體的大小
Dimension frameSize = tabXianLuDialog.getSize();
/*以防窗體的大小超過屏幕的大小*/
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
/*設置窗體在屏幕中間*/
tabXianLuDialog.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
tabXianLuDialog.setVisible(true);
}
if(tabShow.getSelectedColumn()==1||tabShow.getSelectedColumn()==2||tabShow.getSelectedColumn()==3)
{
//根據站路名調方法獲得table的模型
javax.swing.table.DefaultTableModel dtm=sel.selectZhan(strSel);
vec.add(dtm);
if(vec.size()>1)
{
btnHuanHui.setEnabled(true);
}
for(int i=0;i<vec.size();i++)
{
System.out.println ("****vecgeti"+vec.get(i));
}
num=vec.size();
tabShow.setModel(dtm);//根據站路名更換Model
}
}
}
});
tabShow.setBounds(20,40,480,430);
pnlSouth.setBounds(0,476,500,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(650,560));
setTitle("長沙公交查詢管理系統");
}
/*構造函數重載 **/
public BtnCenter(BtnShuang bs,DefaultTableModel dtm)
{
super(bs,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, 610,440));
tabShow.setColumnSelectionAllowed(true);
// tabShow.getIntercellSpacing(java.awt.Dimension.);
// tabShow.setcolumnwid
/*用匿名類實現監聽器接口*/
this.tabShow.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent me)
{
if(me.getClickCount()==1&&me.getButton()==me.BUTTON1)
{
String strSel=(String)(tabShow.getValueAt(tabShow.getSelectedRow(),tabShow.getSelectedColumn()));
tabShow.setSelectionForeground(Color.red);
tabShow.setSelectionBackground(Color.GREEN);
if(tabShow.getSelectedColumn()==0)
{
VoSumBus vsb=new VoSumBus();
vsb=sel.selectDataByXianName(strSel);
TabXianLuDialog tabXianLuDialog=new TabXianLuDialog(BtnCenter.this,vsb);
//獲得屏幕的大小
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//獲得窗體的大小
Dimension frameSize = tabXianLuDialog.getSize();
/*以防窗體的大小超過屏幕的大小*/
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
/*設置窗體在屏幕中間*/
tabXianLuDialog.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
tabXianLuDialog.setVisible(true);
}
if(tabShow.getSelectedColumn()==1||tabShow.getSelectedColumn()==2||tabShow.getSelectedColumn()==3)
{
//根據站路名調方法獲得table的模型
javax.swing.table.DefaultTableModel dtm=sel.selectZhan(strSel);
vec.add(dtm);
if(vec.size()>1)
{
btnHuanHui.setEnabled(true);
}
for(int i=0;i<vec.size();i++)
{
System.out.println ("****vecgeti"+vec.get(i));
}
num=vec.size();
tabShow.setModel(dtm);//根據站路名更換Model
}
}
}
});
tabShow.setBounds(20,40,480,430);
pnlSouth.setBounds(0,476,500,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(650,560));
setTitle("長沙公交查詢管理系統");
}
/*構造函數重載 **/
public BtnCenter(BtnShuang2Dialog b2s,DefaultTableModel dtm)
{
super(b2s,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, 610,440));
tabShow.setColumnSelectionAllowed(true);
// tabShow.getIntercellSpacing(java.awt.Dimension.);
// tabShow.setcolumnwid
/*用匿名類實現監聽器接口*/
this.tabShow.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent me)
{
if(me.getClickCount()==1&&me.getButton()==me.BUTTON1)
{
String strSel=(String)(tabShow.getValueAt(tabShow.getSelectedRow(),tabShow.getSelectedColumn()));
tabShow.setSelectionForeground(Color.red);
tabShow.setSelectionBackground(Color.GREEN);
if(tabShow.getSelectedColumn()==0)
{
VoSumBus vsb=new VoSumBus();
vsb=sel.selectDataByXianName(strSel);
TabXianLuDialog tabXianLuDialog=new TabXianLuDialog(BtnCenter.this,vsb);
//獲得屏幕的大小
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//獲得窗體的大小
Dimension frameSize = tabXianLuDialog.getSize();
/*以防窗體的大小超過屏幕的大小*/
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
/*設置窗體在屏幕中間*/
tabXianLuDialog.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
tabXianLuDialog.setVisible(true);
}
if(tabShow.getSelectedColumn()==1||tabShow.getSelectedColumn()==2||tabShow.getSelectedColumn()==3)
{
//根據站路名調方法獲得table的模型
javax.swing.table.DefaultTableModel dtm=sel.selectZhan(strSel);
vec.add(dtm);
if(vec.size()>1)
{
btnHuanHui.setEnabled(true);
}
for(int i=0;i<vec.size();i++)
{
System.out.println ("****vecgeti"+vec.get(i));
}
num=vec.size();
tabShow.setModel(dtm);//根據站路名更換Model
}
}
}
});
tabShow.setBounds(20,40,480,430);
pnlSouth.setBounds(0,476,500,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(650,560));
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 + -