gpt4 book ai didi

java - setTitle 方法中的异常

转载 作者:行者123 更新时间:2023-12-01 19:11:06 27 4
gpt4 key购买 nike

我目前正在开发自己的扫雷器。在重写 setTitle 方法时,我遇到以下问题。

//InfoDisplayer is inner class of class MenuActionListener
class InfoDisplayer extends JDialog{


JLabel info;
BorderLayout infoBorderLayout = new BorderLayout();

public InfoDisplayer(JFrame ownerFrame){
super(ownerFrame,true); //Always modal is set to be true....
info = new JLabel();
setFocusable(false);
setSize(300,400);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLayout(infoBorderLayout);
add(info,BorderLayout.SOUTH);
setVisible(true);
}

void setInfo(JLabel info){
this.info = info;
}

public void setTitle(String title){
setTitle(title);
}
}

if ((event.getActionCommand()).equals("HowToPlay")){
InfoDisplayer instructionsDisplay = new InfoDisplayer(gUIManagerFrame);
//gUIManagerFrame is an object of its outer class,MenuActionListener
instructionsDisplay.setTitle("INSTRUCTIONS");
instructionsDisplay.setInfo(new JLabel("<html><h1><B>INSTRUCTIONS</B></h1></html>"));

}
else{// if about is clicked!!
InfoDisplayer aboutDisplay = new InfoDisplayer(gUIManagerFrame);
aboutDisplay.setTitle("MineSweeper v0.1");
aboutDisplay.setInfo(new JLabel("<html><h1><B>MineSweeperv1.0</B></h1> </html>"));

}
}

setTitle 和 setInfo 方法不起作用。除此之外,setTitle 方法还会产生异常。

at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338) at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338) at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338) at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338) at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338) at graphicalUserInterface.BoardMenuBar$MenuItemsActionListener$1InfoDisplayer.setTitle(GUIManager.java:338)

我也很想知道持续异常生成的原因。

编辑:抱歉,我没有查看递归调用。这是我的错误。现在我已经改正了。

最佳答案

public void setTitle(String  title){
setTitle(title);
}

这就是自称——递归。你想要

public void setTitle(String  title){
super.setTitle(title);
}

关于java - setTitle 方法中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8388540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com