您的位置:首页 > 产品设计 > UI/UE

黑马程序员 【】java学习之路——GUI开始简析三

2014-08-19 17:59 183 查看
-------
android培训、java培训、期待与您交流! ----------

需求:实现如下窗口,功能:能够转到相应的盘符下显示该盘内的内容

<span style="font-size:18px;">import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MyWindows
{
private Frame f;
private TextField tf;
private Button b ;
private TextArea ta;

MyWindows()
{
init();
}
private void init()
{
f = new Frame("我的窗口");
f.setBounds(300,100,600,500);
f.setLayout(new FlowLayout());

tf = new TextField(50);
b = new Button("转到");
ta = new TextArea(25,70);

f.add(tf);
f.add(b);
f.add(ta);

myEvent();
f.setVisible(true);
}

private void myEvent()
{

b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String dirPath = tf.getText();
File dir = new File(dirPath);
if (dir.exists() && dir.isDirectory())
{
ta.setText("");
String[] names = dir.list();
for(String name : names)
{
ta.append(name+"\r\n");
}
}
}
});
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main(String[] args)
{
new MyWindows();
}
}
</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: