need help with moving objects
well i've been assigned to make a simple java game but im already having trouble
.. i need to get something to move across the screen. I'm trying to get a rectangle to go across the top portion of the application. ofc I've youtubed and everything but i still get this smudge across the top of the screen when i do the fillRet ; when i do drawRect i get a bunch of lines spaced across. In case your curious of what im trying to make, i will be attempting to make a game sorta like fruit ninja. Much much simpler of course. Currently i just need to get an object to move :L Once i do that ill add pictures mouse stuff etc..Here's the code.
.. i need to get something to move across the screen. I'm trying to get a rectangle to go across the top portion of the application. ofc I've youtubed and everything but i still get this smudge across the top of the screen when i do the fillRet ; when i do drawRect i get a bunch of lines spaced across. In case your curious of what im trying to make, i will be attempting to make a game sorta like fruit ninja. Much much simpler of course. Currently i just need to get an object to move :L Once i do that ill add pictures mouse stuff etc..Here's the code.Code:
package gameapplication; import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import javax.swing.*; import java.awt.event.ActionListener; import javax.swing.Timer; @SuppressWarnings("serial") public class gameapp1 extends JFrame implements ActionListener{ Timer tm = new Timer(5,this); int x =0, velX=2; public gameapp1 (){ setSize(800,850); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable(true); setVisible(true); } public void paint(Graphics g){ g.setColor(Color.RED); g.drawRect(x, 57, 90, 30); tm.start(); } public void actionPerformed(ActionEvent e){ x = x + velX; repaint();} public static void main(String[] args) { gameapp1 gm = new gameapp1(); }}