Java 如何从groupbutton检索jbuttons文本
我正在尝试获取所选按钮的文本名称并将其发送到我的数据库。按钮组是否有方法传递所选按钮名称的文本?因为我想将所选按钮名称插入到事务表中Java 如何从groupbutton检索jbuttons文本,java,swing,prepared-statement,jbutton,buttongroup,Java,Swing,Prepared Statement,Jbutton,Buttongroup,我正在尝试获取所选按钮的文本名称并将其发送到我的数据库。按钮组是否有方法传递所选按钮名称的文本?因为我想将所选按钮名称插入到事务表中 try { conn = getConnection(); String Transaction = "INSERT INTO Transaction" + "(Currency_type, currency_Amount,Local_Amount,Rate,Tran_type) VALUES"
try {
conn = getConnection();
String Transaction = "INSERT INTO Transaction"
+ "(Currency_type, currency_Amount,Local_Amount,Rate,Tran_type) VALUES"
+ "(?,?,?,?)";
pst = conn.prepareStatement(Transaction); // create a statement
pst.setObject(1,DisplayL.getText()); // set input parameter 1
pst.setObject(2,txt_select.getText()); // set input parameter 2
pst.setObject(3,txt_amount.getText()); // set input parameter 1
pst.setObject(4,txt_rate.getText()); // set input parameter 2
pst.setObject(5,buttonGroup2); // set input parameter 2
pst.execute();// execute update statement
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
pst.close();
} catch (SQLException ex) {
Logger.getLogger(connectnm.class.getName()).log(Level.SEVERE, null, ex);
}
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(connectnm.class.getName()).log(Level.SEVERE, null, ex);
}
}
预期产量
交易
Tran_ID |Currency_type | currency_Amount| Local_Amount| Rate |Tran_type|
4 | Euro | 1200.00 | 1000.00 | 1.120 |**Sell** |
JButton或JToggleButton或JCheckBox或JRadioButton???,取决于,默认情况下无法选择纯JButton如何选择JButton?我想根据按钮的选择来存储显示bough或Seld的消息
我如何通过按下鼠标、输入和键盘上的Tab键来选择Jbutton
->,在这种情况下,与JToggleButton/JCheckBox/JRadioButton相比,事件立即被消耗
ButtonModel btnModel = buttonGroup2.getSelection();
if(btnModel !=null)
{
btnModel.getActionCommand()
}