user4828556
user4828556

Reputation:

JApplet window is blank in netbeans

I created Test.class that extends JApplet. When I run the code, the open window appears blank and doesn't show any string. How can I solve this issue?

package test;

import java.awt.Graphics;
import javax.swing.JApplet;

public class Test extends JApplet {       

    @Override
    public void paint(Graphics g) {
        g.drawString("Hello World!", 0, 0);
    }

    @Override
    public void init() {
        repaint();
    }

}

Upvotes: 1

Views: 41

Answers (1)

trashgod
trashgod

Reputation: 205785

In drawString(), x and y are the leftmost character's baseline. With no descenders, your text is entirely outside the rendering area. Try

g.drawString("Hello World!", 5, g.getFontMetrics().getAscent());

See also Initial Threads.

Upvotes: 3

Related Questions