tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
322
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    sunmania sunmania ist offline Mitglied
    Registriert seit
    Jun 2007
    Beiträge
    24
    Hallo,

    ich habe 2 Fenster programmiert. Das erste Fenster hat einen Start-Button, mit dem man das zweite Fenster öffnen kann. Wenn man dann das zweite Fenster schließt, dann schließen beide Fenster. Ich möchte aber das zweite Fenster schließen, ohne dass das erste Fenster dabei geschlossen wird.

    Fenster 1:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    
    public class NewJFrame extends javax.swing.JFrame {
        
        /** Creates new form NewJFrame */
        public NewJFrame() {
            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">//GEN-BEGIN:initComponents
        private void initComponents() {
     
            jButton1 = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jButton1.setText("START");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jButton1)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jButton1)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>//GEN-END:initComponents
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame1().setVisible(true);
                }
            });
        }//GEN-LAST:event_jButton1ActionPerformed
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JButton jButton1;
        // End of variables declaration//GEN-END:variables
        
    }

    Fenster 2:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    public class NewJFrame1 extends javax.swing.JFrame {
        
        /** Creates new form NewJFrame1 */
        public NewJFrame1() {
            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">//GEN-BEGIN:initComponents
        private void initComponents() {
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>//GEN-END:initComponents
        
        /**
         * @param args the command line arguments
         */
     
        
        // Variables declaration - do not modify//GEN-BEGIN:variables
        // End of variables declaration//GEN-END:variables
        
    }

    danke

    gruss
     

  2. #2
    Avatar von Matze
    Matze Matze ist offline Weltenwanderer
    Registriert seit
    Jul 2007
    Ort
    Die Welt
    Beiträge
    1.504
    Blog-Einträge
    7
    Versuch mal ob es klappte, wenn du die Zeile
    Code java:
    1
    
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    aus dem Code des 2. Fensters rausnimmst.
     
    "... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)

    "Sir?, we're sorrounded!"
    "Excellent, we can attack in any direction"

Ähnliche Themen

  1. fenster schließen
    Von Steffilove im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 8
    Letzter Beitrag: 30.03.07, 12:51
  2. [c++] Fenster schließen
    Von haribald im Forum C/C++
    Antworten: 3
    Letzter Beitrag: 12.10.06, 09:04
  3. Fenster schließen
    Von Tunemaster im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 7
    Letzter Beitrag: 21.06.05, 12:03
  4. Link in altem Fenster öffnen + Fenster schließen
    Von PhoenixDH im Forum Javascript & Ajax
    Antworten: 17
    Letzter Beitrag: 08.09.04, 22:10
  5. Fenster öffnen, Inhalt drucken, Fenster schließen
    Von dermac'z im Forum Javascript & Ajax
    Antworten: 8
    Letzter Beitrag: 02.07.04, 15:44