zoukankan      html  css  js  c++  java
  • 制作一个Frame界面显示盘符的东西

    import java.awt.BorderLayout;
    
    
    public class JFramedemo extends JFrame {
    
    	protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
    	private JPanel contentPane;
    	private JTextField textField;
    	private JScrollPane scrollPane;
    	private JTextArea textArea;
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					JFramedemo frame = new JFramedemo();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	/**
    	 * Create the frame.
    	 */
    	public JFramedemo() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 656, 433);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
    		contentPane.setLayout(null);
    		
    		textField = new JTextField();
    		textField.addKeyListener(new KeyAdapter() {
    			@Override
    			public void keyPressed(KeyEvent e) {
    				if(e.getKeyCode() == KeyEvent.VK_ENTER)
    				{
    					showdir();
    				}
    			}
    		});
    		textField.setBounds(54, 10, 344, 27);
    		textField.setFont(new Font("宋体", Font.PLAIN, 18));
    		contentPane.add(textField);
    		textField.setColumns(30);
    		
    		JButton btnNewButton = new JButton("转到");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				showdir();
    			}
    			
    		});
    		btnNewButton.setBounds(403, 10, 113, 27);
    		contentPane.add(btnNewButton);
    		
    		scrollPane = new JScrollPane();
    		scrollPane.setBounds(54, 50, 462, 323);
    		contentPane.add(scrollPane);
    		
    		textArea = new JTextArea();
    		scrollPane.setViewportView(textArea);
    	}
    
    	public void showdir() {
    		String str = textField.getText();
    		File file = new File(str);
    		if(file.exists() && file.isDirectory())
    		{
    			textArea.setText("");
    			File file2[] = file.listFiles();
    			for(File file3 : file2)
    			{
    				textArea.append(file3.getName() + LINE_SEPARATOR);
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    Wordpress 所有hoor列表
    Redis的PHP操作手册(转)
    thinkphp pathinfo nginx 无法加载模块:Index
    gitlab 创建SSH Keys 报500错
    在docker 中配置hadoop1.2.1 cluser
    docker 配置文件引发的问题
    shell在一个大文件找出想要的一段字符串操作技巧
    php关于金额比较引发的问题(转)
    mac 终端乱码
    Swoole笔记(二)
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11854389.html
Copyright © 2011-2022 走看看