gpt4 book ai didi

java - 如何将用户在一种方法中获得的值用于同一类中的其他方法

转载 作者:行者123 更新时间:2023-12-01 06:13:12 25 4
gpt4 key购买 nike

我从 abcd 获取 EnterOrderID 的值,我想在 fillCombobox 中使用它,我怎样才能实现这一点?

我是编程新手,请帮忙。

我尝试将其设置为公开,但还是不行

有人可以指导我吗

 public class abcd extends JFrame {

private JPanel contentPane;
private JComboBox comboBoxRSU;
public JTextPane EnterOrderID;
/**
* Launch the application.
*/


Connection conn = null;

/**
* Create the frame.
*/
public abcd() {



EnterOrderID = new JTextPane();
EnterOrderID.setContentType("integer");
EnterOrderID.setBounds(114, 11, 224, 20);
contentPane.add(EnterOrderID);


JButton btnGetdetails = new JButton("Getdetails");
btnGetdetails.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {

String query = "select distinct p.RM_ORDERID,s.VALID_VALUE as GID,t.TASK_NUMBER, p.INSITEA_CITY, p.ORDER_TYPE from data p,value s,task t where s.VALUE_LABEL = 'INDICATOR' and t.TASK_TYPE = 'LIS'and p.DOCUMENT_NUMBER = ?";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, (String) EnterOrderID.getText());
//is is the value input by user EnterOrderID
ResultSet rs = pst.executeQuery();

while (rs.next()) {
textFieldcrm.setText(rs.getString("RM_ORDERID"));
textGID.setText(rs.getString("GID"));
}

);

comboBoxRSU = new JComboBox();
comboBoxRSU.setBounds(354, 74, 138, 20);
contentPane.add(comboBoxRSU);
fillComboBox();



}

public void fillComboBox() {

try {
String query = "select distinct s.VALID_VALUE as rsu,p.INSITEA_CITY from value s,data p where s.VALUE_LABEL = 'GIS_RSU_DLC' and p.INSITEA_CITY = (select INSITEA_CITY from data where DOCUMENT_NUMBER = ?)";
//(select INSITEA_CITY from data where DOCUMENT_NUMBER = ?)
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, (String) EnterOrderID.getText());
//Here I want to use it again, i do want user to input value again and again.
ResultSet rs = pst.executeQuery();

while (rs.next()) {
comboBoxRSU.addItem(rs.getString("rsu"));
}

}
}

最佳答案

public JTextPane EnterOrderID 是一个类变量,因此您可以在 fillComboBox() 中使用它。

关于java - 如何将用户在一种方法中获得的值用于同一类中的其他方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30957461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com