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

📄 formselect.java

📁 weka机器学习系统(本站可下载)的拓展
💻 JAVA
字号:
package com.prcomps.cahitarf.gui;

import com.prcomps.cahitarf.Db2Arff;
import com.sohlman.easylayout.EasyLayout;
import com.sohlman.easylayout.Constraint;

import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import java.util.ResourceBundle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.SQLException;
import java.io.FileNotFoundException;

/**
 */
public class FormSelect
        extends JPanel
        implements IWizardPanel
{
    public static boolean  selectUpdated = false;

    private JTextArea      txtSelect = new JTextArea( 5, 60 );
    private JdbcTableModel tmodel    = new JdbcTableModel();
    private JTable         tblResult = new JTable( tmodel );
    private ResourceBundle bundle    = WizardFrame.getBundle();

    public FormSelect()
    {
        createForm();
        setName( WizardFrame.FORM_SELECT );
    }

    private void createForm()
    {
        setLayout( new EasyLayout( new int[]{ 100 }, new int[] { 0, 0, 0, 100 }, 8, 2 ) );

        txtSelect.addKeyListener( new KeyListener() {
            public void keyTyped( KeyEvent e )
            {
                selectUpdated = true;
            }

            public void keyPressed( KeyEvent e )  {}

            public void keyReleased( KeyEvent e ) {}

        });
        JButton btnRetrieve = new JButton( bundle.getString( "wizard.select.btn" ) );
        btnRetrieve.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e )
            {
                displayRows();
            }
        });
        JScrollPane tablePane = new JScrollPane( tblResult );
        JScrollPane selectPane = new JScrollPane( txtSelect );
        add( new JLabel( bundle.getString( "wizard.select.label") ), new Constraint( 0,0 ) );
        add( selectPane, new Constraint( 0, 1 ) );
        add( btnRetrieve, new Constraint( 0, 2, Constraint.RIGHT, Constraint.CENTER, 4, 4 ) );
        add( tablePane, new Constraint( 0, 3) );
    }

    private void displayRows()
    {
        Db2Arff db2Arff = new Db2Arff();
        db2Arff.setProperties( WizardFrame.properties );
        Connection conn = null;
        try
        {
            db2Arff.loadDrivers();
            conn = db2Arff.connect();
            tmodel.setConnection( conn );
            tmodel.setMaxRows( 50 );
            tmodel.executeQuery( txtSelect.getText() );
        }
        catch ( SQLException e )
        {
            JOptionPane.showMessageDialog( this, e.getMessage(), bundle.getString( "wizard.db.error" ),
                    JOptionPane.ERROR_MESSAGE );
        }
        catch ( ClassNotFoundException e )
        {
            JOptionPane.showMessageDialog( this, e.getMessage(), bundle.getString( "wizard.db.error" ),
                    JOptionPane.ERROR_MESSAGE );
        }
        catch ( FileNotFoundException e )
        {
            JOptionPane.showMessageDialog( this, e.getMessage(), bundle.getString( "wizard.db.error" ),
                    JOptionPane.ERROR_MESSAGE );
        }
    }

    public String getNext()
            throws NotReadyException
    {
        WizardFrame.properties.setProperty( Db2Arff.PROP_JDBC_SELECT, txtSelect.getText() );
        return WizardFrame.FORM_ATTRS;
    }

    public String getPrev()
            throws NotReadyException
    {
        WizardFrame.properties.setProperty( Db2Arff.PROP_JDBC_SELECT, txtSelect.getText() );
        return WizardFrame.FORM_DB;
    }

    public void checkStatus()
    {
        txtSelect.setText( WizardFrame.properties.getProperty( Db2Arff.PROP_JDBC_SELECT ) );
    }
}

⌨️ 快捷键说明

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