JAVA 关闭对话框 出错
publicclassTankClientextendsFrame{……MyTankDeadDialogmtdd=newMyTankDeadDialog(this,myT...
public class TankClient extends Frame {
……
MyTankDeadDialog mtdd = new MyTankDeadDialog(this, myTank, "死亡", true);
……
public void ClosedDialog()
{
mtdd.setVisible(false);
}
}
public class MyTankDeadDialog extends Dialog {
……
public MyTankDeadDialog(TankClient tc,Tank k, String title, boolean modal) {
super(tc, title, modal);
this.k = k;
……
btn1.addActionListener(new Monitor());
btn2.addActionListener(new Monitor());
……
}
class Monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == dp.btn1) {
//tc.BringToLife();
k.live = true;
k.life = k.fullLife;
tc.ClosedDialog();//这句*******************************
}
if(e.getSource() == dp.btn2) {
System.exit(0);
}
}
}
java.lang.NullPointerException!难道这样调用不能初始化吗?请问该如何修正?
在类 MyTankDeadDialog 中已经申明了 TankClient tc; 展开
……
MyTankDeadDialog mtdd = new MyTankDeadDialog(this, myTank, "死亡", true);
……
public void ClosedDialog()
{
mtdd.setVisible(false);
}
}
public class MyTankDeadDialog extends Dialog {
……
public MyTankDeadDialog(TankClient tc,Tank k, String title, boolean modal) {
super(tc, title, modal);
this.k = k;
……
btn1.addActionListener(new Monitor());
btn2.addActionListener(new Monitor());
……
}
class Monitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == dp.btn1) {
//tc.BringToLife();
k.live = true;
k.life = k.fullLife;
tc.ClosedDialog();//这句*******************************
}
if(e.getSource() == dp.btn2) {
System.exit(0);
}
}
}
java.lang.NullPointerException!难道这样调用不能初始化吗?请问该如何修正?
在类 MyTankDeadDialog 中已经申明了 TankClient tc; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询