zoukankan      html  css  js  c++  java
  • 第十四节:窗体实验

    图片

    实验目的

    1 框架类,按扭类,文本类,输入框类的基本方法使用

    要求

    1.在屏幕上显示如下界面,要求窗口显示在屏幕的正中间
    2.窗口的尺寸如图所示

    图片

    步骤:

    定义类继承JFrame
    调用JFrame中的相关方法显示窗体
    根据窗体中的组件为窗口添加成员变量并实例化每个组件。

    定义窗口的布局方式
    将组件按顺序添加到窗体中。
    主方法中实例化窗体并显示

    代码

    package c;
    
    import javax.swing.*;
    
    public class JFrameDemo extends JFrame{
    
    JFrameDemo(){
    super("關於窗口...");
    }
    
    JFrameDemo(String title){
    super(title);
    }
    
    public void init(){
    this.setSize(250,250);
    this.setLocation(100,100);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public static void main(String[] args) {
    new JFrameDemo().init();
    }
    }
    package c;
    
    import java.awt.*;
    
    import javax.swing.*;
    
    public class FlowLayoutDemo extends JFrameDemo {
    JLabel jb11,jb12,jb13;
    JButton jb1;
    JButton jb2;
    JTextField jb111;
    
    FlowLayoutDemo(){
    super("關於窗口...");
    jb11=new JLabel("Happy聊天室Copyright2007-2010");
    jb12=new JLabel(new ImageIcon("logo.gif"));
    jb1=new JButton("系统信息");
    jb13=new JLabel("请输入你的名字");
    jb111=new JTextField(15);
    jb2=new JButton(("退出"),new ImageIcon("exit.gif"));  
    }
    
        public void init(){
        super.init();
        this.setLayout(new FlowLayout(FlowLayout.CENTER));
        this.add(jb11);
        this.add(jb12);
        this.add(jb1);
        this.add(jb13);
        this.add(jb111);
        this.add(jb2);
        }
    
    public static void main(String[] args) {
    FlowLayoutDemo demo=new FlowLayoutDemo();
    demo.init();
    }
    }

    运行结果图

    图片

    小礼物走一走 or 点赞

    图片

  • 相关阅读:
    3-AII--BroadcastReceiver实现锁、开屏、短信监听
    grpc入门2
    关于golang中某些包无法下载的解决方法
    grpc入门
    grpc安装
    小鼠试毒问题(二进制)
    gomod
    POJ 1743 Musical Theme ——后缀数组
    SPOJ DISUBSTR ——后缀数组
    BZOJ 4066 简单题 ——KD-Tree套替罪羊树
  • 原文地址:https://www.cnblogs.com/dashucoding/p/11932584.html
Copyright © 2011-2022 走看看