//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?????怎麼調大一點呢?