?? myface.java
字號(hào):
package com.ljz.gongJiaoSearch;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import java.awt.event.WindowListener;
import java.util.EventListener;
public class MyFace extends JFrame implements ActionListener, ItemListener, ListSelectionListener, WindowListener,MouseListener{
private JMenu menu;
private JMenuBar menubar;
private JMenuItem menuitem;
private JComboBox c1,c2;
private JButton b1,b2;
private JList list;
private Face face;
private Search search=new Search();
private DiTuImage dt;
JTextArea t=new JTextArea();
private JCheckBoxMenuItem mShuJuLuRu;
public MyFace(Face fff){
super("起止點(diǎn)查詢");//設(shè)置Title
getContentPane().setLayout(new BorderLayout());
face=fff;
int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int height=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setSize(width,height-30);//設(shè)置初始大小
// this.setAlwaysOnTop(true);//設(shè)置總在最上
//this.setResizable(false);//設(shè)置不允許改變大小
this.setLocation(0,0);//設(shè)置初始位置
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);//設(shè)置默認(rèn)關(guān)閉命令
initializationMenu();//初始化菜單
this.addWindowListener(this);
this.setVisible(true);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true);
getContentPane().add(splitPane);
splitPane.setDividerLocation(width-430);
splitPane.setOneTouchExpandable(true);
// splitPane.setEnabled(false);
//加入地圖
dt=new DiTuImage("qizi.jpg",this);
JPanel pdt=new JPanel(new BorderLayout());
JScrollPane js=new JScrollPane(dt);
js.setBorder(new BevelBorder(BevelBorder.LOWERED));
pdt.add(js);
pdt.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue),"地圖"));
JPanel p3=new JPanel(null);
this.list=new JList();
JScrollPane j2=new JScrollPane(list);
j2.setBounds(30, 224, 278, 98);
p3.add(j2);
list.setBorder(new BevelBorder(BevelBorder.LOWERED));
this.list.addListSelectionListener(this);
splitPane.setLeftComponent(pdt);
splitPane.setRightComponent(new JScrollPane(p3));
c2=new JComboBox(new String[]{"黃河","動(dòng)物","醫(yī)院","火車(chē)","車(chē)站"});
c2.setBounds(77, 174, 150, 23);
p3.add(c2);
c2.setEditable(true);
c1=new JComboBox(new String[]{"交巡警二大隊(duì)"});
c1.setBounds(77, 145, 150, 23);
p3.add(c1);
c1.setEditable(true);
final JLabel label = new JLabel("終點(diǎn):");
label.setBounds(30, 178, 54, 15);
p3.add(label);
final JLabel label_1 = new JLabel("起點(diǎn):");
label_1.setBounds(30, 149, 54, 15);
p3.add(label_1);
this.b1=new JButton("OK(A)");
b1.setBounds(233, 144, 75, 25);
p3.add(b1);
b1.setMnemonic('a');
b1.addActionListener(this);
this.getRootPane().setDefaultButton(b1);
//p1.add(b1);
//JLabel jk=new JLabel("路線:");
//p4.add(jk);
//jk.setBounds(20,20,50,20);
//p4.add(new JScrollPane(list));
//p2.add(p4,BorderLayout.NORTH);
b1.setToolTipText("OK(A)");
this.b2=new JButton("地圖選擇(B)");
b2.setBounds(533, 162, 75, 25);
p3.add(b2);
b2.setMnemonic('a');
b2.addActionListener(this);
b2.setToolTipText("從地圖選擇(B)");
JScrollPane j1=new JScrollPane(t);
t.addMouseListener(this);
t.setToolTipText("雙擊鼠標(biāo)將顯示路線詳細(xì)信息!");
j1.setBounds(28, 357, 352, 159);
p3.add(j1);
j1.setViewportView(t);
t.setBorder(new BevelBorder(BevelBorder.LOWERED));
final JLabel label_2 = new JLabel();
label_2.setText("線路列表:");
label_2.setBounds(30, 203, 90, 15);
p3.add(label_2);
final JLabel label_2_1 = new JLabel();
label_2_1.setText("結(jié)果列表:");
label_2_1.setBounds(31, 328, 89, 23);
p3.add(label_2_1);
final JLabel label_3 = new JLabel();
label_3.setForeground(new Color(255, 0, 255));
label_3.setFont(new Font("黑體", Font.BOLD | Font.ITALIC, 42));
label_3.setText("公交查詢");
label_3.setBounds(58, 51, 250, 56);
p3.add(label_3);
b2.setVisible(false);
}
//初始化菜單
public void initializationMenu(){
menuitem=new JMenuItem("關(guān)閉(C)");
menuitem.setMnemonic('c');
menuitem.addActionListener(this);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
mShuJuLuRu=new JCheckBoxMenuItem("數(shù)據(jù)錄入(Z)");
mShuJuLuRu.addActionListener(this);
mShuJuLuRu.setMnemonic('z');//在此處表示可見(jiàn)快捷鍵
mShuJuLuRu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.CTRL_MASK));
menu=new JMenu("文件(F)");
menu.setMnemonic('f');
menu.add(mShuJuLuRu);
menu.addSeparator();
menu.add(menuitem);
menubar=new JMenuBar();
menubar.add(menu);
this.setJMenuBar(menubar);
}
//main方法
public static void main(String[] args){
//new MyFace(new Face());
}
int qsd=0;
public boolean setQiShiDian(String s){
if(qsd==0){
this.c1.getEditor().setItem(s);
qsd=1;
return true;
}else if(qsd==1){
this.c2.getEditor().setItem(s);
qsd=-1;
searchLuXian();
list.setSelectedIndex(0);
return true;
}
return false;
}
public void setChongXinKaiShi(){
qsd=0;
dt.setLabelForColor(Color.blue);
}
public void searchLuXian(){
String s1=((String)c1.getEditor().getItem()).trim();
String s2=((String)c2.getEditor().getItem()).trim();
if(s1.equals("")||s2.equals("")||s1.equals(s2))
return;
//加入JList
list.removeAll();
ArrayList al=search.getKeNeng(s1,s2);
String[] v=new String[al.size()];
for(int i=0;i<al.size();i++)
v[i]=(String)al.get(i);
if(al.size()==0){
v=new String[1];
v[0]="Sorry!";
}
list.setListData(v);
}
//ActionEvent
public void actionPerformed(ActionEvent e) {
//
if(e.getSource()==this.b1){
searchLuXian();
}else if(e.getSource()==menuitem){
this.dispose();
face.setVisible(true);
}else if(e.getSource()==this.b2){
//setChongXinKaiShi();
dt.shuJuLuRu();
}else if (e.getSource()==mShuJuLuRu) {
dt.setShujuluru(mShuJuLuRu.isSelected());
}
}
//DEBUG
public static void Debug(ArrayList k){
if(DEBUG)
for(int i=0;i<k.size();i++)
Debug((String)k.get(i));
}
public static void Debug(String s){
if(DEBUG)
System.out.println(s);
}
/**
* Method itemStateChanged
*
*
* @param e
*
*/
public void itemStateChanged(ItemEvent e) {
// TODO: 在這添加你的代碼
}
/**
* Method valueChanged
*
*
* @param e
*
*/
private boolean bd=true;
public void valueChanged(ListSelectionEvent e) {
if(bd){
String s=(String)list.getSelectedValue();
s=search.getPath(s);
t.setText(s);
bd=false;
}else
bd=true;
}
/**
* Method windowOpened
*
*
* @param e
*
*/
public void windowOpened(WindowEvent e) {
// TODO: 在這添加你的代碼
}
public void windowClosing(WindowEvent e) {
face.setVisible(true);
}
public void windowClosed(WindowEvent e) {
// TODO: 在這添加你的代碼
}
public void windowIconified(WindowEvent e) {
// TODO: 在這添加你的代碼
}
public void windowDeiconified(WindowEvent e) {
//face.setVisible(true);
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
// TODO: 在這添加你的代碼
}
public Search getSearch() {
return search;
}
//鼠標(biāo)事件
XiangXiXinXi xx=null;
public void mouseClicked(MouseEvent e) {
if(e.getSource()==t){
if (e.getButton()==1 && e.getClickCount()==2) {
String s=search.getPath2();
if(xx==null || !xx.isVisible())
xx=new XiangXiXinXi(s);
}
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -