Weiteren Frame öffnen

JHounter

Grünschnabel
Huhu,

ich habe ein Java AWT Frame auf dem sich ein Button befindet und ich möchte, das wenn man den Button klickt, das sich ein weiterer neuer Frame öffnet.

Ich bekomme das leider nicht auf die reihe, kann mir bitte jemand weiter helfen?

Als IDE benutze ich den JavaEditor
 
Du packst einen ActionListener auf den Button, implementiert die actionPerformed Methode und erstellt darin einen neuen Frame und zeigst diesen an.
 
Hallo,

ich nutze jetzt NetBeans ...

Ich habe einen Frame (NewFrame.java) mit einem Button drauf, wenn man den Button klickt, soll der Dialog (NewDialog.java) geöffnet werden.

Wie mach ich das denn?

Code:
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
  NewDialog.getWindows();
}

Das Packet (package javaapplication2;) ist ja drin, aber es geht nicht :(
 
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onlineapplication;

/**
 *
 * @author Kevin
 */
public class Main extends Hauptfenster {
    public Main()
    {
        super();
        setVisible(true);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Main  frame = new Main();
    }

}

Die Main Klasse ruft jetzt den Frame (Hauptfenster)

Code:
/*
 * Hauptfenster.java
 *
 * Created on 1. Mai 2008, 18:56
 */

package onlineapplication;

/**
 *
 * @author  Kevin
 */
public class Hauptfenster extends java.awt.Frame {

    /** Creates new form Hauptfenster */
    public Hauptfenster() {
        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() {

        button1 = new java.awt.Button();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        button1.setLabel("button1");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(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(32, 32, 32)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(190, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(129, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {                          
        System.exit(0);
    }                         

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Hauptfenster().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify
    private java.awt.Button button1;
    // End of variables declaration

}

Der Button soll jetzt den Dialog "Bereich" öffnen, wie mach ich das?
 
Zuletzt bearbeitet:
Genauso wie man es sonst auch macht.

Java:
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Bereich bereich = new Bereich();
bereich.setVisible(true);
}

Vielleicht solltest du nochmal ein wenig was über Java im allgemeinen nachlesen. Online gibts da schöne Bücher zu.
 
Zurück