- package DIALOG;
- import java.awt.Button;
- import java.awt.FlowLayout;
- import java.awt.Frame;
- import java.awt.Label;
- import java.awt.TextArea;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- public class Dialog {
- private static Frame frame;
- private static TextField text;
- private static TextArea area;
- private static Button button,button1;
- private static Dialog dialog;
- private static Label label;
- public static void show(){
- frame=new Frame("First Windown");
- button=new Button("DIALOG");
- button1=new Button("我的按钮");
- text=new TextField(20);
- area=new TextArea(50, 0);
- dialog=new Dialog(frame,"错误信息",true<FONT color=red><FONT color=silver>);</FONT>//为什么这里会报错呢???
- </FONT>label=new Label();
- frame.add(button);
- frame.add(button1);
- frame.add(text);
- frame.add(area);
- frame.setVisible(true);
- frame.setBounds(300,200,500,500);
- frame.setLayout(new FlowLayout());
- button1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- System.out.println("关闭软件");
- System.exit(0);
- }
- });
- button.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- String dirpath=text.getText();
- File dir=new File(dirpath);
- if(dir.exists()&&dir.isDirectory()){
- area.setText("");
- String[] name=dir.list();
- for(String names :name){
- area.append(names+"\r\n");
- }
- }else{
- dialog.setVisible(true);
- }
- }
- });
- }
- protected static void setVisible(boolean b) {
- // TODO Auto-generated method stub
- }
- public static void main(String[] args) {
- show();
- }
- }
复制代码 |
|