Jump to content
  • Advertisement
Sign in to follow this  

Problem with Background

This topic is 2398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a class that is suppose to draw a red rectangle in a JPanel with and the background of the panel is suppose to be black here is my code

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;

public class View extends JFrame
private JPanel panel = new JPanel();
public void paint(Graphics g)
g.drawRect(20, 50, 100, 100);
public View()
setSize(640, 480);
panel.setSize(640, 480);

public static void main(String[] args)
View view = new View();


and here is what I get as a result there appears to be some glitch in the background

(this is a screen of the gui from my code not a minimized Eclipse)

and here is how it is without the paint method it does as it suppose to making a window with a black background

[attachment=7845:without paint method.PNG]

Is it something wrong with my code that it does like that or there is something wrong with my computer ?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!