package com.sunzhiyan; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Demo_1 extends JFrame{ /** * @param args */ JButton button1,button2,button3; public static void main(String[] args) { // TODO Auto-generated method stub Demo_1 demo = new Demo_1("hellow"); } public Demo_1(String name){ JButton button1 = new JButton("123"); JButton button2 = new JButton("456"); JButton button3 = new JButton("789"); this.add(button1); this.add(button2); this.add(button3); //启动流式布局,并且左浮动 this.setLayout(new FlowLayout(FlowLayout.LEFT)); this.setTitle(name); this.setSize(400,400); this.setLocation(100,100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //this.setLayout(null); //this.setResizable(false); //this.setEnabled(true); this.setVisible(true); } }
查JDK手册,可知 JButton
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JButton
内部是这样的一个多继承的方式,因此底层的同时也能够使用上 层的方法和属性