📄 displayfile.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
public class DisplayFile extends JApplet implements ActionListener {
public JTextArea theText=new JTextArea();
public String name=new String();
// public String name1=new String();
public void init() {
this.setSize(300, 200);
Container contentPane = getContentPane();
contentPane.setBackground(Color.WHITE);
contentPane.setLayout(new BorderLayout());
JButton DisplayButton = new JButton("显示文件");
DisplayButton.addActionListener(this);
contentPane.add(DisplayButton,BorderLayout.SOUTH);
theText=new JTextArea(30,40);
theText.setEditable(false);
theText.setBackground(Color.white);
contentPane.add(theText,BorderLayout.NORTH);
try {
GetFile(".");
} catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
Container contentPane = getContentPane();
if (e.getActionCommand().equals("显示文件"))
theText.append(name);
else
System.out.println("Error in Button interface");
}
public void GetFile(String strPath) throws Exception {
try {
File file = new File(strPath);
File[] tempFile = file.listFiles();
for(int i = 0;i<tempFile.length;i++)
{
if(tempFile[i].isFile())
{
name=tempFile[i].getName()+ "\r\n"+ name;
}
}
}
catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -