我有兩個類另一個JFrame的,我現在用的ActionListeners,事情是,我想從第二個... THE FIRST CLASS接收第一類中的int值這是一個:傳遞int值從一個JFrame中使用的ActionListener
public class PanelCotizacion extends javax.swing.JPanel implements ActionListener {
private int numCotizacion = 0;
public PanelCotizacion() {
initComponents();
}
public void actionPerformed(ActionEvent e) {
System.out.println("HERE IS WHERE I WANT TO RECEIVE THE VALUE");
this numCotizacion = "";
//THE VALUE THAT I WANT TO RECEIVE FROM THE OTHER jFRAME
//TRIGGERED BY THE EVENT OF THE BUTTON (action performed)
}
}
這是第二個,在這裏我要發送的int值:
public class BusquedaCotizacionGUI extends javax.swing.JFrame {
private int numCotizacion = 0;
public BusquedaCotizacionGUI() {
initComponents();
this.setLocationRelativeTo(null);
PanelCotizacion pC = new PanelCotizacion();
this.cmdOK.addActionListener(pC);
}
private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) {
this.numCotizacion = Integer.parseInt(this.txtNumCotizacion.getText());
//Here is where I WANT TO PASS THE VARIABLE "numCotizacion" tho the other class
//Can Somebody Help Me
this.dispose();
}
}
你能幫我傢伙要做到這一點,非常感謝!
感謝Salah您的評論,構造函數採取一個int參數不起作用,第二個選項我不知道把它放到我的代碼「parent.getNumCotizacion();」導致它產生我的錯誤,我忘了也提到,我使用的面板我已經改變了很多時間與其他面板,使用removeAll(); .add(component),.updateUI();所以我不知道這是否會影響爲什麼我不能看到變量numCotizacion的更新,我要嘗試Kojotak – Mario