Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Problem with Background

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 PsionicTransvection   Members   

262
Like
0Likes
Like

Posted 22 March 2012 - 07:46 AM

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.setColor(Color.RED);
  g.drawRect(20, 50, 100, 100);
}
public View()
{
  setSize(640, 480);
  setResizable(true);
  setVisible(true);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setLocationRelativeTo(null);
  setBackground(Color.BLACK);
  panel.setSize(640, 480);
  panel.setBackground(Color.BLACK);
  panel.paint(null);
  this.add(panel);
}

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

WTF.PNG
(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

without paint method.PNG


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




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.