2017-02-21 81 views
0

我一直在使用Java多年,但我從未使用過圖形用戶界面。我現在想先這麼做,我想知道很多框架中的哪一個可能最適合我。Java最適合的初學者GUI lib

我不想做任何奇特的事情,只是基本的東西:按鈕,單選按鈕,複選框,textfileds,我可能希望能夠繪製圖形。我想使用最容易安裝的框架,開始使用,使用等等,並且可以執行上面提到的事情。我不想全部嘗試。

任何幫助/建議將grely讚賞。

在此先感謝!

霍斯特

+1

你有沒有試過Swing? –

+0

使用swing或swt。 – krock

+0

可能的[Java GUI框架。可以選擇什麼? Swing,SWT,AWT,SwingX,JGoodies,JavaFX,Apache Pivot?](http://stackoverflow.com/questions/7358775/java-gui-frameworks-what-to-choose-swing-swt-awt-swingx-jgoodies -javafx) –

回答

0

Swing是很容易使用。你不需要任何外部庫,只需創建你的對象(JFrame,JPanel,JButton ...)並顯示它們。還有很多可視化編輯器可以用來更方便地進行GUI設計。

Hello World程序與Swing:

/* 
* HelloWorldSwing.java requires no other files. 
*/ 
import javax.swing.*;   

public class HelloWorldSwing { 
    /** 
    * Create the GUI and show it. For thread safety, 
    * this method should be invoked from the 
    * event-dispatching thread. 
    */ 
    private static void createAndShowGUI() { 
     //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(); 
      } 
     }); 
    } 
} 
+0

非常感謝這個答案,我會先嚐試擺動。 – DFF

3

我有同樣的問題,我採用了普通的JavaFX(像格里芬或其他無框架)。

由於2個原因,JavaFX是Java的新桌面UI標準,因此更好地開始使用最新版本。

我選擇不使用框架,因爲在使用它們之前,您需要對它們基於的內容有深入的瞭解。

最後,使用了Gluon場景構建器並閱讀了一些JavaFX教程,我確實經歷了這些體驗,現在我有4個JavaFX應用程序正在運行。