我伸出的JDialog創建一個自定義對話框中輸入輸入了用戶必須填寫一些字段: dialog http://www.freeimagehosting.net/uploads/3d4c15ed9a.jpg檢索一個JDialog
我應該如何檢索輸入的數據?
我想出了一個可行的解決方案。它模仿的JOptionPane,但我做的方式,它看起來醜陋的我,因爲所涉及的靜態字段...這裏是我的粗略代碼:
public class FObjectDialog extends JDialog implements ActionListener {
private static String name;
private static String text;
private JTextField fName;
private JTextArea fText;
private JButton bAdd;
private JButton bCancel;
private FObjectDialog(Frame parentFrame) {
super(parentFrame,"Add an object",true);
// build the whole dialog
buildNewObjectDialog();
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==bAdd){
name=fName.getText();
text=fText.getText();
}
else {
name=null;
text=null;
}
setVisible(false);
dispose();
}
public static String[] showCreateDialog(Frame parentFrame){
new FObjectDialog(parentFrame);
String[] res={name,text};
if((name==null)||(text==null))
res=null;
return res;
}
}
正如我所說的,可以正常工作,但我想這可能會引起嚴重併發問題...
有沒有更簡單的方法來做到這一點?它如何在JOptionPane中完成?
你使用什麼外觀和感覺? – 2010-04-12 07:32:16
@Martijn Courteaux:Nimbus(http://stackoverflow.com/questions/2616448/im-tired-of-jbuttons-how-can-i-make-a-nicer-gui-in-java);-) – 2010-04-12 07:39:43