请各位前辈帮小弟我看一个程序!多谢啦
请各位前辈帮我看一个程序!谢谢啦
------解决思路----------------------
第一个参数解释:
owner: the owner of the dialog or null if this dialog has no owner
布局对象是不能持有窗口的,而且我也没找到你外围类里有这么一个布局对象
改成MyWindowDemo.this
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class MyWindowDemo extends Frame{
private Button button;
private TextField textField;
private TextArea textArea;
private String str;
public MyWindowDemo(String title){
super(title);
button=new Button("转到");
textField=new TextField(30);
textArea=new TextArea(30,50);
setLayout(new FlowLayout());
add(textField);
add(button);
add(textArea);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
button.addActionListener(new ActionListener(){
/*
public void actionPerformed(ActionEvent e){
textArea.setText("");
str=textField.getText();
//textArea.append(str);
textArea.setText(str);
}
*/
public void actionPerformed(ActionEvent e){
textArea.setText("");
str=textField.getText();
File dirPath=new File(str);
if(dirPath.exists()&&dirPath.isDirectory()){
String[] names=dirPath.list();
for(int x=0;x<names.length;x++){
textArea.append(names[x]+"\r\n");
}
}
else{
Dialog dialog=new Dialog(BorderLayout.this,"提示信息",true);
Button okButton=new Button("确定");
Label label=new Label();
label.setText("对不起,你输入的信息:"+str+"有误,请重新输入");
dialog.setLayout(new FlowLayout());
dialog.add(okButton);
dialog.add(label);
setBounds(200,200,250,120);
setVisible(true);
}
}
});
setBounds(200,100,500,400);
setVisible(true);
}
public static void main(String[] args){
new MyWindowDemo("hello java");
}
}
------解决思路----------------------
第一个参数解释:
owner: the owner of the dialog or null if this dialog has no owner
布局对象是不能持有窗口的,而且我也没找到你外围类里有这么一个布局对象
改成MyWindowDemo.this