package
org.loon.chair.example1;
import
java.awt.*;
import
javax.swing.*;
public
class
Example1
extends
JPanel{
private
static
final
int
WIDTH
=
300;
private
static
final
int
HEIGHT
=
300;
public
Example1(){
setBackground(new
Color(255,255,255));
setPreferredSize(new
Dimension(WIDTH,
HEIGHT));
}
public
void
paintComponent(Graphics
g){
super.paintComponent(g);
g.drawString("Easy
Java",
40,
40);
} //要在这里加上一个main函数才可以运行这个程序。 public
static
void
main(String
[]
args){
JFrame
f
=
new
JFrame();
f.add(new
Example1());//注意这里,要把panel放到Frame上才可以显示出来。如果不理解,可以再问我
f.setSize(500,400);
f.setVisible(true);}}