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

📄 gui.java

📁 一个简单的数据库
💻 JAVA
字号:
/* * GUI.java * * Created on 2008年10月27日, 上午9:27 */package test;import apiManager.*;import interpreterManager.*;import database.*;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.JFileChooser;import javax.swing.UnsupportedLookAndFeelException;import stringManager.*;import java.io.*;import java.util.ArrayList;import javax.swing.UIManager;/** * * @author  outlaw */public class GUI extends javax.swing.JFrame {    /** Creates new form GUI */    public GUI()  {        initComponents();        try {            init();        } catch (Exception ex) {            ex.printStackTrace();        }    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jScrollPane1 = new javax.swing.JScrollPane();        command = new javax.swing.JTextArea();        jScrollPane2 = new javax.swing.JScrollPane();        result = new javax.swing.JTextArea();        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        start = new javax.swing.JButton();        jScrollPane3 = new javax.swing.JScrollPane();        history = new javax.swing.JTextArea();        jLabel3 = new javax.swing.JLabel();        jMenuBar1 = new javax.swing.JMenuBar();        jMenu1 = new javax.swing.JMenu();        open = new javax.swing.JMenuItem();        jMenu2 = new javax.swing.JMenu();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setResizable(false);        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                formWindowClosing(evt);            }        });        command.setColumns(20);        command.setRows(5);        jScrollPane1.setViewportView(command);        result.setColumns(20);        result.setRows(5);        jScrollPane2.setViewportView(result);        jLabel1.setFont(new java.awt.Font("新宋体", 0, 12)); // NOI18N        jLabel1.setText("请输入命令");        jLabel2.setText("以下是结果");        start.setText("执行");        start.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                startActionPerformed(evt);            }        });        history.setColumns(20);        history.setRows(5);        jScrollPane3.setViewportView(history);        jLabel3.setText("历史记录");        jMenu1.setText("文件");        open.setText("打开文件");        open.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                openActionPerformed(evt);            }        });        jMenu1.add(open);        jMenuBar1.add(jMenu1);        jMenu2.setText("操作");        jMenuBar1.add(jMenu2);        setJMenuBar(jMenuBar1);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()                        .addGap(440, 440, 440)                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE))                    .addGroup(layout.createSequentialGroup()                        .addContainerGap()                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)                        .addGap(18, 18, 18)                        .addComponent(start, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addGroup(layout.createSequentialGroup()                        .addGap(169, 169, 169)                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 311, Short.MAX_VALUE)                        .addComponent(jLabel3)                        .addGap(152, 152, 152)))                .addGap(17, 17, 17))            .addGroup(layout.createSequentialGroup()                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(391, Short.MAX_VALUE))            .addGroup(layout.createSequentialGroup()                .addGap(290, 290, 290)                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(328, Short.MAX_VALUE))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(layout.createSequentialGroup()                        .addContainerGap()                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addGap(10, 10, 10)                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addGap(18, 18, 18)                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                            .addComponent(jLabel3)                            .addComponent(jLabel2)))                    .addGroup(layout.createSequentialGroup()                        .addGap(100, 100, 100)                        .addComponent(start)))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE))                .addContainerGap())        );        pack();    }// </editor-fold>//GEN-END:initComponentspublic void init() throws Exception{    APIManager.open();}public void close() throws Exception{    APIManager.close(history.getText());}public void start(String command) throws Exception {    ArrayList<String> commands=Interpreter.engine(command);    for(int i=0;i<commands.size();i++)    {        try        {            Interpreter.dispatchInstr(commands.get(i));        }        catch(OperationInfo op)        {            result.append(op.toString()+"\n");            //op.printStackTrace();        }catch(Success suc)        {            result.append(suc.toString()+"\n");            //suc.printStackTrace();        }catch(Quit q)        {            quit();        }        catch(Exception ex)        {            ex.printStackTrace();        }        result.append("===================================================\n");    }    }private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed// TODO add your handling code here:    String com=command.getText();    command.setText("");    history.append(com+"\n");    try     {        start(com);    } catch (Exception ex)     {       ex.printStackTrace();    }   }//GEN-LAST:event_startActionPerformedprivate void quit() throws Exception{    close();    System.exit(0);}private void openActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openActionPerformed// TODO add your handling code here    JFileChooser chooser=new JFileChooser();    int target=chooser.showOpenDialog(this);        if(target==JFileChooser.APPROVE_OPTION)    {        try        {            command.setText("");            File file=chooser.getSelectedFile();            FileInputStream fis=new FileInputStream(file);            Reader r=new InputStreamReader(fis);            BufferedReader br=new BufferedReader(r);            String data=null;            while((data=br.readLine())!=null)            {                command.append(data+"\n");            }        }catch(Exception ex)        {            ex.printStackTrace();        }    }}//GEN-LAST:event_openActionPerformedprivate void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing        try {// TODO add your handling code here:            close();        } catch (Exception ex) {//GEN-LAST:event_formWindowClosing            ex.printStackTrace();        }}    /**    * @param args the command line arguments    */    public static void main(String args[]) {        try {            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());        } catch (Exception ex) {            ex.printStackTrace();        }        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new GUI().setVisible(true);            }        });    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JTextArea command;    private javax.swing.JTextArea history;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JMenu jMenu1;    private javax.swing.JMenu jMenu2;    private javax.swing.JMenuBar jMenuBar1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JScrollPane jScrollPane3;    private javax.swing.JMenuItem open;    private javax.swing.JTextArea result;    private javax.swing.JButton start;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

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