📄 netsetup.java
字号:
jp1.add (cb1);
jp3.add (lb2);
jp3.add (tf7);
jp4.add (tf8);
jp4.add (bt4);
jp2.add (jp3);
jp2.add (jp4);
lt.add ("North", jp1);
lt.add ("Center", jp2);
//右边面板
jp5.add (lb3);
jp5.add (cb2);
jp6.add (rb1);
jp6.add (rb2);
jp6.add (rb3);
rt.add ("North", jp5);
rt.add ("Center", jp6);
bs.add (lt);
bs.add (rt);
//加标题框
jp1.setBorder (BorderFactory.createTitledBorder ("数据库连接方式"));
jp2.setBorder (BorderFactory.createTitledBorder ("ODBC连接设置"));
jp5.setBorder (BorderFactory.createTitledBorder ("窗口起始页"));
jp6.setBorder (BorderFactory.createTitledBorder ("系统外观设置"));
return bs; //返回一个JPanel
}
/**=======================================================================**
* [## private void setupInit(int fg) {} ]: 根据INI文件初起化默认值
* 参数 :int fg变量是一个标志,
* 取值0、1的时候为连接方式事件调用的刷新;
* 取值2的时候为通过INI文件初起化各组件的默认值。
* 返回值 :无
* 修饰符 :private
* 功能 :设置本对话框各组件的默认值
**=======================================================================**
*/
private void setupInit(int fg) {
int link = 0; //取值 0,1
int page = 0; //取值 0,1
char style = '2'; //取值 0,1,2
tf1.setText (sunini.getIniKey (ini[31]));
tf2.setText (sunini.getIniKey (ini[32]));
tf3.setText (sunini.getIniKey (ini[28]));
tf4.setText (sunini.getIniKey (ini[29]));
tf5.setText (sunini.getIniKey (ini[30]));
tf7.setText (sunini.getIniKey (ini[34]));
//风格默认设定
style = sunini.getIniKey (ini[7]).charAt (0);
switch(style) {
case '0':
rb1.setSelected (true);
break;
case '1':
rb2.setSelected (true);
break;
case '2':
rb3.setSelected ( true );
break;
}
//连接方式默认值设定
if(fg == 2) {
link = Integer.parseInt (sunini.getIniKey (ini[5]));
cb1.setSelectedIndex (link);
}
else { link = fg; }
//起始页默认设定
page = Integer.parseInt (sunini.getIniKey (ini[6]));
cb2.setSelectedIndex (page);
if(link == 0) {
tf1.setEditable (false);
tf2.setEditable (false);
tf3.setEditable (false);
tf4.setEditable (false);
tf5.setEditable (false);
tf7.setEditable (true);
bt3.setEnabled (false);
bt4.setEnabled (true);
}
else {
tf1.setEditable (true);
tf2.setEditable (true);
tf3.setEditable (true);
tf4.setEditable (true);
tf5.setEditable (true);
tf7.setEditable (false);
bt3.setEnabled (true);
bt4.setEnabled (false);
}
}
//
/**=======================================================================**
* [## private void ceShi() {} ]: 测试连接
* 参数 :无
* 返回值 :无
* 修饰符 :private
* 功能 :测试对话框里的设置能否正常连接数据库
**=======================================================================**
*/
private void ceShi() {
int flag = cb1.getSelectedIndex();
try {
Statement ste = null;
if(flag == 1) { //JDBC连接方式
String user = tf4.getText();
String pwd = tf5.getText();
String ip = tf1.getText();
String acc = tf2.getText();
String dbf = tf3.getText();
String url = "jdbc:microsoft:sqlserver://" + ip + ":" + acc + ";" + "databasename=" + dbf;
//注册驱动
DriverManager.registerDriver (new com.microsoft.jdbc.sqlserver.SQLServerDriver());
//获得一个连接
Connection conn = DriverManager.getConnection (url, user, pwd);
//建立高级载体
ste = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
tf6.setText ("测试结果: 成功连接到服务器");
ste.close();
conn.close();
//将INI键值存入缓冲区
sunini.setIniKey(ini[31], ip);
sunini.setIniKey(ini[32], acc);
sunini.setIniKey(ini[28], dbf);
sunini.setIniKey(ini[29], user);
sunini.setIniKey(ini[30], pwd);
}
else {
//注册驱动 //JDBCODBC连接方式
DriverManager.registerDriver (new sun.jdbc.odbc.JdbcOdbcDriver());
//获得一个连接
Connection conn = DriverManager.getConnection ("jdbc:odbc:" + tf7.getText());
//建立高级载体
ste = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
tf8.setText ("测试结果: 成功连接到服务器");
ste.close();
conn.close();
//将INI键值存入缓冲区
sunini.setIniKey(ini[34], tf7.getText());
}//End if(flag == 1)
sunini.setIniKey(ini[5], cb1.getSelectedIndex()+""); //保存连接方式设置
sunini.setIniKey(ini[6], cb2.getSelectedIndex()+""); //保存起始页
bt1.setEnabled ( true );
}
catch (Exception ex) {
if(flag == 1)
tf6.setText ("测试结果: 连接失败 ...");
else
tf8.setText ("测试结果: 连接失败 ...");
bt1.setEnabled (false);
JOptionPane.showMessageDialog (null, "无法连接到服务器,请检查参数配置与网络连接 ...", "错误", JOptionPane.ERROR_MESSAGE);
}
}
/**=======================================================================**
* ActionListener 监听
**=======================================================================**
*/
public void actionPerformed (ActionEvent ae) {
Object o = ae.getSource();
if(o == rb1)
sunini.setIniKey(ini[7], "0"); //设置外观为Windows 风格
else if(o == rb2)
sunini.setIniKey(ini[7], "1"); //设置外观为JAVA 默认风格
else if(o == rb3)
sunini.setIniKey(ini[7], "2"); //设置外观为JAVA 金属风格
else if(o == bt1) {
int fee = JOptionPane.showConfirmDialog(null, "是否要保存当前设置 ?", "提示", JOptionPane.YES_NO_OPTION);
if(fee == JOptionPane.YES_OPTION) {
sunini.saveIni(ini); //保存INI文件
JOptionPane.showMessageDialog(null, "您已更改了系统设置,必须重新登录系统 ...", "提示", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//Ene if(fee == JOptionPane.YES_OPTION)
else
bt1.setEnabled(false);
}//End if(o == bt1)
else if(o == bt2)
this.setVisible(false); //返回
else if(o == bt3 || o==bt4)
ceShi(); //测试连接
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) { //鼠标移进提示
Object o = me.getSource ();
if(o == bt1) {
HotelFrame.lbA.setText (HotelFrame.clue +
"将当前设置保存到INI配置文件中 ");
}else if(o == bt2) {
HotelFrame.lbA.setText (HotelFrame.clue +
"返回主操作界面 ");
}else if(o == bt3) {
HotelFrame.lbA.setText (HotelFrame.clue +
"测试当前连接方式是否能正常连接指定的数据库 ");
}else if(o == bt4) {
HotelFrame.lbA.setText (HotelFrame.clue +
"测试当前连接方式是否能正常连接指定的数据库 ");
}
}
public void mouseExited (MouseEvent me) {
HotelFrame.lbA.setText (HotelFrame.clue +
"请选择功能项 ... ");
}
/**=======================================================================**
* KeyListener 监听
**=======================================================================**
*/
public void keyPressed (KeyEvent ke) {
//键盘按下监听
}
public void keyReleased (KeyEvent ke) {
//键盘释放监听
bt1.setEnabled (false);
}
public void keyTyped (KeyEvent ke) {
//按键型监听
}
/**=======================================================================**
* ItemListener 监听
**=======================================================================**
*/
public void itemStateChanged (ItemEvent ie) {
if(ie.getSource() == cb1) {
setupInit(cb1.getSelectedIndex()); //刷新控件的值
bt1.setEnabled(false);
}//Endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -