📄 generatewizardconnectioncard.java
字号:
package org.dbgen.view;import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;import org.dbgen.gui.*;import org.dbgen.DbGenPro;import org.dbgen.support.StringHelper;/** * This class was generated by a SmartGuide. * */public class GenerateWizardConnectionCard extends javax.swing.JPanel implements WizardCard, TextFieldListener, ActionListener { org.dbgen.view.TextField fieldDriverField = null; org.dbgen.view.TextField fieldUrlField = null; org.dbgen.view.TextField fieldUsernameField = null; protected static final int DRIVER_FIELD = 1; protected static final int URL_FIELD = 2; protected static final int USERNAME_FIELD = 3; protected static final int PASSWORD_FIELD = 4; boolean fieldDriverLoaded = false; org.dbgen.support.DbAccess fieldDBA = null; JButton fieldConnectButton = null; PasswordField fieldPasswordField = null; /** * ImportWizardCard1 constructor comment. */ public GenerateWizardConnectionCard() { super(); initialize(); } /** * This method was created by a SmartGuide. * @param event java.awt.event.ActionEvent */ public void actionPerformed(ActionEvent event) { try { Wizard wizard = Wizard.findWizard(this); wizard.setMessage("Connecting Data Source... "); wizard.repaint(); org.dbgen.support.DbAccess dba = getDBA(); dba.setDriver(getDriverField().getText()); dba.setUrl(getUrlField().getText()); dba.setUser(getUsernameField().getText()); dba.setPassword(new String(getPasswordField().getPassword())); dba.connect(true); //wizard.setMessage("Successful! Please Click NEXT Button."); //wizard.updateSensitivities(); CommonDialog.showInformation(wizard, "Connection Status", "JDBC Connection Successful!"); } catch (ClassNotFoundException e1) { JOptionPane.showMessageDialog(this, "Cannot load class " + getDriverField().getText() + "!", "Error Message", JOptionPane.ERROR_MESSAGE); } catch (SQLException e2) { JOptionPane.showMessageDialog(this, "SQLException: " + e2.toString(), "Error Message", JOptionPane.ERROR_MESSAGE); } return; } /** * This method was created by a SmartGuide. * @param wizard org.dbgen.gui.Wizard */ public void cardShown(Wizard wizard) { /* Fill in some default values */ if (getDriverField().getText().length() == 0) { String driver = (String) DbGenPro.getValue(DbGenPro.JDBC_DRIVER); if (driver == null) { getDriverField().setText("sun.jdbc.odbc.JdbcOdbcDriver"); getUrlField().setText("jdbc:odbc:dsn"); getUsernameField().setText("yourname"); getPasswordField().setText("yourpassword"); } else { getDriverField().setText(driver); getUrlField().setText((String) DbGenPro.getValue(DbGenPro.JDBC_URL)); getUsernameField().setText((String) DbGenPro.getValue(DbGenPro.JDBC_USERNAME)); getPasswordField().setText((String) DbGenPro.getValue(DbGenPro.JDBC_PASSWORD)); } Wizard.findWizard(this).setMessage("Tips: Enter the parameters to connect to your database."); } return; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean enableFinishButton() { return true; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean enableNextButton() { return false; } /** * This method was created by a SmartGuide. * @return java.lang.String */ public String getCardName() { return "Import Wizard Card #1"; } /** * Gets the connectButton property (javax.swing.JButton) value. * @return The connectButton property value. */ public JButton getConnectButton() { /* Returns the connectButton property value. */ if (fieldConnectButton == null) { try { fieldConnectButton = new JButton(); } catch (Throwable exception) { System.err.println("Exception creating connectButton property."); } }; return fieldConnectButton; } /** * Gets the DBA property (org.dbgen.support.DbAccess) value. * @return The DBA property value. * @see #setDBA */ public org.dbgen.support.DbAccess getDBA() { /* Returns the DBA property value. */ if (fieldDBA == null) { try { fieldDBA = new org.dbgen.support.DbAccess(); } catch (Throwable exception) { System.err.println("Exception creating DBA property."); } }; return fieldDBA; } /** * Gets the driverField property (org.dbgen.view.TextField) value. * @return The driverField property value. * @see #setDriverField */ public TextField getDriverField() { /* Returns the driverField property value. */ if (fieldDriverField == null) { try { fieldDriverField = new TextField(); } catch (Throwable exception) { System.err.println("Exception creating driverField property."); } }; return fieldDriverField; } /** * Gets the driverLoaded property (boolean) value. * @return The driverLoaded property value. * @see #setDriverLoaded */ public boolean getDriverLoaded() { /* Returns the driverLoaded property value. */ return fieldDriverLoaded; } /** * This method was created by a SmartGuide. * @return java.awt.Dimension */ public Dimension getMinimumSizeOld() { return new Dimension(400, 150); } /** * Gets the passwordField property (org.dbgen.view.PasswordField) value. * @return The passwordField property value. */ public PasswordField getPasswordField() { /* Returns the passwordField property value. */ if (fieldPasswordField == null) { try { fieldPasswordField = new PasswordField(); } catch (Throwable exception) { System.err.println("Exception creating passwordField property."); } }; return fieldPasswordField; } /** * Gets the urlField property (org.dbgen.view.TextField) value. * @return The urlField property value. */ public org.dbgen.view.TextField getUrlField() { /* Returns the urlField property value. */ if (fieldUrlField == null) { try { fieldUrlField = new org.dbgen.view.TextField(); } catch (Throwable exception) { System.err.println("Exception creating urlField property."); } }; return fieldUrlField; } /** * Gets the usernameField property (org.dbgen.view.TextField) value. * @return The usernameField property value. */ public org.dbgen.view.TextField getUsernameField() { /* Returns the usernameField property value. */ if (fieldUsernameField == null) { try { fieldUsernameField = new org.dbgen.view.TextField(); } catch (Throwable exception) { System.err.println("Exception creating usernameField property."); } }; return fieldUsernameField; } /** * This method was created by a SmartGuide. */ public void initialize() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); Insets insets = new Insets(5, 5, 5, 5); int row = 1; Util.addgbc2(this, new JLabel("How do you connect to your database in Test classes?"), gbc, row++, 1, 2, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, new Insets(5, 5, 5, 10)); Util.addgbc2(this, new JLabel("Driver Class:"), gbc, row, 1, 1, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc2(this, getDriverField(), gbc, row++, 2, 1, 1, .7f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); Util.addgbc2(this, new JLabel("Data Source URL:"), gbc, row, 1, 1, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc2(this, getUrlField(), gbc, row++, 2, 1, 1, .7f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); Util.addgbc2(this, new JLabel("Username:"), gbc, row, 1, 1, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc2(this, getUsernameField(), gbc, row++, 2, 1, 1, .7f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); Util.addgbc2(this, new JLabel("Password:"), gbc, row, 1, 1, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc2(this, getPasswordField(), gbc, row++, 2, 1, 1, .7f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); Util.addgbc2(this, getConnectButton(), gbc, row++, 1, 2, 1, 0f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); getConnectButton().setText("Test Connection"); getConnectButton().addActionListener(this); getDriverField().addSetFieldListener(this, DRIVER_FIELD); getUrlField().addSetFieldListener(this, URL_FIELD); getUsernameField().addSetFieldListener(this, USERNAME_FIELD); getPasswordField().addSetFieldListener(this, PASSWORD_FIELD); return; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean proceedNext() { return true; } /** * Sets the DBA property (org.dbgen.support.DbAccess) value. * @param DBA The new value for the property. * @see #getDBA */ public void setDBA(org.dbgen.support.DbAccess DBA) { fieldDBA = DBA; return; } /** * Sets the driverField property (org.dbgen.view.TextField) value. * @param driverField The new value for the property. * @see #getDriverField */ public void setDriverField(TextField driverField) { /* Get the old property value for fire property change event. */ TextField oldValue = fieldDriverField; /* Set the driverField property (attribute) to the new value. */ fieldDriverField = driverField; /* Fire (signal/notify) the driverField property change event. */ firePropertyChange("driverField", oldValue, driverField); return; } /** * Sets the driverLoaded property (boolean) value. * @param driverLoaded The new value for the property. * @see #getDriverLoaded */ public void setDriverLoaded(boolean driverLoaded) { /* Get the old property value for fire property change event. */ boolean oldValue = fieldDriverLoaded; /* Set the driverLoaded property (attribute) to the new value. */ fieldDriverLoaded = driverLoaded; /* Fire (signal/notify) the driverLoaded property change event. */ firePropertyChange("driverLoaded", new Boolean(oldValue), new Boolean(driverLoaded)); return; } /** * This method was created by a SmartGuide. * @param id int * @param value java.lang.String */ public void setField(int id, String value) { /* Make sure DBA is not null when user changes settings. */ try { getDBA().disconnect(); } catch (SQLException exception) { } Wizard.findWizard(this).updateSensitivities(); return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -