繁体   English   中英

如何将从一种方法中的用户获得的值用于同一类中的另一种方法

[英]How to use value obtained from user in one method to other method in same class

我从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()中使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM