Java JButton按钮使用

/**
 *JButton按钮按键
 *
 */
package com.swing;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
class jbutton extends JFrame{
    private JButton btn1,btn2,btn3,btn4,btn5;
    public static void main(String[] args){
        jbutton jb=new jbutton();
    }
    public jbutton(){
        this.setTitle("多设置按钮!");
        this.setSize(800,500);
        this.setLocation(100,100);
        btn1=new JButton("东");
        btn2=new JButton("南");
        btn3=new JButton("西");
        btn4=new JButton("北");
        btn5=new JButton("中");
        this.add(btn1,BorderLayout.EAST);
        //this.add(btn2,BorderLayout.SOUTH);
        this.add(btn3,BorderLayout.WEST);
        //this.add(btn4,BorderLayout.NORTH);
        this.add(btn5,BorderLayout.CENTER);
                
        //关闭窗体是退出进程
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //显示窗体
        this.setVisible(true);
                 
    }
}


运行结果:

203037693.jpg

你可能感兴趣的:(java,import,package,private,public)