写了一个关于JAVA中AWT的程序 不知道哪有问题 。 请大家帮我看看,谢谢
就是点开对话框时往里面输入文字然后点set或者按回车时没有反映不知道怎么回事请大家帮我看看谢谢了。。packageEventPackage;importjava.awt....
就是点开对话框时 往里面输入文字 然后点set或者按回车时 没有反映 不知道怎么回事 请大家帮我看看 谢谢了。。
package EventPackage;
import java.awt.*;
import java.awt.event.*;
public class DialogWindow extends Frame implements ActionListener{
private SimpleDialog dialog;
private TextArea textArea;//文本区
String newline;
public DialogWindow(){
textArea=new TextArea(5,40);
textArea.setEditable(false);
add("Center",textArea);//??
Button button=new Button ("打开对话框");
button.addActionListener(this);
add("South",button);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
newline = System.getProperty("line.separator");//获得分隔符
}
public void actionPerformed(ActionEvent event){//按钮监听器
if (dialog==null){
dialog=new SimpleDialog(this,"A Simple Dialog");
}
dialog.setVisible(true);
}
//设置文本区textArea的内容
public void setText(String text){
textArea.append(text+newline);
}
public static void main(String[] args) {
DialogWindow window=new DialogWindow();
window.setTitle("DialogWindow Application");
window.pack();
window.setVisible(true);
}
}
//实现一个简单对话框的类
class SimpleDialog extends Dialog implements ActionListener{
TextField field;//文本域
DialogWindow parent;
Button setButton;
public SimpleDialog(Frame dw,String title){
super(dw,title,false);
parent=(DialogWindow)dw;//强制转换
Panel p1=new Panel();
Label label=new Label("请随意输入文字:");
p1.add(label);
field = new TextField(20);
field.addActionListener(this);//又设置了一个监听器
p1.add(field);
add("Center",p1);
//创建两个按钮
Panel p2=new Panel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));//???
Button b=new Button("Cancel");
b.addActionListener(this);//又设置了一个监听器
setButton=new Button("Set");
p2.add(b);
p2.add(setButton);
add("South",p2);
pack();//将对话框设置为最佳的大小
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event){
Object source=event.getSource();//??
if((source==setButton)||(source==field)){
parent.setText(field.getText());
}
field.selectAll();//文本域
setVisible(true);
}
} 展开
package EventPackage;
import java.awt.*;
import java.awt.event.*;
public class DialogWindow extends Frame implements ActionListener{
private SimpleDialog dialog;
private TextArea textArea;//文本区
String newline;
public DialogWindow(){
textArea=new TextArea(5,40);
textArea.setEditable(false);
add("Center",textArea);//??
Button button=new Button ("打开对话框");
button.addActionListener(this);
add("South",button);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
newline = System.getProperty("line.separator");//获得分隔符
}
public void actionPerformed(ActionEvent event){//按钮监听器
if (dialog==null){
dialog=new SimpleDialog(this,"A Simple Dialog");
}
dialog.setVisible(true);
}
//设置文本区textArea的内容
public void setText(String text){
textArea.append(text+newline);
}
public static void main(String[] args) {
DialogWindow window=new DialogWindow();
window.setTitle("DialogWindow Application");
window.pack();
window.setVisible(true);
}
}
//实现一个简单对话框的类
class SimpleDialog extends Dialog implements ActionListener{
TextField field;//文本域
DialogWindow parent;
Button setButton;
public SimpleDialog(Frame dw,String title){
super(dw,title,false);
parent=(DialogWindow)dw;//强制转换
Panel p1=new Panel();
Label label=new Label("请随意输入文字:");
p1.add(label);
field = new TextField(20);
field.addActionListener(this);//又设置了一个监听器
p1.add(field);
add("Center",p1);
//创建两个按钮
Panel p2=new Panel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));//???
Button b=new Button("Cancel");
b.addActionListener(this);//又设置了一个监听器
setButton=new Button("Set");
p2.add(b);
p2.add(setButton);
add("South",p2);
pack();//将对话框设置为最佳的大小
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event){
Object source=event.getSource();//??
if((source==setButton)||(source==field)){
parent.setText(field.getText());
}
field.selectAll();//文本域
setVisible(true);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询