Home  >  Article  >  Database  >  Swing桌面程序(第2篇)

Swing桌面程序(第2篇)

WBOY
WBOYOriginal
2016-06-07 15:33:091282browse

Swing中的控件可以分为三类:顶层容器、非顶层容器和普通控件。 1)顶层容器是一种可以直接显示在系统桌面上的控件,也就是作为GUI应用程序的最外层容器。其他控件必须直接或间接地借助顶层容器进行显示。 顶层容器一般包括JFrame窗口类,JWindow和JDialog类

Swing中的控件可以分为三类:顶层容器、非顶层容器和普通控件。

1)顶层容器是一种可以直接显示在系统桌面上的控件,也就是作为GUI应用程序的最外层容器。其他控件必须直接或间接地借助顶层容器进行显示。

顶层容器一般包括JFrame窗口类,JWindow和JDialog类。

2)非顶层容器是要放到顶层容器中使用的,对于顶层容器来说,非顶层容器是一般控件。

     在非顶层容器中还可以添加控件,对于这些控件来看,非顶层容器就是一个容器。

     非顶层容器包括JPanel面板类。

3)普通控件在控件中占大多数,使用这些控件可以实现特定的功能,但普通控件不具有容器的作用。

 

package com.whut.sw;

import javax.swing.*;
public class Swing7 extends JFrame{
 JPanel jp=new JPanel();
 JButton jb=new JButton();
 //定义构造器
 public Swing7(){
  this.setTitle("创建面板");
  jb.setText("这是一个按钮");
  
  jp.add(jb);
  this.add(jp);
  this.setBounds(300, 250, 300, 200);
  this.setVisible(true);
 }
 public static void main(String[] args) {
  Swing7 s = new Swing7();

 }

}
---------------------------------------------------------------------------------

结果如下:

Swing桌面程序(第2篇)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn