A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 途中ms前进 中级黑马   /  2015-6-1 17:50  /  299 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.awt.*;
import java.awt.event.*;
import java.io.*;
class FrameDemo
{        private Frame f;
private Button b;
private TextField tf;
private TextArea ta;
private Dialog d;
private Label l;
private Button ok;
FrameDemo(){
init();
}
public void init(){
f=new Frame();
f.setBounds(500,200,300,200);
f.setLayout(new FlowLayout());
b=new Button("转到");
tf=new TextField(50);
ta=new TextArea(20,60);
d=new Dialog(f,"提示信息_self",true);
d.setBounds(400,200,260,170);
d.setLayout(new FlowLayout());
l=new Label();
ok=new Button("确定");
d.add(ok);
d.add(l);
f.add(b);
f.add(tf);
f.add(ta);
MyEvent();
f.setVisible(true);

}
private void MyEvent(){
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
d.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
d.setVisible(false);
}
});
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

ok.setVisible(true);
}
});


b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String dirPath=tf.getText();
File f=new File(dirPath);
if(f.exists()&&f.isDirectory()){
ta.setText("");
String[] names=f.list();
for(String name:names){
ta.append(name+"\r\n");

}
}
else{
String s="您输入信息错误,请重新输入或者换电脑";
l.setText(s);
d.setVisible(true);
}



}
});

}


        public static void main(String[] args)
        {
                new FrameDemo();
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马