这是第一个类,事情是我必须接收由按钮中的事件触发的其他类的值(行动表演),所以在这个班我想展示它!如何将文本设置为一个jTextField,它位于jFrame内部的jPanel中,以供其他jFrame使用
public class PanelCotizacion extends javax.swing.JPanel {
private int numCotizacion = 0;
public int getNumCotizacion() {
return numCotizacion;
}
public void setNumCotizacion(int numCotizacion) {
this.numCotizacion = numCotizacion;
}
public PanelCotizacion() {
initComponents();
showTextFields();
}
show textFields(){
this.txtCosTra.setText(String.valueOf(cosTra));
}
}
这是第二类,在这里我想送这是JTextField中值,记得我提到,在这两种jFrames,有jPanels和JTextFields将在其内部。
public class BusquedaCotizacionGUI extends javax.swing.JFrame {
public BusquedaCotizacionGUI() {
initComponents();
this.setLocationRelativeTo(null);
}
private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) {
PanelCotizacion p = new PanelCotizacion();
p.setNumCotizacion(Integer.parseInt(this.txtCotizacion.getText()));
p.setVisible(true);
p.revalidate();
p.updateUI();
this.dispose();
}
}
所以,请不要看sintaxis,如果你可以给我一个想法来解决这个问题,我想也许不中JTextFields将导致显示它是私有的,有没有什么办法来显示它或如何我可以更新jPanel组件以显示更新TextFields吗?非常感谢!
参见[多个JFrames,好/坏习惯的用?(http://stackoverflow.com/a/9554657/418556) –
你只是创建PanelCotization'的'实例除非你在'initComponent()'中做了,但你没有显示,并且我猜是netbeans mattise生成的代码。 – nachokk