有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

通过十六进制改变swing Java Gui颜色

public class Game implements ActionListener {

    public static Game game ;
    public static Render render ;
    JFrame frame = new JFrame("Game");
    Timer timer = new Timer(25,this);
    public Game(){
        render = new Render();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Dimension windowSize = frame.getSize();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Point centerPoint = ge.getCenterPoint();

        int dx = centerPoint.x - windowSize.width / 2;
        int dy = centerPoint.y - windowSize.height / 2;    
        frame.setLocation(dx, dy);
        frame.add(render);
        timer.start();
        frame.setVisible(true);


    }

    public static void main(String[] args){
        game = new Game();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        render.repaint();

    }

}

public class Render extends JPanel{

    public static int i = 166673;
    protected void paintComponent(Graphics g){
        super.paintComponent(g);
        g.setColor(new Color(i));
        g.fillRect(0, 0,300,300);
        i += 10;
    }

}

我正在尝试制作一个每秒钟都会改变颜色的程序,或者我制作了一个计时器,现在我的程序可以工作了,但它以蓝色开始,等等。我开始它作为一个十六进制数字,如1666073一些绿色。它开始变蓝了,但又变蓝了我不知道为什么?。很抱歉打扰你。谢谢你的帮助


共 (0) 个答案