小编Eam*_*mes的帖子

程序没有正确绘制屏幕

我一直在构建一个简短的程序,基本上在JPanel上绘制一个太空船,并听取指示程序射击子弹的键.问题是它甚至没有在屏幕上绘制宇宙飞船或子弹.我还怀疑KeyBindings可能无法工作,因为这是以前的问题(我可能已经或可能没有修复),但手头的主要问题仍然是我的屏幕没有被绘制.这是我的代码:

public enum Direction {
    LEFT, RIGHT, SPACE
}

import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame frame;

        Ship s1;
        Shoot shoot;

        // Set the frame up
        frame = new JFrame();
        frame.setSize(400, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setVisible(true);

        // Get some more necessary objects
        s1 = new Ship();
        shoot = new Shoot(s1);
        frame.getContentPane().add(shoot);
        s1.setShoot(shoot);

        // Threads
        Thread ship = new Thread(s1);
        ship.start();
    }
}

import java.awt.Graphics;
import java.awt.event.KeyEvent;

import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JPanel;
import …
Run Code Online (Sandbox Code Playgroud)

java null swing key-bindings paintcomponent

0
推荐指数
1
解决办法
102
查看次数

标签 统计

java ×1

key-bindings ×1

null ×1

paintcomponent ×1

swing ×1