图形界面 ----JButton

来源:互联网 发布:域名注册信息批量查询 编辑:程序博客网 时间:2024/05/16 01:22
  1. JButton是一个普通的按钮,直接使用此类就可以增加一个按钮。可以设置快捷键。setMnemonic();还以设置成图片按钮

    package GUI;

    import java.awt.FlowLayout;
    import java.io.File;

    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class JButtonDemo01 {
    public static void main(String[] args){
    JFrame j = new JFrame();
    j.setLayout(new FlowLayout());
    JButton jb1 = new JButton("kick me");

    String picPath = "F:"+File.separator+"123.jpg";

    Icon icon = new ImageIcon(picPath);
    JButton jb2 = new JButton(icon);

    j.add(jb1);
    j.add(jb2);

    j.setSize(300, 300);
    j.setLocation(300, 300);

    j.setVisible(true);
    }
    }



0 0
原创粉丝点击