Also Mein HauptProgramm sieht so aus :
import javax.swing.*;
import java.awt.Color;
import java.awt.*;
import javax.swing.JButton;
import java.awt.event.*;
// ........... und action!
public class elf1 implements ActionListener {
int Tor=0, Versuch=0;
JFrame meinFrame;
JPanel box4, box5, boxSpiel;
Container cp;
GridLayout meineAnordnung;
JLabel meinLabel1,meinLabel2;
JButton Tor1, Tor2, Tor3, Tor4, Tor5, Tor6;
public void aektschen1() {
JWidget11 Tor1 = new JWidget11();
boxSpiel.add(Tor1);
Tor++;
meinLabel1.setText("Tor "+Tor);
}
public void aektschen2() {
Versuch++;
meinLabel2.setText("Versuch "+Versuch);
}
public void actionPerformed(ActionEvent Ereignis) {
if (Ereignis.getSource() == Tor1)
this.aektschen1();
else
this.aektschen2();
}
public void bauAuf() {
meinFrame = new JFrame();
cp = meinFrame.getContentPane();
meineAnordnung = new GridLayout(2,1);
cp.setLayout(meineAnordnung);
JPanel box4 = new JPanel();
box4.setLayout(new GridLayout(2,3));
JPanel box5 = new JPanel();
box5.setLayout(new GridLayout(2,1));
JPanel boxSpiel = new JPanel();
boxSpiel.setLayout(new GridLayout(1,1));
Tor1 = new JButton("1");
Tor1.addActionListener(this);
Tor2 = new JButton("2");
Tor2.addActionListener(this);
Tor3 = new JButton("3");
Tor3.addActionListener(this);
Tor4 = new JButton("4");
Tor4.addActionListener(this);
Tor5 = new JButton("5");
Tor5.addActionListener(this);
Tor6 = new JButton("6");
Tor6.addActionListener(this);
JWidget01 TorAnfang = new JWidget01();
boxSpiel.add(TorAnfang);
cp.add(boxSpiel);
box4.add(Tor1);
box4.add(Tor2);
box4.add(Tor3);
box4.add(Tor4);
box4.add(Tor5);
box4.add(Tor6);
box5.add(box4);
Box box3 = Box.createVerticalBox();
meinLabel1 = new JLabel("Tor ");
meinLabel2 = new JLabel("Vorsuch ");
box3.add(meinLabel1);
box3.add(meinLabel2);
box5.add(box3);
cp.add(box5);
// alles zeigen:
meinFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
meinFrame.setSize(850,670);
meinFrame.setVisible(true);
}
public static void main(String[] arx) {
elf1 gui1 = new elf1();
gui1.bauAuf();
}
}