您的位置:首页 > 编程语言 > Java开发

用java Swing写一个最简单的图形框

2015-06-29 21:53 447 查看
使用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);//在点击关闭的时候,程序停止
</pre><pre name="code" class="java">
<span style="white-space:pre">		</span>//下面两句代码可以设置颜色,但需要用到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();
}
}


以上就是简单的显示图形窗口的程序!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  图形 swing java class