import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("")
frame.setLayout(new FlowLayout())
frame.setSize(220, 90)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
JLabel jLabel = new JLabel("hello")
JButton jButton = new JButton("欢迎")
frame.add(jLabel)
frame.add(jButton)
frame.setVisible(true)
}
}
JFrame可以理解成一个容器,既然是容器就可以装东西。JButton就属于容器里面的东西,比如说是鱼。如果鱼离开了水,是无法生存的,这就可以类比JButtion必须放到JFrame上面才能进行添加。JAVA Swing中JFrame代表容易,JPane代表面板或者画布,可以在上面添加按钮、对话框、输入框等。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)