0

Hey guys, sorry I didn't post for long. Now here I am, with a new issue. Here is my code:-

import java.applet.*;
import java.awt.*;
import javax.swing.JFrame;
public class HelloWorld extends JFrame
{
public HelloWorld() {
  setVisible(true);
  setResizable(false);
    setSize(300, 300);
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
     public void paint (Graphics g)
{
  g.drawString("Hello World!", 50, 25);
 }
public static void main(String[] args) {
new HelloWorld();
}

}

The string displays, but the window is transparent. Why and how to solve it?

Edited by jackbauer24: Wrong code

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by JamesCherrill
1

You overrode paint so you lost all the stuff that normally happens when a JFrame paints itself. Just start your method with a super.paint(g) to get all that stuff painted before you add your own drawing.

Votes + Comments
It works now, thanks!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.