Java学习之创建一个JFrame
案例代码:
import javax.swing.*;
import java.awt.*;
public class MyFrame {
private JFrame f;
//JButton jb=new JButton("OK");
public MyFrame() {
f=new JFrame("Hello,this is the first GUI");
}
public void launchFrame(){
f.setSize(170,170);
f.setLocation(50,50);
Container c=f.getContentPane();
c.setBackground(Color.BLUE);
//c.add(jb);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
MyFrame mf=new MyFrame();
mf.launchFrame();
}
}
案例运行图:
还没有评论,来说两句吧...