zoukankan      html  css  js  c++  java
  • GUI_文件管理器(练习)

    实现想windows下的文件管理器(主要是监听器里的方法,showDir()写法)

    package com.mywindow.test;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.io.File;
    
    import javax.swing.JButton;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.WindowConstants;
    
    
    /**
    * This code was edited or generated using CloudGarden's Jigloo
    * SWT/Swing GUI Builder, which is free for non-commercial
    * use. If Jigloo is being used commercially (ie, by a corporation,
    * company or business for any purpose whatever) then you
    * should purchase a license for each developer using Jigloo.
    * Please visit www.cloudgarden.com for details.
    * Use of Jigloo implies acceptance of these licensing terms.
    * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
    * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
    * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
    */
    public class NewJFrame extends javax.swing.JFrame {
        private static final String LINE_SEPARATOR = System.getProperty("line.separator");
        private JTextField jTextField1;
        private JButton jButton1;
        private JTextArea jTextArea1;
    
        /**
        * Auto-generated main method to display this JFrame
        */
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    NewJFrame inst = new NewJFrame();
                    inst.setLocationRelativeTo(null);
                    inst.setVisible(true);
                }
            });
        }
        
        public NewJFrame() {
            super();
            initGUI();
        }
        
        private void initGUI() {
            try {
                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                getContentPane().setLayout(null);
                {
                    jTextField1 = new JTextField();
                    getContentPane().add(jTextField1, "Center");
                    jTextField1.setBounds(12, 27, 268, 27);
                    jTextField1.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            jTextField1KeyPressed(evt);
                        }
                    });
                }
                {
                    jButton1 = new JButton();
                    getContentPane().add(jButton1);
                    jButton1.setText("u8f6cu5230");
                    jButton1.setBounds(292, 28, 76, 24);
                    jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jTextArea1 = new JTextArea();
                    getContentPane().add(jTextArea1);
                    jTextArea1.setBounds(12, 65, 356, 185);
                }
                pack();
                setSize(400, 300);
            } catch (Exception e) {
                //add your error handling code here
                e.printStackTrace();
            }
        }
        
        //Button的活动监听器
        private void jButton1ActionPerformed(ActionEvent evt) {
            showDir();
        }
    
        private void showDir() {
            /*
             * 通过点击按钮获取文本框目录
             * 将目录中的内容显示到文本区域中
             * */
            String dir_str = jTextField1.getText();
            
            File dir = new File(dir_str);
            
            if(dir.exists() && dir.isDirectory()){
                jTextArea1.setText("");
                
                String[] names = dir.list();
                
                for(String name : names){
                    jTextArea1.append(name+LINE_SEPARATOR);
                }
            }
        }
        
        private void jTextField1KeyPressed(KeyEvent evt) {
            
            if(evt.getKeyCode()==KeyEvent.VK_ENTER){
                showDir();
            }
                
        }
    
    }
  • 相关阅读:
    SqlServer存储过程
    SQL Server :DBLINK创建及使用
    jQuery控制TR的显示隐藏
    JAVA------22.git导出项目,启动项目
    JAVA------21.String转时间,并向前推进一天
    JAVA------20.经纬度转换省市区
    JAVA------20.图片中插文字和图片
    JAVA------19.生成二维码并插入logo
    JAVA------18.excel导出
    JAVA------17.charles(青花瓷)抓包工具,适用安卓
  • 原文地址:https://www.cnblogs.com/LO-ME/p/3606237.html
Copyright © 2011-2022 走看看