通过HEX改变Java Gui颜色

时间:2017-10-24 21:19:13

标签: java swing user-interface

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;
    }

}

我正在尝试制作一个程序,可以在每一秒钟改变颜色或我制作一个Timer的东西,现在我的程序可以运行,但它以蓝色开始等等。我将其作为十六进制到十二进制数,例如1666073一些绿色。它开始但又变成蓝色我不知道为什么?抱歉打扰你。谢谢你的帮助。

0 个答案:

没有答案