zoukankan      html  css  js  c++  java
  • 170220GUI基础1

    JPanel,JButton,JLabel,JTextField,JPasswordField,JLabel,JCheckBox,JRadioButton

    20170220上课课程记录代码1(JPanel,JButton,JLabel,JTextField,JPasswordField):

    package test;
    import java.awt.*;
    import javax.swing.*;
    public class test extends JFrame{
    /**
    * 
    */
    private static final long serialVersionUID = 1L;
    
    private JPanel jp1,jp2,jp3;
    private JButton jb1,jb2,jb3,jb4,jb5;
    private JLabel jlbl1,jbl1,jbl2;//文本控件
    private JTextField jtf1,jtf2;
    private JPasswordField jpf1;
    private JButton jbt1,jbt2;
    
    public test(){
    this.setTitle("我的第一个窗体");//设置窗体标题 this 该类当前的对象
    this.setLocation(200,200);//设置窗体显示的位置
    this.setSize(200,200);//设置大小
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    
    /*jp1=new JPanel();
    jp1.setLocation(0,0);
    jp1.setSize(200,200);
    jp1.setBackground(Color.red);
    this.add(jp1);*/
    
    
    //流式布局 设置了布局按钮大小事固定的
    /* LayoutManager manager = new FlowLayout(FlowLayout.LEFT);
    this.setLayout(manager);
    jb1=new JButton();
    jb1.setText("按钮1");
    jb2=new JButton();
    jb2.setText("按钮2");
    jb3=new JButton();
    jb3.setText("按钮3");
    jb4=new JButton();
    jb4.setText("按钮4");
    jb5=new JButton();
    jb5.setText("按钮5");
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jb5);*/
    
    
    //边框布局
    /*LayoutManager manager = new BorderLayout();
    this.setLayout(manager);
    jb1=new JButton();
    jb1.setText("按钮1");
    jb2=new JButton();
    jb2.setText("按钮2");
    jb3=new JButton();
    jb3.setText("按钮3");
    jb4=new JButton();
    jb4.setText("按钮4");
    jb5=new JButton();
    jb5.setText("按钮5");
    this.add(jb1,BorderLayout.NORTH);
    this.add(jb2,BorderLayout.WEST);
    this.add(jb3,BorderLayout.CENTER);
    this.add(jb4,BorderLayout.EAST);
    this.add(jb5,BorderLayout.SOUTH);*/
    
    
    //网格布局
    /*this.setLayout(new GridLayout(3,2));//三行两列
    jb1=new JButton();
    jb1.setText("按钮1");
    jb2=new JButton();
    jb2.setText("按钮2");
    jb3=new JButton();
    jb3.setText("按钮3");
    jb4=new JButton();
    jb4.setText("按钮4");
    jb5=new JButton();
    jb5.setText("按钮5");
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jb5);*/
    
    
    //文本控件
    /*ImageIcon icon=new ImageIcon("D:1.bmp");
    jlbl1=new JLabel("我是文本标签控件",icon,SwingConstants.CENTER);
    this.add(JLabel);*/
    
    
    //登陆界面
    this.setLayout(new FlowLayout());
    
    jp1=new JPanel();
    //jp1.setLayout(new FlowLayout());默认流式
    jbl1=new JLabel("用户名:");
    jtf1=new JTextField(10);
    jp1.add(jbl1);
    jp1.add(jtf1);
    this.add(jp1);
    
    jp2=new JPanel();
    jbl2=new JLabel("密 码:");
    jpf1=new JPasswordField(10);
    jp2.add(jbl2);
    jp2.add(jpf1);
    this.add(jp2);
    
    jp3=new JPanel();
    jbt1= new JButton("登陆");
    jbt2= new JButton("重置");
    jp3.add(jbt1);
    jp3.add(jbt2);
    this.add(jp3);
    
    this.setVisible(true); 
    }
    public static void main(String []args){
    new test();
    }
    }
    

      

    20170220上课课程记录代码2(JLabel,JCheckBox,JRadioButton):

    package test;
    import java.awt.*;
    import javax.swing.*;
    public class test1 extends JFrame{
    /**
    * 
    */
    private static final long serialVersionUID = 1L;
    
    private JLabel jbl1,jbl2;//文本控件
    private JCheckBox jcb1,jcb2,jcb3;
    private JRadioButton jrb1,jrb2;
    
    public test1(){
    this.setTitle("我的第一个窗体");//设置窗体标题 this 该类当前的对象
    this.setLocation(200,200);//设置窗体显示的位置
    this.setSize(300,300);//设置大小
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    
    this.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    /*ImageIcon icon=new ImageIcon("1.gif");
    JLabel jl1=new JLabel("这是haha",icon,SwingConstants.LEFT);
    */
    
    jbl1=new JLabel("请选择你感兴趣的运动:");
    jcb1=new JCheckBox("篮球");
    jcb2=new JCheckBox("排球");
    jcb3=new JCheckBox("花球");
    this.add(jbl1);
    this.add(jcb1);
    this.add(jcb2);
    this.add(jcb3);
    
    jbl1=new JLabel("请选择你的性别:");
    jrb1=new JRadioButton("男",false);
    jrb2=new JRadioButton("女",false);
    this.add(jbl1);
    this.add(jrb1);
    this.add(jrb2);
    
    this.setVisible(true); 
    
    }
    public static void main(String []args){
    new test1();
    }
    
    }
    
     
    

      

  • 相关阅读:
    [51Nod] 配对
    [Poj] Roads in the North
    【Java学习笔记之二十六】深入理解Java匿名内部类
    【Java学习笔记之二十五】初步认知Java内部类
    【Java学习笔记之二十四】对Java多态性的一点理解
    【Java学习笔记之二十三】instanceof运算符的用法小结
    【Java学习笔记之二十二】解析接口在Java继承中的用法及实例分析
    图论--拓扑排序模板
    hdu 5384 AC自动机
    java大数
  • 原文地址:https://www.cnblogs.com/liao13160678112/p/6421719.html
Copyright © 2011-2022 走看看