I was following http://www.youtube.com/watch?v=4T3WJEH7zrc tutorial and followed it through, it did remove the lines (double buffered it) but it also inverted my image, so the ball is white and background is black, which stops me from getting a coloured background.
package javagame; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JFrame; public class JavaGame extends JFrame { int x, y; private Image dbImage; private Graphics dbg; public class AL extends KeyAdapter { public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if(keyCode == e.VK_LEFT){ if(x <= 0) x = 0; else x+= -5; } if(keyCode == e.VK_RIGHT){ if(x >= 485) x = 485; else x+= +5; } if(keyCode == e.VK_UP){ if(y <= 20) y = 20; else y+= -5; } if(keyCode == e.VK_DOWN){ if(y >= 485) y = 485; y+= +5; } } public void keyReleased(KeyEvent e) { } } public JavaGame() { addKeyListener(new AL()); setTitle("Game"); setSize(250, 250); setResizable(false); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBackground(Color.GREEN); x = 15; y = 15; } public void paint(Graphics g) { dbImage = createImage(getWidth(), getHeight()); dbg = dbImage.getGraphics(); paintComponent(dbg); g.drawImage(dbImage, 0, 0, this); } public void paintComponent(Graphics g) { g.fillOval(x, y, 15, 15); repaint(); } public static void main(String[] args) { new JavaGame(); } }
I just want to know if anyone can help me. It goes back to normal if I remove public void paint. please help. Thanks in advance.
Bye.