黑马程序员技术交流社区
标题:
GUI dialog程序问题求助
[打印本页]
作者:
莫运飞
时间:
2012-4-23 10:36
标题:
GUI dialog程序问题求助
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();
}
}
复制代码
作者:
莫运飞
时间:
2012-4-23 10:38
上面发得不好 我再发一次。红色部分报错
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);
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();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2