Hi, i've started making a simple breakout game with java swing. This is just for fun and to learn more about java and swing. I got a frame and a panel and a mouse listener. I draw a paddle on the screen and it moves as the mouse moves. I also print out on motion the x value of the mouse.
I want a timer to move the ball. My timer is in the frame class and it works. right now its called every second and increments a variable z. with system.out.println, i can see z incrementing.
The problem is i'm tring to print out z in the drawing function on the screen ( same place x is printing) and it is allways 0. z is a variable on the frame object and panel object. in the frame class where the timer is i do panel.setz(z);.
i think i have two copies of my panel. breakoutpanel panel; is a class variable in the frame. in the constructor i do
the constructor is called twice. when i comment out frame.add(panel) its called once. so i guess my actual panel is a copy of my panel variable, and once i do frame.add(panel); i need to talk to that panel and my code with panel.setz(z); is communication with the panel i started with and coppied. How would i do this?