你判断目录不存在的话,弹出一也对话框,也成一个封装类比较好,例如:
public class MyDialog {
private Frame frame;//框架
private Dialog dialog;//对话框
private Label info;//显示内容的
private Button OK;//确定按钮
private String path;//路径
public MyDialog(Frame frame,String path){
this.frame=frame;
this.path=path;
MyFrame();
}
public void MyFrame(){//dialog上的组件的集合
dialog =new Dialog(frame,"提示信息",true);
dialog.setLayout(new FlowLayout());//设置布局为流水式
//dialog.setBounds(300, 100, 200, 150);
dialog.setLocation(300, 200);
info =new Label();
info.setText("您输入的路径:"+path+"不正确,请重新输入");
String textPath=info.getText();
byte [] text=textPath.getBytes();
dialog.setSize(text.length*7,100);
dialog.add(info);
OK =new Button("确定");
dialog.add(OK);
MyEvent();
dialog.setVisible(true);
}
public void MyEvent(){//监听器的触发事件
dialog.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
dialog.setVisible(false);
}
});
OK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
});
}
}
在判断的时候实例此对象就可以 newMyDialog(框架对象,获取的路径);
希望对你有帮助!
|