GUI工具包 Swing
Swing 是一個為Java設計的GUI工具包。 Swing 是 JAVA基礎類 的一部分。 Swing 包括了圖形用戶界面 (GUI) 器件 如:文本框,按鈕,分隔窗格和表。
SWING 提供許多比AWT更好的屏幕顯示元素。它們用純Java寫成,所以同Java本 身一樣可以跨平臺運行,這 一點不像AWT。 它們是JFC的一部分。 它們支持可更換的面板和主題(各種操作系統默認的特有主題),然而不是真的使用原生平臺提供的設備,而是僅僅在表面上模仿它們。這意味著你可以在任意平臺 上使用JAVA支持的任意面板。 輕量級元件的缺點則是執行速度較慢,優點就是可以在所有平臺上采用統一的行為。
Swing程序外觀
示例代碼:
import javax.swing.*; public class HelloWorldSwing { /** * 創建并顯示GUI。 出于線程安全的考慮, * 這個方法在事件調用線程中調用。 */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!