JtextField auslesen und in JLable einfuegen

  • Themenstarter Themenstarter Huha92
  • Beginndatum Beginndatum
H

Huha92

Gast
Moinsen, im Rahmen meiner Hausaufgabe zu morgen soll ich eine klitzekleine Klasse schreiben, in der ich in einem Fenster ein Standardadressfeld habe, mit TextFields, in denen Name, Nachname, PLZ usw. beschrieben wird. Dies soll nun in einem Ausgabefenster ausgegeben werden, in JLables.

Was habe ich gemacht? Sondierende Methoden der einzelnen Textfelder um den Inhalt zurueckzugeben. (Hauptfenster)
ein Beispiel:
Java:
 public String getNachname(){
        return name.getText();
    }
Und die dazu passende set-Methode im Ausgabefenster:
Java:
    public void setNachname(){
        this.nachname.setText(NewApplication.getNachname());
    }

nun kommt die Fehlermeldung "non-static method can't be referenced from a static context"

habe nun gegooglet, auch http://www.java-forum.org/stichwort...ic-method-cant-referenced-static-context.html gefunden, aber habe wirklich keinerlei Ahnung, wie ich das Problem nun loesen kann...

Waere dankbar, wenn ich eine exakte Erklaerung des Problems bekomme, eine Loesung will ich mir dann schon selbst erarbeiten...

Danke schoen schonmal 🙂
 
NewApplication ist eine Klasse und diese hat keine static Methode die getNachname heist.

Du brauchst eine Instanz der Klasse NewApplication.

D.h.

du hast sicher irgenwo in deinem Code eine zeile die ähnlich aussieht

NewApplication app = new Application();

nun kannst du von app die Methode auffrufen.

app.getNachname
 
Jetzt hab ich es wahrscheinlich da hingesetzt, wo es garnicht hin darf, denn der Compiler meckert nicht mehr, aber uebergeben werden leere Strings... :/
Nun beide Quellcodes direkt:
Mainfenster:

Java:
/*


package p1;

import java.awt.Color;


/**
 *
 * @author Cr
 */
public class NewApplication extends javax.swing.JFrame {
    
    /** Creates new form NewApplication */
    public NewApplication() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lableName = new javax.swing.JLabel();
        labelVorname = new javax.swing.JLabel();
        lableORT = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        titel = new javax.swing.JTextField();
        anrede = new javax.swing.JComboBox();
        name = new javax.swing.JTextField();
        vorname = new javax.swing.JTextField();
        plz = new javax.swing.JTextField();
        ort = new javax.swing.JTextField();
        adresse = new javax.swing.JTextField();
        telefon = new javax.swing.JFormattedTextField();
        handy = new javax.swing.JFormattedTextField();
        btn_ok = new javax.swing.JButton();
        btn_abbord = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Eingabe");

        jLabel1.setText("Titel");

        jLabel2.setText("Anrede");

        lableName.setText("Name");

        labelVorname.setText("Vorname");

        lableORT.setText("PLZ/Ort");

        jLabel6.setText("Adresse");

        jLabel7.setText("Telefon");

        jLabel8.setText("Handy");

