JAVA 之 Swing简介

Swing Package Overview

Swing can expand and simplify your development of cross-platform applications. The Swing collection consists of seventeen packages, each of which has its own distinct purpose. As you'll learn in this short course, these packages make it relatively easy for you to put together a variety of applications that have a high degree of sophistication and user friendliness.
javax.swing
The high level swing package primarily consists of components, adapters, default component models, and interfaces for all the delegates and models.
javax.swing.border
The border package declares the Border interface and classes, which define specific border rendering styles.
javax.swing.colorchooser
The colorchooser package contains support classes for the color chooser component.
javax.swing.event
The event package is for the Swing-specific event types and listeners. In addition to the java.awt.event types, Swing components can generate their own event types.
javax.swing.filechooser
The filechooser package contains support classes for the file chooser component.
javax.swing.plaf.*
The pluggable look-and-feel (PLAF) packages contain the User Interface (UI) classes (delegates) which implement the different look-and-feel aspects for Swing components. There are also PLAF packages under the javax.swing.plaf hierarchy.
javax.swing.table
The table package contains the support interfaces and classes the Swing table component.
javax.swing.text
The text package contains the support classes for the Swing document framework.
javax.swing.text.html.*
The text.html package contains the support classes for an HTML version 3.2 renderer and parser.
javax.swing.text.rtf
The text.rtf package contains the support classes for a basic Rich Text Format (RTF) renderer.
javax.swing.tree
The tree package contains the interfaces and classes which support the Swing tree component.
javax.swing.undo
The undo package provides the support classes for implementing undo/redo capabilities in a GUI.
javax.accessibility
The JFC Accessibility package is included with the Swing classes. However, its usage is not discussed here.
下面是自己写的一个小例子,呵呵,只适合那些从来没有用过的朋友,高手就可以out了:)
在ECLIPSE 下新建一个Java Project,新建类frmMain,然后贴入下面代码,运行即可,初学者可以先体验一下。
import java.awt.*;
import javax.swing.*;
public class frmMain {
   public static void main (String args[]) {
     JFrame f = new JFrame (" Student  Login ");
     Container c = f.getContentPane();
     c.setLayout (new FlowLayout());
     JLabel lblUserName = new JLabel("用户名:");
     JTextField txtUserName = new JTextField("Input your name here");
     JLabel lblPassword = new JLabel("密码");
     JTextField txtPassword = new JTextField("Enter your password here");    
     JButton btnOK = new JButton ("确定");
     JButton btnExit = new JButton("退出");
     c.add(lblUserName);
     c.add(txtUserName);
     c.add(lblPassword);
     c.add(txtPassword);
     c.add (btnOK);
     c.add(btnExit);
     f.setSize (300, 200);
     f.show();
   }
 }
这段代码实际上没有什么意义,因为布局格式没有设定,下面介绍开发FORM Application的第一步。
File ----> New---->Project,选择 Java Project,单击Next,输入工程名称,如StudengManage,然后选择工程的保存路径,单击Finish。这样,工程就建好了。
选择工具栏里的New Java Class右边的小三角,选择Visual Class,在左侧的style栏里选择Frame,在Name里输入frmMain,然后勾选中public static void main(String[] args),---->Finish.这样,一个Frame就建好了,然后需要同样的方式建立一个Panel,再将Panel加入frmMain中,你所有的界面元素都是加在Panel中的。注意,建立Panel时要取消选中的public static void main(String[] args)。将Panel的LayOut属性设为null,这样,你就可以在Panel里面布局你的界面元素了。添加好界面元素后,转到frmMain.java下,在左侧的Palette里选择Chooose Bean,然后添加你建立的Panel.这样,界面就写好了。可以通过右键选择Events--->Add Events.. 来对控件加入事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值