excel2016官方网站:这个JAVA程序为什么不能显示字符串?

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 18:57:45
这个程序有什么不妥当?
发现不能正常现实字符串,请赐教!!

import java.awt.*;
import javax.swing.*;

public class exec
{
public static void main(String args[])
{
MyFrame m=new MyFrame("OK");
m.setSize(200,400);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.setVisible(true);
}
}

class MyFrame extends JFrame
{
public MyFrame(String title)
{
super(title);
}

public void paint(Graphics g)
{
g.drawString("Hello!",0,0);
setBackground(Color.yellow);
g.setColor(Color.red);

}
}

g.drawString("Hello!",0,0); //把位置改一下就能看见了,
00这个位置会被标题栏给挡住