        titel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titelActionPerformed(evt);
            }
        });

        anrede.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Anrede", "Herr", "Frau", "Firma" }));
        anrede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                anredeActionPerformed(evt);
            }
        });

        name.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameActionPerformed(evt);
            }
        });

        plz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plzActionPerformed(evt);
            }
        });
        plz.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                plzFocusLost(evt);
            }
        });

        telefon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telefonActionPerformed(evt);
            }
        });

        btn_ok.setText("OK");
        btn_ok.setMaximumSize(new java.awt.Dimension(85, 23));
        btn_ok.setMinimumSize(new java.awt.Dimension(85, 23));
        btn_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_okActionPerformed(evt);
            }
        });

        btn_abbord.setText("Abbrechen");
        btn_abbord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_abbordActionPerformed(evt);
            }
        });

        fileMenu.setText("File");

        openMenuItem.setText("Open");
        fileMenu.add(openMenuItem);

        saveMenuItem.setText("Save");
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText("Save As ...");
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText("Edit");

        cutMenuItem.setText("Cut");
        editMenu.add(cutMenuItem);

        copyMenuItem.setText("Copy");
        editMenu.add(copyMenuItem);

        pasteMenuItem.setText("Paste");
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setText("Delete");
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        helpMenu.setText("Help");

        contentsMenuItem.setText("Contents");
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lableName)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1))
                    .addComponent(labelVorname)
                    .addComponent(lableORT)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vorname, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(plz, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ort, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))
                            .addComponent(adresse, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(telefon, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(handy, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(name, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btn_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btn_abbord))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(anrede, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titel, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(108, 108, 108))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(36, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(anrede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(titel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lableName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(vorname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelVorname))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(plz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lableORT))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(adresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(telefon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(handy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(btn_ok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_abbord))
                .addGap(33, 33, 33))
        );

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

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
        System.exit(0);
    }                                            

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

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

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

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

    private void btn_abbordActionPerformed(java.awt.event.ActionEvent evt) {                                           
        System.exit(0);
    }                                          

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

    private void plzFocusLost(java.awt.event.FocusEvent evt) {                              
        if(plz.getText().length()==5)
        {
            if(!plz.getText().isEmpty())
            {
                try
                {
                    int int1 = Integer.parseInt(plz.getText());
                    plz.setForeground(Color.black);
                }
                catch(Throwable e)
                {
                    fehlerAusgeben1("Dieses Feld erfordert eine numerische Eingabe!");
                    plz.setForeground(Color.red);
                }
            }
        }
        else
        {
            fehlerAusgeben1("Dieses Feld benoetigt exakt 5 Zeichen!");
            plz.setForeground(Color.red);
            //plz.requestFocus();
        }
    }                             

    private void btn_okActionPerformed(java.awt.event.ActionEvent evt) {                                       
        //fehlerBeiOk();
        Ausgabe aus = new Ausgabe();
        aus.setAusgabe();
        aus.setVisible(true);
    }                                      

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

            }
        });

    }

    // Variables declaration - do not modify                     
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JTextField adresse;
    private javax.swing.JComboBox anrede;
    private javax.swing.JButton btn_abbord;
    private javax.swing.JButton btn_ok;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JFormattedTextField handy;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel labelVorname;
    private javax.swing.JLabel lableName;
    private javax.swing.JLabel lableORT;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextField name;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JTextField ort;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JTextField plz;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JFormattedTextField telefon;
    private javax.swing.JTextField titel;
    private javax.swing.JTextField vorname;
    // End of variables declaration                   

    private void fehlerAusgeben1(String fehlertext)
    {
        Fehler fehler = new Fehler(this, false);
        fehler.fehlertextAendern(fehlertext);
        fehler.setVisible(true);
    }

    private void fehlerBeiOk() {
        if(!plz.getText().isEmpty())
        {
            try
            {
                int int1 = Integer.parseInt(plz.getText());
            }
            catch(Throwable e)
            {
                fehlerAusgeben1("Dieses Feld erfordert eine numerische Eingabe!");
            }
        }
        if(telefon.getText().isEmpty()||handy.getText().isEmpty()||adresse.getText().isEmpty()||ort.getText().isEmpty()||titel.getText().isEmpty()||name.getText().isEmpty()||vorname.getText().isEmpty()||plz.getText().isEmpty()){
            fehlerAusgeben1("Bitte alle Pflichtfelder ausfuellen!");
        }

    }



    public String getNachname(){
        return name.getText();
    }
    public String getVorname(){
        return vorname.getText();
    }
    public String getTitel(){
        return titel.getText();
    }
    public String getAdresse(){
        return adresse.getText();
    }
    public String getPLZ(){
        return plz.getText();
    }
    public String getOrt(){
        return ort.getText();
    }
    public String getHandy(){
        return handy.getText();
    }
    public String getTelefon(){
        return telefon.getText();
    }

}
 
Nun dein Code kompiliert bei mir, wenn ich in den Methoden

fehlerAusgeben1 und btn_okActionPerformed auskommentiere, da du ja den SourceCode für die Klassen Fehler und Ausgabe nicht gepostet hast.


Was ist daher dein Frage was funktioniert nicht?
 
Sry, internet war ploetzlich weg :/

Java:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ausgabe.java
 *
 * Created on 06.11.2010, 23:36:20
 */

package p1;

/**
 *
 * @author Cr
 */
public class Ausgabe extends javax.swing.JFrame {

