Hi hab folgendes Problem, ich habe ein Frame aus dem ich einen Dialog aufrufe.
Im Dialog adde ich ein Panel. Auf dem Panel liegen zwei Textfields und Button. Jetzt wartet er da oben im aufrufenden Frame.
Die init des Panels (also das Panel selbst) ist eine Klasse. Wird instanziert und dem Dialog hinzugefügt.
Wie kann ich erreichen. Das ich nach dem drücken des Buttons die Texteingaben in mein Frame bekomme. Ich will an die Informationen dort rankommen.
Zur Zeit mache ich es so. Das ich nach dem Buttonklick dispose() aufrufe. Dann sind die Informationen auch da. Die hole ich über getMethoden raus. Ich verstehe es aber nicht, warum nach dispose() die Texteingaben noch da sind. Bin mir nicht sicher ob es richtig ist was ich da mache.
Das ist der Code dazu:
Code:
Draht_Input_Dialog id = new Draht_Input_Dialog(this, "Input", true);
String manuNennD = did.getInputNennD();
String manuMaxD = did.getInputMaxD();
System.out.println(manuNennD);
System.out.println(manuMaxD);
Im Dialog adde ich ein Panel. Auf dem Panel liegen zwei Textfields und Button. Jetzt wartet er da oben im aufrufenden Frame.
Die init des Panels (also das Panel selbst) ist eine Klasse. Wird instanziert und dem Dialog hinzugefügt.
Wie kann ich erreichen. Das ich nach dem drücken des Buttons die Texteingaben in mein Frame bekomme. Ich will an die Informationen dort rankommen.
Zur Zeit mache ich es so. Das ich nach dem Buttonklick dispose() aufrufe. Dann sind die Informationen auch da. Die hole ich über getMethoden raus. Ich verstehe es aber nicht, warum nach dispose() die Texteingaben noch da sind. Bin mir nicht sicher ob es richtig ist was ich da mache.
Das ist der Code dazu:
Code:
public class Draht_Input_Dialog extends JDialog {
public DrahtInput di = new DrahtInput();
/** Creates a new instance of Draht_Dialog */
public Draht_Input_Dialog(JFrame MainWindow, String msg, boolean modal) {
super(MainWindow, msg, true); //true steht für modalen Dialog
Point par = MainWindow.getLocation();
//this.setLocation(par.x + 100, par.y +160);
this.setSize(400, 250);
Dimension d = new Dimension();
d = MainWindow.getSize(); //Bildschirmauflösung ermitteln
double hight = d.getHeight(); //Höhe rausziehen
int y = (int)((hight/2)-(this.getSize().getHeight()/2)); //Dialog muss in die Mitte des Bildschirms positioniert werden
double width = d.getWidth(); //Breite rausziehen
int x = (int)((width/2)-(this.getSize().getWidth()/2));
this.setLocation(x,y); //Positionieren
this.setResizable(false);
this.setLayout(new GridLayout(1,1));
//DrahtInput di = new DrahtInput();
this.add(di);
this.setVisible(true);
}
public String getInputNennD(){
String manuNennD = di.getInputNennD();
return manuNennD;
}
public String getInputMaxD(){
String manuMaxD = di.getInputMaxD();
return manuMaxD;
}
public class DrahtInput extends javax.swing.JPanel {
private String manuNennD;
private String manuMaxD;
/** Creates new form DrahtInput */
public DrahtInput() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel_NennD = new javax.swing.JLabel();
jLabel_MaxD = new javax.swing.JLabel();
jTextField_NennDD = new javax.swing.JTextField();
jTextField_MaxDD = new javax.swing.JTextField();
jButton_Uebernehmen = new javax.swing.JButton();
jButton_Abbrechen = new javax.swing.JButton();
setBackground(new java.awt.Color(204, 204, 204));
jLabel_NennD.setFont(new java.awt.Font("Arial", 0, 12));
jLabel_NennD.setText("Nenn Drahtdurchmesser :");
jLabel_MaxD.setFont(new java.awt.Font("Arial", 0, 12));
jLabel_MaxD.setText("Max. Drahtdurchmesser :");
jButton_Uebernehmen.setFont(new java.awt.Font("Arial", 0, 12));
jButton_Uebernehmen.setText("\u00dcbernehmen");
jButton_Uebernehmen.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton_UebernehmenMouseClicked(evt);
}
});
jButton_Abbrechen.setFont(new java.awt.Font("Arial", 0, 12));
jButton_Abbrechen.setText("Abbrechen");
jButton_Abbrechen.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton_AbbrechenMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(87, 87, 87)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel_NennD)
.addComponent(jLabel_MaxD))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField_NennDD)
.addComponent(jTextField_MaxDD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton_Uebernehmen)
.addGap(8, 8, 8)
.addComponent(jButton_Abbrechen, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)))
.addGap(91, 91, 91))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel_NennD, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField_NennDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField_MaxDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel_MaxD, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton_Uebernehmen)
.addComponent(jButton_Abbrechen))
.addContainerGap(67, Short.MAX_VALUE))
);
}// </editor-fold>
private void jButton_AbbrechenMouseClicked(java.awt.event.MouseEvent evt) {
dispose();
}
private void jButton_UebernehmenMouseClicked(java.awt.event.MouseEvent evt) {
manuNennD = jTextField_NennDD.getText();
manuMaxD = jTextField_MaxDD.getText();
dispose();
}
public String getInputNennD(){
return manuNennD;
}
public String getInputMaxD(){
return manuMaxD;
}
// Variables declaration - do not modify
private javax.swing.JButton jButton_Abbrechen;
private javax.swing.JButton jButton_Uebernehmen;
private javax.swing.JLabel jLabel_MaxD;
private javax.swing.JLabel jLabel_NennD;
private javax.swing.JTextField jTextField_NennDD;
private javax.swing.JTextField jTextField_MaxDD;
// End of variables declaration
}
}