⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setsysdialog.java

📁 酒店管理系统·可用于一般旅社的营业操作。方便你的酒店管理
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.redingsoft.setsysdialog;import com.redingsoft.locationutil.LocationUtil;import com.redingsoft.sql.SetSQL;import com.redingsoft.sunsdk.swing.OJButton;import java.awt.Color;import java.awt.Dialog;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.*;import javax.swing.*;/** * * @author Administrator */public class SetSysDialog extends JDialog implements ActionListener {   //声明单选按钮     JRadioButton jr1,jr2; //用于选择连接方式    //声明按钮组    ButtonGroup gb;     //声明3个面板用于存放一个一个按钮组和测试消息按一个确定按钮    JPanel jp1,jp2,jp3;   //声明一个主面板    JPanel mainPane;    //声明2个标签    JLabel jl1,jl2;    //声明一个普通按钮    JButton jbt;         public SetSysDialog(){       //实例化2个按钮   jr1=new JRadioButton("JDBC-ODBC桥连");   jr2=new JRadioButton("JDBC直连接");    //实例化按钮组   gb=new ButtonGroup();   //添加2个按钮   gb.add(jr1);   gb.add(jr2);   //实例化2个标签   jl1=new JLabel("测试信息:");   jl2=new JLabel("  ");//用于存放测试信息   //实例化按钮   jbt=new OJButton("com/redingsoft/pic/setup.gif","确定","可以连接并测试连接",true);   //实例化3个面板   jp1=new JPanel();   jp1.setBorder(BorderFactory.createLineBorder(new Color(255,0,0), 1));   jp1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(255,0,0), 1), "选择连接方式"));   jp2=new JPanel(new FlowLayout(FlowLayout.LEADING,5,10));   jp3=new JPanel(new FlowLayout(FlowLayout.LEADING,5,10));   //实例化主面板   mainPane=new JPanel(new FlowLayout(FlowLayout.LEADING,5,10));//  mainPane.setLayout();   // 把单选按钮添加到jp1中   jp1.add(jr1);   jp1.add(jr2);   jr1.setSelected(true);   //把普通按钮添加到jp2   jp2.add(jbt);   //吧标签添加到jp3中   jp3.add(jl1);   jp3.add(jl2);   //将子各面半添加到主面板中   mainPane.add(jp1);   mainPane.add(jp2);   mainPane.add(jp3);   this.add(mainPane);   //添加事件侦听   jbt.addActionListener(this);   //设置窗体大小各种属性   this.setSize(new Dimension(300,200));   this.setResizable(false);   this.setModalityType(Dialog.DEFAULT_MODALITY_TYPE);   this.setDefaultCloseOperation(SetSysDialog.DISPOSE_ON_CLOSE);    LocationUtil.setLocation(this);   this.setVisible(true);  }  //	/**=======================================================================**	 *		[## private void ceShi() {} ]:				测试连接	 *			参数   :无	 *			返回值 :无	 *			修饰符 :private	 *			功能   :测试对话框里的设置能否正常连接数据库	 **=======================================================================**	 */	private void ceShi() {		Boolean flag = jr1.isSelected();		try {			Statement ste = null;			if(flag) {		                            //注册驱动										//JDBCODBC连接方式				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");				//获得一个连接				Connection conn = DriverManager.getConnection ("jdbc:odbc:source" );				//建立高级载体				ste = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);                                jl2.setForeground(new Color(0,0,255));				jl2.setText(" 成功连接到服务器");				ste.close();				conn.close();			}			else {  jl2.setForeground(new Color(255,0,0));				jl2.setText ("  连接失败 ...");			}//End if(flag == 1)	    }	    catch (Exception ex) {	    	if(flag)	    		jl2.setText("  连接失败 ...");	    	else	    		jl2.setText ("  连接失败 ...");	    	jbt.setEnabled (false);	    	JOptionPane.showMessageDialog (null, "无法连接到服务器,请检查参数配置与网络连接 ...", "错误", JOptionPane.ERROR_MESSAGE);	    }	}        /**************************************  public static void main(String ars[]){      new SetSysDialog();  }         * *************************************///事件侦听    public void actionPerformed(ActionEvent e) {      ceShi(); //测试连接    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -