简体   繁体   English

Java fillOval将不会填充窗口

[英]Java fillOval will not fill window

** Please feel free to provide feedback on the process flow as well. **请随时提供有关流程的反馈。 There is probably a better way to complete what I'm doing, I'm just not aware of it. 可能有更好的方法来完成我正在做的事情,我只是不知道而已。

I have a Game class which extends a JPanel. 我有一个Game类,它扩展了JPanel。 In the paintComponent() method it renders a different class based on the state of the game (menus). paintComponent()方法中,它根据游戏状态(菜单)呈现不同的类。 Only the welcome screen paints across the entire window. 仅欢迎屏幕在整个窗口上绘制。 The others don't fill the window, even if I manually assign the coordinates of (0, 0, 1000, 1000) on a 640x480 window. 即使我在640x480窗口上手动指定(0,0,1000,1000)的坐标,其他窗口也不会填满窗口。

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (state == State.WELCOME) {

        welcome.render(g);

    } else if (state == State.SELECTPOSITION) {

        selectPosition.render(g);

    } else if (state == State.SELECTSCENARIO) {

        selectScenario.render(g);
...

More states are listed with the same logic are listed under the selectScenario() line. selectScenario()行下列出了具有相同逻辑的更多状态。

The render() methods of the first 2 are listed below: 下面列出了前两个的render()方法:

welcome.render(g)

public void render(Graphics g) {
    g.setColor(Color.red);
    g.fillRect(0, 0, 640, 480);
    g.setColor(Color.white);
    g.drawString("Welcome", 50, 150);
}


selectPosition.render(g)

public void render(Graphics g) {
    g.setColor(Color.blue);
    g.fillRect(0, 0, 1000, 1000);
}

There is a red line approximately 50px high at the bottom of the screen during the SelectPosition screen. 在SelectPosition屏幕期间,屏幕底部有一条大约50像素高的红线。

Please let me know if you need more information. 如果您需要更多信息,请告诉我。 I attempted to share only relevant lines. 我试图只分享相关的内容。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

We are unfamiliar with much of your code, your logic, and your program's structure, and you may wish to create and post an sscce to let us actually experience for ourselves what you are experiencing. 我们不熟悉您的许多代码,逻辑和程序的结构,并且您可能希望创建并发布一个scsc,以使我们自己实际体验您所遇到的事情。 But it sounds to me as if what you really want to do is swap views based on state such as can be accomplished using a CardLayout. 但是在我看来,您真正想要做的就是根据状态交换视图,例如可以使用CardLayout来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM