2013-01-13 174 views
0

我想從類的DataEntry文本字段的值到我目前的類SoilTable爲了使表工作如何從一個文本框獲得價值到另一個

private void btgetinvActionPerformed(java.awt.event.ActionEvent evt) {           



    try {         //my class DATAENTRY from which i have to fetch the value of textfield tf_rm_id 
     DBUtil util = new DBUtil(); 
     Connection con = util.getConnection(); 
     PreparedStatement stmt = con.prepareStatement("select COUNT(box_no)as total from mut_det WHERE rm_id = ?"); 
     ResultSet rs; 
     String rm = tf_rm_id.getText().trim(); 
     stmt.setInt(1, Integer.parseInt(rm)); 
     rs = stmt.executeQuery(); 
     while (rs.next()) { 
      tf_boxno.setText(rs.getString("total")); 
     } 

這是我的課堂,我想要替換textfield tf_rm_id的值爲?參數

 try {            // My current class SoilTable 
     DBUtil util = new DBUtil(); 
     Connection con = util.getConnection(); 
     Statement stmt = con.createStatement(); 
     ResultSet rs = stmt.executeQuery("select * from soil_det where rm_id=?"); 
     String rmn = (tf_rm_id.getText() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText(); 
     stmt.setLong(1, Long.parseLong(rmn)); 
+0

是textfield聲明爲 私有? –

+0

是什麼問題? – vels4j

回答

1

如果我理解得很好(你的代碼不是很清楚),我會創建一個方法並返回該值。

在你其他類我將創建一個類的對象,並調用該方法,然後,如果你想,像分配給另一個值:

//的DataEntry類

public String getVal() 
    { 
     return tf_rm_id; 
    } 

// SoilTable

DATAENTRY textFieldVal = new DATAENTRY(); 

String strTextFieldVal = textFieldVal.getVal(); 
//assigned a new value 
strTextFieldVal = " field value manipulated"; 

//or display it directly: 

System.out.println("Value recieved: "+textFieldVal.getVal()); 
相關問題