使用java中的swing来写出简单的图形框
import java.awt.Color;
import javax.swing.JFrame;
public class SwingDemo extends JFrame{
public SwingDemo(){
this.setSize(400,400);//设置窗体的大小
this.setLocation(200, 200);//设置窗体的位置
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//在点击关闭的时候,程序停止
//下面两句代码可以设置颜色,但需要用到awt。
// Container c = this.getContentPane();
// c.setBackground(Color.YELLOW);
this.getContentPane().setBackground(Color.red);
this.setVisible(true);//设置窗体显示
}
public static void main(String[] args) {
new SwingDemo();
}
}
以上就是简单的显示图形窗口的程序!