📄 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 + -