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);
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    Android 布局中 如何使控件居中
    VGA, QVGA, HVGA, WVGA, FWVGA和iPhone显示分辨率
    [转+整理] Android 分辨率,密度,像素单位说明
    多线程的知识点总结
    集合的相关信息
    spring cloud详解
    iostat实时监控磁盘util
    Jenkins安装过程
    hdfs的block为什么设置成128M
    shell变量自增的几种方式
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11854389.html
Copyright © 2011-2022 走看看