GUI组件——按钮 Button
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package x_05;
import javax.swing.*;//导入Swing类,其中包括了JFrame类
import java.awt.*;//设置布局管理器的调用的类库
/**
*
* @author Administrator
*/
public class XButton extends JFrame{ //继承JFrame框架类
/**
* @param args the command line arguments
*/
public XButton(){ //Frame框架的构造函数
super("XFrame mono!"); //设置标题
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭窗口的事件
setVisible(true);//设置框架可见性
setSize(350,200);//设置框架大小
FlowLayout flo =new FlowLayout();//创建布局管理器对象
setLayout(flo);//将管理器和容器关联
JButton play =new JButton("Play");//创建按钮play,并显示内容为“Play”
JButton stop =new JButton("Stop");
JButton pause =new JButton("Pause");
add(play);//将按钮play加入到容器中
add(stop);
add(pause);
setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
XButton sal= new XButton();//创建框架对象实例
}
}
运行界面: