我正在用Java编写这个游戏,我只是将基于java.awt的所有窗口相关代码重写为javax.swing.不久之后,我意识到事情现在有点复杂了,所以我做了一些研究,并找到了如何绘制东西,如何设置JFrame的大小等等.但由于某种原因,我的JFrame的大小总是超出我指定的尺寸10个像素.在这种情况下,我希望它是640 x 640像素.
这是我的代码:
package chrononaut;
import java.awt.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
@SuppressWarnings("serial")
public class GameJFrame extends JFrame
{
//Background color:
static Color bgrCol = new Color(12, 4, 64);
//Size:
final static int size = 640;
//The component that does the actual drawing:
static GameJComp drawingComp = new GameJComp();
//Constructor:
public GameJFrame()
{
//Calling super() and setting the title:
super("Chrononaut");
//Setting icon image:
try
{
Image icon = ImageIO.read(getClass().getResource("/icon/icon 1.png"));
setIconImage(icon);
}
catch (IOException e) {}
//make it …
Run Code Online (Sandbox Code Playgroud)