Variablen von einer in andere Funktion

BassSportler

Grünschnabel
Hey,
ich spiele grad bissl mit Java rum und versuche ein Applet zu machen, das wenn man auf eine Knopf drückt etwas anzeigt.
Java:
public void init() {
        Container left = new Container();
        Container top = new Container();
        Container center = new Container();
        
        setSize(800,600);
        
        ActionListener aktion = new Knopfdruck();
        
        BorderLayout all = new BorderLayout(10,10);
        GridLayout menu = new GridLayout(6,1,5,5);
        setLayout(all);
        left.setLayout(menu);
        top.setLayout(new BorderLayout());
        center.setLayout(new FlowLayout());
        
        add("West",left);
        add("North",top);
        add("Center",center);
        
        JButton gp1, gp2, fp, tex, misc, res;
        JLabel headline, content;
        
        headline = new JLabel("mrmz.ohost.de");
        headline.setFont(new Font("Arial", Font.BOLD,18));
        headline.setForeground(Color.RED);
        top.add("East", headline);
        
        gp1 = new JButton("GP1-Protokolle");
        left.add(gp1);
        gp1.addActionListener(aktion);
    gp1.setActionCommand("showgp1");
        
        gp2 = new JButton("GP2-Protokolle");
        left.add(gp2);
        
        fp = new JButton("FP-Protokolle");
        left.add(fp);
        
        tex = new JButton("UltraEdit LaTeX-Files");
        left.add(tex);
        
        misc = new JButton("Misc");
        left.add(misc);
        
        res = new JButton("restricted");
        left.add(res);
        
        content = new JLabel("");
        center.add(content);
        
    }
Konkret z.B. wenn ich auf Burron "gp1" klinke soll ein neues Label im Container "center" erscheinen etc.
Dafür muss ich ja bei der GP1Clicked()-Methode auf die Variablennamen "center" und "content" zugreifen, was ja eig. nicht geht. Weiß da vll. jemand abhilfe?
 
Zurück