Java学习之创建一个JFrame

短命女 2023-01-18 06:39 238阅读 0赞

案例代码:

  1. import javax.swing.*;
  2. import java.awt.*;
  3. public class MyFrame {
  4. private JFrame f;
  5. //JButton jb=new JButton("OK");
  6. public MyFrame() {
  7. f=new JFrame("Hello,this is the first GUI");
  8. }
  9. public void launchFrame(){
  10. f.setSize(170,170);
  11. f.setLocation(50,50);
  12. Container c=f.getContentPane();
  13. c.setBackground(Color.BLUE);
  14. //c.add(jb);
  15. f.setVisible(true);
  16. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17. }
  18. public static void main(String args[]){
  19. MyFrame mf=new MyFrame();
  20. mf.launchFrame();
  21. }
  22. }

案例运行图:
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,238人围观)

还没有评论,来说两句吧...

相关阅读