1
라디오 버튼을 클릭 한 후에 void 메소드에서 "재 선택"할 수 있도록 버튼을 설정하려하지만 버튼에 대한 변수를 actionPerformed 메소드에서 사용할 수 없습니까?설정 버튼이 표시됩니다.
public class SelectionForm extends WindowAdapter implements ActionListener {
void select() {
JFrame frame = new JFrame("Selection Form");
JPanel leftPanel = new JPanel();
// JPanel has BoxLayout in x-direction
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.X_AXIS));
JRadioButton rd1 = new JRadioButton("Laptop");
JRadioButton rd2 = new JRadioButton("Desktop");
//submit button
JButton reselect = new JButton(" Re-select ");
reselect.setVisible(false);
// adding radio buttons in the JPanel
leftPanel.add(rd1);
leftPanel.add(rd2);
leftPanel.add(reselect);
rd1.addActionListener(this);
rd2.addActionListener(this);
//reselect button
reselect.addActionListener(this);
// add JLabels in the frame
frame.getContentPane().add(leftPanel);
frame.setSize(300, 200);
//frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
System.out.println("Selected: " + e.getActionCommand());
if(e.getActionCommand().equals("Laptop") ||
(e.getActionCommand().equals("Desktop"))){
//OnlineShop oS = new OnlineShop();
// oS.onlineShop();
reselect.setVisible(true);
}
}
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.out.println("Closing window!");
System.exit(0);
}
}
성공적인 프로그래머가되고 싶다면 가변 범위를 포함하여 기본 사항을 알아야합니다. – mre
이 첫 번째 Java 프로그램입니까? – buch11