Вот кусок текста программы:
public class ViewFrame extends javax.swing.JFrame {
public JRadioButton deptRadioButton;
public JRadioButton empRadioButton;
public JRadioButton salRadioButton;
public String direct;
public ViewFrame() {
setTitle("AppDirectory");
setSize(700, 600);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setLayout(new BorderLayout());
JPanel dbTablePanel = new JPanel(new GridBagLayout());
DataBaseTableModel dbtm = new DataBaseTableModel("jdbc:oracle:thin:@localhost:1521:orcl",
"oracle.jdbc.OracleDriver", "SCOTT", "TIGER");
JTable dbTable = new JTable(dbtm);
System.out.println(deptRadioButton.isSelected());
/*if(deptRadioButton.isSelected()){
direct = "SELECT * FROM SCOTT.DEPT";
}
else if(empRadioButton.isSelected()){
direct = "SELECT * FROM SCOTT.EMP";
}
else {
direct = "SELECT * FROM SCOTT.SALGRADE";
}*/
dbtm.executeQuery(direct);
JScrollPane dbTableScrollPane = new JScrollPane(dbTable);
dbTableScrollPane.setPreferredSize(new Dimension(550, 250));
dbTablePanel.add(dbTableScrollPane, new GridBagConstraints(0, 0, 3, 1, 2,
1, GridBagConstraints.NORTH, GridBagConstraints.BOTH,
new Insets(1, 1, 1, 1), 0, 0));
JPanel buttonPanel = new JPanel(new GridBagLayout());
JButton addButton = new JButton("Ввод");
addButton.setToolTipText("Ввести новые данные в таблицу");
JButton editButton = new JButton("Редактировать");
editButton.setToolTipText("Редактировать существующую запись");
JButton deleteButton = new JButton("Удалить");
deleteButton.setToolTipText("Удалить данные из таблицы");
JButton dropButton = new JButton("Очистить");
dropButton.setToolTipText("Очистить таблицу");
dropButton.setBackground(Color.RED);
dropButton.setForeground(Color.WHITE);
buttonPanel.add(addButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 1, 1, 1), 0, 0));
buttonPanel.add(editButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 1, 1, 1), 0, 0));
buttonPanel.add(deleteButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 1, 1, 1), 0, 0));
buttonPanel.add(dropButton, new GridBagConstraints(3, 1, 1, 1, 1, 1,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 1, 1, 1), 0, 0));
add(dbTablePanel, BorderLayout.NORTH);
add(buttonPanel, BorderLayout.SOUTH);
setVisible(false);
pack();
setLocationRelativeTo(null);
}
}
я пробовал и isChecked()
, и isSelected()
, и такую форму:
true.isSelected().equals(deptRadioButton);
и такую:
deptRadioButton.isSelected().equals(true);
deptRadioButton.isSelected()
, если вывести прямо на экран?