|
package com.renxing.r0040_frameactiveevent;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
//小的练习
/**
*
*
* 讲学过的知识巩固下
* 在图形界面的
* 支持下 按下一个按钮讲磁盘中的内容显示出来!
* OK!
*
*
*
*/
public class FristDemo
{
public static void main(String[] args)
{
final Frame f=new Frame("abc");
f.setSize(200, 400);
f.setLayout(new FlowLayout());
f.setBackground(Color.blue);
Button b1=new Button("转到");
final TextField tf=new TextField(20);
final TextArea ta=new TextArea(20,75);
f.add(tf);
f.add(b1);
f.add(ta);
//添加监听事件
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
File file=new File(tf.getText());
String [] str=file.list();
for(int i=0;i<str.length;i++)
{
ta.append(str);
ta.append("\n");
}
}
});
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setVisible(true);
}
} |
|