tôi mở rộng JDialog để tạo ra một hộp thoại tùy chỉnh mà người dùng phải điền một số lĩnh vực: dialog http://www.freeimagehosting.net/uploads/3d4c15ed9a.jpgLấy đầu vào nhập vào một JDialog
Làm thế nào tôi nên lấy dữ liệu nhập vào?
Tôi đã đưa ra giải pháp hoạt động. Nó bắt chước JOptionPane nhưng cách tôi làm điều đó trông xấu xí với tôi bởi vì các trường tĩnh tham gia ... Đây là khoảng mã của tôi:
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;
}
}
Như tôi đã nói, đó là hoạt động đúng, nhưng tôi đoán rằng có thể nâng cao nghiêm trọng vấn đề tương tranh ...
Có cách nào khác để làm điều đó không? Làm thế nào là nó được thực hiện trong JOptionPane?
Bạn sử dụng giao diện nào? –
@Martijn Courteaux: Nimbus (http://stackoverflow.com/questions/2616448/im-tired-of-jbuttons-how-can-i-make-a-nicer-gui-in-java) ;-) –