//DrawTextAreaDemo.java
//在构件中绘制图形,一般较大的构件可以,如JTextArea
//2009-11-08
//<applet code=DrawTextAreaDemo width=500 height=500>
//</applet>
import javax.swing.*;
import java.awt.*;
class DrawTextArea extends JTextArea
{
int size=200;
public DrawTextArea(){
super("Draw a circle",20,20);//调用超类的构造方法。
repaint();//自动调用下面重写的paintComponent()方法,这是java内在机制决定的。
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.blue);
g.drawOval(20,20,size,size);
}
}
public class DrawTextAreaDemo extends JApplet
{
DrawTextArea drawCircle=new DrawTextArea();
public void init(){
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(drawCircle);
}
}
怎么JTextArea这么小,显示不全,是不是得来个JScrollPane?????怎么调大一点呢?