    //Ausgabe aus = new Ausgabe();
    /** Creates new form Ausgabe */
    public Ausgabe() {
        initComponents();


        //setAusgabe();
        setDefaultCloseOperation(Ausgabe.HIDE_ON_CLOSE);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelVorname = new javax.swing.JLabel();
        labelName = new javax.swing.JLabel();
        labelAnrede = new javax.swing.JLabel();
        labelTitel = new javax.swing.JLabel();
        labelORT = new javax.swing.JLabel();
        lableAdresse = new javax.swing.JLabel();
        labelTele = new javax.swing.JLabel();
        labelHandy = new javax.swing.JLabel();
        titel = new javax.swing.JLabel();
        name = new javax.swing.JLabel();
        vorname = new javax.swing.JLabel();
        plz = new javax.swing.JLabel();
        ort = new javax.swing.JLabel();
        adresse = new javax.swing.JLabel();
        telefon = new javax.swing.JLabel();
        handy = new javax.swing.JLabel();
        anrede = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        labelVorname.setText("Vorname");

        labelName.setText("Name");

        labelAnrede.setText("Anrede");

        labelTitel.setText("Titel");

        labelORT.setText("PLZ/Ort");

        lableAdresse.setText("Adresse");

        labelTele.setText("Telefon");

        labelHandy.setText("Handy");

        titel.setText("jLabel3");

        name.setText("jLabel4");

        vorname.setText("jLabel5");

        plz.setText("jLabel9");

        ort.setText("jLabel10");

        adresse.setText("jLabel11");

        telefon.setText("jLabel12");

        handy.setText("jLabel13");

        anrede.setText("jLabel14");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelName)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(labelAnrede)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(labelTitel))
                    .addComponent(labelVorname)
                    .addComponent(labelORT)
                    .addComponent(lableAdresse)
                    .addComponent(labelTele)
                    .addComponent(labelHandy))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(plz, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ort, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                            .addComponent(vorname, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(adresse, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(telefon, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                            .addComponent(handy, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(anrede, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(titel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAnrede)
                    .addComponent(labelTitel)
                    .addComponent(anrede)
                    .addComponent(titel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelName)
                    .addComponent(name))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelVorname)
                    .addComponent(vorname))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelORT)
                    .addComponent(plz)
                    .addComponent(ort))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lableAdresse)
                    .addComponent(adresse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTele)
                    .addComponent(telefon))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelHandy)
                    .addComponent(handy))
                .addGap(62, 62, 62))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

    /**
    * @param args the command line arguments
    */


    // Variables declaration - do not modify                     
    private javax.swing.JLabel adresse;
    private javax.swing.JLabel anrede;
    private javax.swing.JLabel handy;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelAnrede;
    private javax.swing.JLabel labelHandy;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelORT;
    private javax.swing.JLabel labelTele;
    private javax.swing.JLabel labelTitel;
    private javax.swing.JLabel labelVorname;
    private javax.swing.JLabel lableAdresse;
    private javax.swing.JLabel name;
    private javax.swing.JLabel ort;
    private javax.swing.JLabel plz;
    private javax.swing.JLabel telefon;
    private javax.swing.JLabel titel;
    private javax.swing.JLabel vorname;
    // End of variables declaration                   


    public void setAusgabe()
    {
NewApplication app = new Application();

        this.titel.setText(app.getTitel());
        this.name.setText(app.getName());
        this.vorname.setText(app.getVorname());
        this.plz.setText("48222");
        this.ort.setText(app.getOrt());
        this.telefon.setText(app.getTelefon());
        this.handy.setText(app.getHandy());
        this.adresse.setText(app.getAdresse());
    }


}
[/Java]
 
Nun das Problem das du hast ist, dass wenn du wenn du deine setAusgabe aufrufst,
machst du wieder

NewApplication app = new NewApplication();

damit greifst du aber nicht auf das Object zu in dem der User zuvor die eingaben gemacht hast.

Du musst dir eine Refernz des Objects übergeben.

dass machst du am besten in dem du dir in deiner Ausgeben Klasse eine var anlegst

private NewApplication app;

und den Konstruktor so anpasst:
Java:
public Ausgabe(NewApplication t){
  app=t;
  
}

dann kannst du in der setAusgabe()
die Zeile von Oben löschen.

unn musst du nur noch in der Methode btn_okActionPerformed

den Aufruf so schreiben

Ausgabe aus= new Ausgabe(this);
 
ouch. Dankeschoen, mir kam die Zeile in setAusgabe() schon etwas spanisch vor, aber wusste nicht, wo ich sie haette sonst hinschreiben koennen. dankeschoen fuer die Antwort, warum und weshalb konnt ich auch nachvollziehen. =)
 

Neue Themen


Zurück
Oben