📄 changetypepanel.java
字号:
/********************************************************************
*
* $RCSfile: ChangeTypePanel.java,v $ $Revision: 1.1 $ $Date: 2003/09/22 08:06:23 $
*
* $Log: ChangeTypePanel.java,v $
* Revision 1.1 2003/09/22 08:06:23 icestone
* init
*
*
*
**********************************************************************/
package pcdmupgradedata;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import java.awt.event.*;
/**
* <p>Title: 选择对应设施的jpanel</p>
* <p>Description: </p>
*/
public class ChangeTypePanel extends JPanel {
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
public static JComboBox jComboBox1 = new JComboBox();
public static JComboBox jComboBox2 = new JComboBox();
static DefaultListModel ListModel1=new DefaultListModel();
private DefaultListModel ListModel2=new DefaultListModel();
static DefaultListModel ListModel3=new DefaultListModel();
public static JList jList1 = new JList(ListModel1);
private JList jList2 = new JList(ListModel2);
private JPanel jPanel3 = new JPanel();
private JButton jButton1 = new JButton(new ImageIcon(Const.ARRW_R_IMAGE));
private JButton jButton2 = new JButton(new ImageIcon(Const.ARRW_L_IMAGE));
public static JList jList3 = new JList(ListModel3);
private PaneLayout paneLayout1 = new PaneLayout();
private TitledBorder titledBorder1;
private TitledBorder titledBorder2;
private TitledBorder titledBorder3;
Connection conn;
private JScrollPane jScrollPane1 = new JScrollPane();
private JScrollPane jScrollPane2 = new JScrollPane();
private PaneLayout paneLayout2 = new PaneLayout();
public ChangeTypePanel(Connection conn) {
this.conn=conn;
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
/*add combobox*/
addCombobox(conn);
}
void jbInit() throws Exception {
titledBorder1 = new TitledBorder("已入库数据类型");
titledBorder3 = new TitledBorder("标准定义设施类型");
this.setBorder(BorderFactory.createEtchedBorder());
this.setLayout(null);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(6, 44, 298, 282));
jPanel1.setLayout(paneLayout2);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBounds(new Rectangle(7, 6, 296, 36));
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setBounds(new Rectangle(355, 11, 173, 314));
jPanel3.setLayout(paneLayout1);
jButton1.setBounds(new Rectangle(310, 127, 37, 26));
jButton1.setBorder(BorderFactory.createRaisedBevelBorder());
jButton1.setToolTipText("选择");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setBounds(new Rectangle(312, 166, 36, 26));
jButton2.setBorder(BorderFactory.createRaisedBevelBorder());
jButton2.setToolTipText("删除");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jList1.setBorder(titledBorder1);
jList2.setBorder(titledBorder3);
jList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox1_actionPerformed(e);
}
});
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox2_actionPerformed(e);
}
});
this.add(jPanel1, null);
jPanel1.add(jScrollPane1, new PaneConstraints("jScrollPane1", "jScrollPane1", PaneConstraints.ROOT, 1.0f));
jScrollPane1.getViewport().add(jList1, null);
jPanel1.add(jScrollPane2, new PaneConstraints("jScrollPane2", "jScrollPane1", PaneConstraints.RIGHT, 0.53691274f));
jScrollPane2.getViewport().add(jList2, null);
jPanel2.add(jComboBox1, null);
jPanel2.add(jComboBox2, null);
this.add(jButton1, null);
this.add(jButton2, null);
this.add(jPanel3, null);
jPanel3.add(jList3, new PaneConstraints("jList3", "jList3", PaneConstraints.ROOT, 0.5f));
this.add(jPanel2, null);
}
private void addCombobox(Connection conn){
String Query = "select distinct tablename from codelist where fieldname like '%设施类型'";
try{
Statement QueryTableStatement = conn.createStatement();
ResultSet TableNameResult=QueryTableStatement.executeQuery(Query);
while(TableNameResult.next()){
jComboBox1.addItem((Object)TableNameResult.getString(1));
}
QueryTableStatement.close();
TableNameResult.close();
}
catch (java.sql.SQLException se)
{
}
Query=null;
}
void jComboBox1_actionPerformed(ActionEvent e) {
jComboBox2.removeAllItems();
String Query = "select distinct FIELDNAME from codelist where tablename='"+(String)jComboBox1.getSelectedItem()+"' and fieldname like '%设施类型'";
try{
Statement QueryTableStatement = conn.createStatement();
ResultSet TableNameResult=QueryTableStatement.executeQuery(Query);
while(TableNameResult.next()){
jComboBox2.addItem((Object)TableNameResult.getString(1));
}
QueryTableStatement.close();
TableNameResult.close();
}
catch (java.sql.SQLException se)
{
}
Query=null;
}
void jComboBox2_actionPerformed(ActionEvent e) {
ListModel1.removeAllElements();
ListModel2.removeAllElements();
String Query = "select distinct "+(String)jComboBox2.getSelectedItem()+" from "+(String)jComboBox1.getSelectedItem();
try{
Statement QueryTableStatement = conn.createStatement();
ResultSet TableNameResult=QueryTableStatement.executeQuery(Query);
while(TableNameResult.next()){
ListModel1.addElement(TableNameResult.getString(1));
}
QueryTableStatement.close();
TableNameResult.close();
}
catch (java.sql.SQLException se)
{
}
Query = "select VALUE from CODELIST where TABLENAME='"+(String)jComboBox1.getSelectedItem()+"' and fieldname='"+(String)jComboBox2.getSelectedItem()+"' order by SERIAL";
try{
Statement QueryTableStatement = conn.createStatement();
ResultSet TableNameResult=QueryTableStatement.executeQuery(Query);
while(TableNameResult.next()){
ListModel2.addElement(TableNameResult.getString(1));
}
QueryTableStatement.close();
TableNameResult.close();
}
catch (java.sql.SQLException se)
{
}
Query=null;
}
void jButton1_actionPerformed(ActionEvent e) {
if((String)jList2.getSelectedValue()==null) return;
if((jList1.getSelectedValues()).length==1)
ListModel3.addElement((String)jList1.getSelectedValue()+"->"+(String)jList2.getSelectedValue());
else
{
for(int i=0;i<(jList1.getSelectedValues()).length;i++)
{
ListModel3.addElement((jList1.getSelectedValues())[i]+"->"+(String)jList2.getSelectedValue());
}
}
jList1.clearSelection();
jList2.clearSelection();
}
void jButton2_actionPerformed(ActionEvent e) {
ListModel3.removeElement(jList3.getSelectedValue());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -