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;
}
}
I am trying to make a program that changes color in every second or something I made a Timer and now my program works but it starts with blue and so on. I am starting it as an Hex to Dec number such as 1666073 some greenish color. it starts but goes into blue again I don't know why?. Sorry to bother you. Thanks for the help.