JButton():设置一个没有文本图案的按钮
JButton(String text):创建一个带文本的按钮
getContentPane().add(组件)
package apiapi;import javax.swing.*;public class api {public static void main(String[] args) {JFrame frame=new JFrame();frame.setTitle("JButton按钮提示");frame.setSize(514,538);frame.setLocationRelativeTo(null);frame.setAlwaysOnTop(true);frame.setDefaultCloseOperation(3);//1.通过窗体对象,取消默认布局frame.setLayout(null);//2.创建按钮对象JButton btn=new JButton();//在setLayout(null)后指定放在哪一位置btn.setBounds(50,50,50,50);JButton btn2=new JButton("点我呀");btn2.setBounds(150,150,80,80);//3.通过窗体对象,获取到面板对象,并调用add方法添加按钮组件frame.getContentPane().add(btn);frame.getContentPane().add(btn2);frame.setVisible(true);}
}
结果: