新人菜鸟求助!
我定义了框架 也定义了面板 为什么只显示框架,没显示Hello,World 呢?
import javax.swing.*;
import java.awt.*;
public class HelloWorld
{
public static void main(String[] args)
{
TextFrame frame=new TextFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class TextFrame extends JFrame
{
public TextFrame()
{
setTitle("HelloWorld");
setSize(WIDTH,HEIGHT);
TextPanel panel=new TextPanel();
Container contenPane=getContentPane();
contenPane.add(panel);
}
public static final int WIDTH=300;
public static final int HEIGHT=200;
}
class TextPanel extends JPanel
{
public void painComponent(Graphics g)
{
super.paintComponent(g);
g.drawString("Hello,World", x, y);
}
public int x=100;
public int y=100;
}