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() {
    setSize(300, 300);
     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?

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.

commented: It works now, thanks! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.