我的教训是更改JFrame的setTitle方法,使其允许整数作为参数。怎么做?我必须重载该方法,对吧?我在 setTitle 方法中尝试的任何操作都会导致堆栈溢出。
import javax.swing.*;
public class MyFrame extends JFrame
{
MyFrame()
{
super();
setSize(400, 400); // Standard initial size
setVisible(true);
setDefaultCloseOperation(MyFrame.EXIT_ON_CLOSE);
}
MyFrame(int size)
{
this();
setSize(size, size);
}
public void setTitle(int title)
{
}
}
public class MainClass
{
public static void main(String[] args)
{
MyFrame frame = new MyFrame();
frame.setTitle(1000);
}
}
最佳答案
方法 setTitle
来自 JFrames API
public void setTitle(String title)
Sets the title for this frame to the specified string.
然后 frame.setTitle("1000");
就可以了
关于java - 将 JFrame setTitle(String) 重载为 setTitle(int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657401/