//TestDrawString.java
impront java.awt. *;
impront javax.awt. *;
//主框架类
public class TestDrawString extends JFrame
{
public TestDrawString()
{
setTitle("TestDrawString");
this.getContentPane().add(new MyPanel());
}
public static void main(String[]args)
{
TestDrawString frame=new TestDrawString();
frame.setSize(200,100);
frame.setVisible(true);
}
}
//定义一个可以显示图形的面板类
class Mypanel extends JPanel
{
public void paintComponent(Graphic g)
{
//调用父类的paintComponent方法进行初始绘制
super.paintComponent(g);
//绘制文本
g.drawString("Hello World!!!",20,30);
}
}
impront java.awt. *;
impront javax.awt. *;
//主框架类
public class TestDrawString extends JFrame
{
public TestDrawString()
{
setTitle("TestDrawString");
this.getContentPane().add(new MyPanel());
}
public static void main(String[]args)
{
TestDrawString frame=new TestDrawString();
frame.setSize(200,100);
frame.setVisible(true);
}
}
//定义一个可以显示图形的面板类
class Mypanel extends JPanel
{
public void paintComponent(Graphic g)
{
//调用父类的paintComponent方法进行初始绘制
super.paintComponent(g);
//绘制文本
g.drawString("Hello World!!!",20,30);
}
}