一道java练习题,帮帮忙!
import java.awt.*;
import java.awt.event.*;
class MyDialog extends Dialog implements ActionListener
{ Label La1,La2;int message=1;
TextField text1,text2;static int a,b;
MyDialog(Frame f,String s,boolean b)
{ super(f,s,b);
La1=new Label("Width:"); text1=new TextField(4);
text2=new TextField(4);
La2=new Label("Height:");
text1.addActionListener(this);
text2.addActionListener(this);
add(La1);
add(text1);
add(La2);
add(text2);
setBounds(30,30,60,200);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{setVisible(false);message=0;}
});
}
public int getMessage()
{return message;}
public void actionPerformed(ActionEvent e)
{
a=Integer.parseInt(text1.getText());
b=Integer.parseInt(text2.getText());
}
}
class Win extends Frame implements ActionListener
{
TextArea text;MyDialog dialog;Button b;
Win(String s)
{ setTitle(s);
text=new TextArea(22,22);
b=new Button("设置");
b.addActionListener(this);dialog=new MyDialog(this,"对话框",true);
add(b);add(text);
setVisible(true);
setLayout(new FlowLayout());
setBounds(20,20,360,360);
validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}}) ;
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b){dialog.setVisible(true);}
if(dialog.getMessage()==0){dialog.setVisible(false);text.setSize(MyDialog.a,MyDialog.b);}
}
}
public class Examplej
{
public static void main(String args[])
{
new Win("对话窗口");}
}
------解决方案--------------------
问题是什么。。。。。崩溃中。。 我在报
空指针异常