3 つのテキスト フィールドと 2 つのラジオ ボタン (はいまたはいいえを選択するため) を含む jframe があります。
次のようになります。
しかし、私のコードでは、これは次のとおりです。
私のコード:
public class editFrame extends JFrame {
JButton saveButton;
JButton cancelButton;
JRadioButton radioB1;
JRadioButton radioB2;
public editFrame() {
JPanel wrapper = new JPanel();
wrapper.add(createForm());
add(wrapper, BorderLayout.WEST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 50, 500, 600);
this.setVisible(true);
}
public JPanel createForm() {
String[] labels = {"ID", "Name", "Date"};
JPanel panel = new JPanel();
JTextField idtf = new JTextField(10);
JTextField nametf = new JTextField(10);
JTextField datetf = new JTextField(10);
panel.add(idtf);
panel.add(nametf);
panel.add(datetf);
radioB1 = new JRadioButton("Yes");
radioB2 = new JRadioButton("No");
ButtonGroup group = new ButtonGroup();
group.add(radioB1);
group.add(radioB2);
panel.add(radioB1);
panel.add(radioB2);
saveButton = new JButton("update");
cancelButton = new JButton("Cancel");
panel.add(saveButton);
panel.add(cancelButton);
SpringLayout sL = new SpringLayout();
panel.setLayout(sL);
SpringUtilities.makeCompactGrid(panel, 3, 2, 100, 50, 15, 20);
return panel;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
editFrame edF = new editFrame();
}
});
}
借用ステータス テキストは、ラジオ ボタンの横に表示されません。私の 2 番目の主な問題は、このコードではテキスト フィールドにアクセスできないことです。後でテキスト フィールドにアクセスする必要があります...