2015-03-25 30 views
0

問題只是希望GUI看起來像這樣:無法Java GUI以我想要的方式...?

下面的代碼我有

import javax.swing.JOptionPane; 

class Customer 
    { 

    String n = JOptionPane.showInputDialog("Enter name"); 
    String id = JOptionPane.showInputDialog("Enter id"); 
    String sub = JOptionPane.showInputDialog("Enter Submit"); 

JOptionPane.showMessageDialog(null, null, null, JOptionPane.PLAIN_MESSAGE) 

    } 

}

我想這一切看起來水平

Enter Name   [box to fill in name] 

Enter id   [box to fill in id] 

Submit    [box to enter submit] 
+2

開始用一些輕閱讀:[創建GUI用JFC/Swing的(http://docs.oracle.com/javase/tutorial/uiswing/ ),[在容器中放置組件](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html),[如何使用文本字段](http://docs.oracle.com)。 (如何使用按鈕,複選框和單選按鈕)(http://docs.oracle.com/javase/tutorial/uiswing/components/button.html ),你可能會想[如何編寫一個動作監聽器](http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html) – MadProgrammer 2015-03-25 01:41:23

+0

嘿謝謝你的鏈接,真的幫了大忙! – Noah 2015-03-26 01:59:39

+0

不用擔心,玩得開心;) – MadProgrammer 2015-03-26 02:00:19

回答

2

你總共顯示4個選項面板。如果你想在一個一切選項窗格,這可能幫助:

JPanel msgPanel = new JPanel(); 
msgPanel.setLayout(new GridLayout(3 , 2)); 

msgPanel.add(new JLabel("Enter name"); 

JTextField nameField = new JTextField(); 
msgPanel.add(nameField); 

//create other fields and labels 

JOptionPane.showMessageDialog(null , msgPanel , "" , JOptionPane.PLAIN_MESSAGE); 

String name = nameField.getText(); 
//read other fields 
相關問題