hey all

I was watching a tutorial on java game development.In that video,the guy was making a window a on the screen,then making an oval,then moving it.

His code worked fine and i am 100% sure that my code is similar to his(i checked it a few times).
What my problem is that the window just display the image behind the window and not displays the blank screen.
for eg. i use netbeans IDE.When i run the program,he window appears on the top left corner of the screen but what it displays is the things behind it such as : "file","edit","view","navigate","run"(basically,al the components behind the window) etc.

package javaapplication1;

import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class JavaApplication1 extends JFrame{
int x,y;
    public class AL extends KeyAdapter{
        public void keyPressed(KeyEvent e){
            int keyCode = e.getKeyCode();
if(keyCode == e.VK_A){
if(keyCode == e.VK_D){
if(keyCode == e.VK_W){
if(keyCode == e.VK_S){

        public void KeyReleased(KeyEvent e){


    public JavaApplication1(){
        addKeyListener(new AL());
         setTitle("Java Game");

        x = 150;
        y = 150;
    public void paint(Graphics g){    

    public static void main(String[] args) {
        new JavaApplication1();


The ball is on the copied screen and is moving just fine.
Please i am really going insane due to this frustration.I googles it but could'nt find any solution.Now, this is the place where i rely the most.

Thanks to all.

You should not have a repaint() call in your paint() method. Also, you should really be overridding paintComponent() on a JPanel or something instead of paint() on a JFrame. If you really must override paint, make sure you call super.paint() first or other components in the frame won't render correctly.

This question has already been answered. Start a new discussion instead.