代码如下:(红色字体为发生错误处)
import java.awt.*;
import java.awt.event.*;
public class DialogDemo extends Frame implements ActionListener{
int row=8,col=40;
Panel p1=new Panel();
Panel p2=new Panel();
TextArea ta=new TextArea("row"+row+" col"+col+col,row,col);
Button exit=new Button("Exit");
Button dialog=new Button("Dialog");
DialogDemo(){
SetTitle("SuperDialog");
setSize(350,200);
add("Center",p1);
add("South",p2);
p1.add(ta);
p2.add(exit);
p2.add(dialog);
exit.addActionListener(this);
dialog.addActionListener(this);
setVisible(true);
}
public static void main(String[] args){
new DialogDemo();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==exit)
System.exit(0);
else{
MyDialog dlg=new MyDialog(this,true);
dlg.show();
}
}
class MyDialog extends Dialog implements ActionListener{
Label label1=new Label("Please input row");
Label label2=new Label("Please input column");
TextField rows=new TextField(50);
TextField column=new TextField(50);
Button ok=new Button("OK");
Button cancel=new Button("Cancel");
MyDialog(DialogDemo parent,boolean modal){
super(parent,modal);
setTitle("User-Defined Dialog");
setSize(260,140);
setResizeable(true);
setLayout(null);
add(label1);
add(label2);
label1.setBounds(50, 30, 120, 20);
label2.setBounds(50, 30, 120, 20);
add(rows);
add(column);
rows.setText(Integer.toString(ta.getRows()));
column.setText(Integer.toString(ta.getColumns()));
rows.setBounds(180, 30, 80, 20);
column.setBounds(180, 60, 80, 20);
add(ok);
add(cancel);
ok.setBounds(60, 80, 60, 25);
cancel.setBounds(140, 80, 60, 25);
ok.addActionListener(this);
cancel.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==ok){
int row=Integer.parseInt(rows.getText());
int col=Integer.parseInt(column.getText());
ta.setRows(row);
ta.setColumns(col);
ta.setText("row:"+row+" col:"+col);
}
dispose() ;
}
}
}
发生错误的原因为:The method SetTitle(String) is undefined for the type DialogDemo;
The method setResizeable(boolean) is undefined for the type DialogDemo.MyDialog;