?? biaojishezhi.java
字號:
package com.ljz.gongJiaoSearch;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.BevelBorder;
public class BiaoJiSheZhi extends JFrame implements ActionListener,ItemListener{
private JComboBox comboBox_3;
private JComboBox comboBox_2;
private JTextArea textArea;
private JComboBox comboBox;
private DiTuImage dtimage;
private MyFace myface;
private JLabel label_1_2_1;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
// BiaoJiSheZhi frame = new BiaoJiSheZhi(new Point);
// frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public BiaoJiSheZhi(Point p,DiTuImage d,MyFace m) {
super();
this.myface=m;
this.point=p;
this.dtimage=d;
setSize(435, 340);
setTitle("添加標記");
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setLocation(200, 150);
setResizable(false);
final JLabel label_1 = new JLabel();
label_1.setFont(new Font("", Font.PLAIN, 18));
label_1.setText("名稱");
label_1.setBounds(70, 105, 60, 15);
getContentPane().add(label_1);
final JLabel label_1_1 = new JLabel();
label_1_1.setFont(new Font("", Font.PLAIN, 18));
label_1_1.setText("詳細信息");
label_1_1.setBounds(70, 160, 103, 15);
getContentPane().add(label_1_1);
final JLabel label = new JLabel();
label.setFont(new Font("", Font.PLAIN, 18));
label.setText("類型");
label.setBounds(72, 38, 60, 15);
getContentPane().add(label);
comboBox = new JComboBox(new String[]{"公交站點","位置標記"});
comboBox.setEditable(true);
comboBox.setBounds(124, 34, 144, 23);
getContentPane().add(comboBox);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(75, 185, 288, 61);
getContentPane().add(scrollPane);
textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollPane.setViewportView(textArea);
final JLabel label_2 = new JLabel();
label_2.setText("路線");
label_2.setBounds(70, 70, 60, 15);
label_2.setFont(new Font("", Font.PLAIN, 18));
getContentPane().add(label_2);
comboBox_2 = new JComboBox();
comboBox_2.setBounds(125, 65, 144, 23);
getContentPane().add(comboBox_2);
comboBox_2.addItemListener(this);
comboBox_3 = new JComboBox(new String[]{""});
comboBox_3.setBounds(125, 100, 144, 23);
comboBox_3.setEditable(true);
getContentPane().add(comboBox_3);
button = new JButton();
button.setText("確定(E)");
button.setBounds(93, 259, 99, 23);
getContentPane().add(button);
button.addActionListener(this);
button_1 = new JButton();
button_1.setText("取消(C)");
button_1.setBounds(229, 259, 99, 23);
getContentPane().add(button_1);
button_1.addActionListener(this);
//
setVisible(true);
final JLabel label_1_2 = new JLabel();
label_1_2.setFont(new Font("Dialog", Font.PLAIN, 18));
label_1_2.setText("位置");
label_1_2.setBounds(70, 130, 60, 23);
getContentPane().add(label_1_2);
label_1_2_1 = new JLabel();
label_1_2_1.setFont(new Font("Dialog", Font.PLAIN, 18));
label_1_2_1.setBounds(125, 130, 143, 23);
getContentPane().add(label_1_2_1);
chuShiHuaLuXian();//初始化所有路線號信息
}
//初始化所有路線號信息
public void chuShiHuaLuXian() {
Search search=myface.getSearch();
String[] bn=search.getHaos();
b=false;
comboBox_2.addItem("");
for(int i=0;i<bn.length;i++)
comboBox_2.addItem(bn[i]);
b=true;
//初始化位置信息
label_1_2_1.setText("( "+(int)point.getX()+","+(int)point.getY()+" )");
}
//button event
private final JButton button;
private final JButton button_1;
private Point point;
public void actionPerformed(ActionEvent e) {
//添加
if(e.getSource()==this.button){
// jian cha shi fou wei fan gui ding
String leixing=((String)this.comboBox.getEditor().getItem()).trim();
String name=((String)this.comboBox_3.getEditor().getItem()).trim();
if(leixing.equals("")||name.equals("")){
JOptionPane.showMessageDialog(this, "請將信息填寫完整。");
return;
}
//檢查站點是否重復
DataBaseManager dbm=new DataBaseManager();
String strSQL="select * from zhandianxinxi";
ResultSet rs=dbm.getResult(strSQL);
try {
if(!rs.first())
return;
while(!rs.isAfterLast()){
String s=rs.getString(1);
if(s.equals(name)){
JOptionPane.showMessageDialog(this, "已存在該站點。");
return;
}
rs.next();
}
// 添加
strSQL="INSERT INTO zhandianxinxi(name,x,y,leixing,xiangxixinxi) values ('"+name+"','"+(int)point.getX()+"','"+(int)point.getY()+"','"+leixing+"','"+this.textArea.getText().trim()+"')";
dbm.updateSql(strSQL);
dbm.closeConnection();
// 刷新界面
dtimage.addBiaoQian();
this.dispose();
} catch (Exception ee) {
ee.printStackTrace();
}
}else if (e.getSource()==this.button_1) {
this.dispose();
}
}
private boolean b=true;
public void itemStateChanged(ItemEvent e) {
if(b){
String s=(String)comboBox_2.getSelectedItem();
String[] p=myface.getSearch().fanHuiZhanDian(s);
comboBox_3.removeAllItems();
//int a = comboBox_3.getItemCount();
comboBox_3.addItem("");
//System.out.println(a);
//if(a>2){
// for(int i=a-2;i>0;i--)
// comboBox_3.remove(i);
//}
for (int i = 0; i < p.length; i++) {
comboBox_3.addItem(p[i]);
}
//b=false;
}//else
//b=true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -