?? myface2.java
字號:
package com.ljz.gongJiaoSearch;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowListener;
import java.util.EventListener;
public class MyFace2 extends JFrame implements ActionListener, ItemListener, WindowListener{
private JMenu menu;
private JMenuBar menubar;
private JMenuItem menuitem;
private Search search=new Search();
private JComboBox b=new JComboBox();
private JTextArea t=new JTextArea();
private Face face;
public MyFace2(Face fff){
super("線路查詢");//設置Title
face=fff;
this.setSize(400,280);//設置初始大小
this.setAlwaysOnTop(true);//設置總在最上
this.setResizable(false);//設置不允許改變大小
this.setLocation(200,100);//設置初始位置
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);//設置默認關閉命令
initializationMenu();//初始化菜單
this.addWindowListener(this);
this.setVisible(true);
}
//初始化菜單
public void initializationMenu(){
menuitem=new JMenuItem("關閉(C)");
menuitem.setMnemonic('c');
menuitem.addActionListener(this);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
menu=new JMenu("文件(F)");
menu.setMnemonic('f');
menu.add(menuitem);
menubar=new JMenuBar();
menubar.add(menu);
this.setJMenuBar(menubar);
JLabel lb=new JLabel("請選擇線路:");
Container c=this.getContentPane();
c.setLayout(null);
c.add(lb);
JScrollPane j1=new JScrollPane(t);
c.add(j1);
c.add(b);
lb.setBounds(30,10,100,20);
b.setBounds(120,10,100,20);
j1.setBounds(30,40,330,150);
//b.removeAll();
b.addItem("");
String[] bn=search.getHaos();
for(int i=0;i<bn.length;i++)
b.addItem(bn[i]);
b.addItemListener(this);
t.setLineWrap(true);
}
//main方法
public static void main(String[] args){
//new MyFace2();
}
//ActionEvent
public void actionPerformed(ActionEvent e) {
this.dispose();
face.setVisible(true);
}
/**
* Method itemStateChanged
*
*
* @param e
*
*/
public void itemStateChanged(ItemEvent e) {
String s=(String)b.getSelectedItem();
t.setText(search.getXiangXi(s));
}
/**
* Method windowOpened
*
*
* @param e
*
*/
public void windowOpened(WindowEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method windowClosing
*
*
* @param e
*
*/
public void windowClosing(WindowEvent e) {
face.setVisible(true);
}
/**
* Method windowClosed
*
*
* @param e
*
*/
public void windowClosed(WindowEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method windowIconified
*
*
* @param e
*
*/
public void windowIconified(WindowEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method windowDeiconified
*
*
* @param e
*
*/
public void windowDeiconified(WindowEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method windowActivated
*
*
* @param e
*
*/
public void windowActivated(WindowEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method windowDeactivated
*
*
* @param e
*
*/
public void windowDeactivated(WindowEvent e) {
// TODO: 在這添加你的代碼
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -