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

      

  • 相关阅读:
    css换行
    <a>标签里的<img>标签点击虚线框
    iframe子页面调用父页面元素
    快捷键
    用css绘制三角形
    解决div被embed,object覆盖问题
    一些兼容问题
    兼容padding
    记一次用html2canvas将页面内容生成海报并保存图片到本地
    PUPPETEER安装遇到 ERROR:CHROMIUM REVISION IS NOT DOWNLOADED.的解决办法
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11854389.html
Copyright © 2011-2022 走看看