为什么 在Dialog中add 一个Lable,但运行的时候并没有显示? 求大神
import java.awt.Button;
import java.awt.Dialog;
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.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
public class MyFrame
{
private Frame frame ;
private Button butCount;
private Button butClear;
private TextField tf ;
private TextArea ta ;
private TextField answer;
public void init()
{
//定义组建
frame = new Frame("统计代码行数软件--by Owen");
butCount = new Button("统计");
butClear = new Button("结果清零");
tf = new TextField("请输入要计算的文件夹路径" , 60);
tf.selectAll(); //设置将初始的"请输入要计算的文件夹路径"全选
ta = new TextArea(25 , 75);
answer = new TextField(40);
//向面板添加组建
frame.add(tf);
frame.add(butCount);
frame.add(butClear);
frame.add(ta);
frame.add(answer);
//设置面板
frame.setVisible(true);
frame.setBounds(300,100,630,500);
frame.setLayout(new FlowLayout());
//引入事件
eventFrame();
eventButton();
eventText();
}
//窗体事件
public void eventFrame()
{
//添加面板监听器
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
//按钮事件
public void eventButton()
{
//添加butCount监听器
butCount.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
action();
}
});
//添加butClear监听器
butClear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
Print.count = 0;
ta.setText("");
tf.setText("");
answer.setText("");
}
});
}
//文本事件
public void eventText()
{
tf.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
action();
}
});
}
//操作部分
private void action()
{
String address = tf.getText();
//健壮性检验
File check = new File(address);
if( !(check.exists() && check.isDirectory() ))
popDialog(address);
String[] files = Print.traDir(address);
for(int i=0 ; i<files.length ; i++)
{
ta.append(files[i]);
}
ta.append("\r\n");
ta.append("\r\n");
ta.append("----------------------------------------------");
ta.append("\r\n");
ta.append("\r\n");
int count = Print.count;
answer.setText("结果: "+count+" 行代码");
}
//弹出对话框------------------这里没有弹出------------------?????????????????????
private void popDialog(String address)
{
//定义弹出窗口口
Dialog wrongDialog = new Dialog(frame,"地址错误提示", false);
Label wrongLabel = new Label();
Button wrongButton = new Button("确定");
wrongDialog.add(wrongLabel);
wrongDialog.add(wrongButton);
wrongDialog.setBounds(320 , 250 , 600 , 150);
wrongDialog.setLayout(new FlowLayout());
wrongDialog.setVisible(true);
String info = "输入地址 \" "+address+" \"有误,请重新输入";
wrongLabel.setText(info);
popEvent(wrongDialog ,wrongLabel ,wrongButton);
}
//弹出对话框 --监听器
private void popEvent(Dialog wrongDialog ,Label wrongLabel ,Button wrongButton)
{
wrongDialog.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
wrongDialog.setVisible(false);
}
});
wrongButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
wrongDialog.setVisible(false);
}
});
}
}