Hallo,
ich bekomme bei folgenden Quell Code eine Compiler Fehler.
Ich wollte eine GUI mit dem ActionEvent und EventListener sowie 7 JButtons bedienbar machen, ich bin mir nicht sicher ob ich es überhaubt richtig habe, aber auf jeden Fall liefert der Compiler den Fehler das meine Methode Abstrakt sei. Ich habe aber Schlüsselwort abstrakt gar nicht verwendet.
Irgendwie stehe ich gerade auf dem Schlauch.
ich bekomme bei folgenden Quell Code eine Compiler Fehler.
Ich wollte eine GUI mit dem ActionEvent und EventListener sowie 7 JButtons bedienbar machen, ich bin mir nicht sicher ob ich es überhaubt richtig habe, aber auf jeden Fall liefert der Compiler den Fehler das meine Methode Abstrakt sei. Ich habe aber Schlüsselwort abstrakt gar nicht verwendet.
Irgendwie stehe ich gerade auf dem Schlauch.
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class GridBagLayoutEventHeader implements ActionListener
{
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
JButton bt3 = new JButton("3");
JButton bt4 = new JButton("4");
JButton bt5 = new JButton("5");
JButton bt6 = new JButton("6");
JButton bt7 = new JButton("7");
public void Action()
{
JFrame wrapper = new JFrame();
wrapper.setLocation(500,200);
wrapper.setResizable(true);
wrapper.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = wrapper.getContentPane();
content.setBackground(Color.white);
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
content.setLayout(gbl);
//Zeile 1 Spalte 3
JPanel Z1S3 = new JPanel();
Z1S3.setBackground(Color.gray);
buildConstraints(gbc, 2,0,1,1,100,100);
bt1.addActionListener(this);
gbl.setConstraints(Z1S3, gbc);
Z1S3.add(bt1);
content.add(Z1S3);
//Zeile 2 Spalte 1
JPanel Z2S1 = new JPanel();
Z2S1.setBackground(Color.gray);
buildConstraints(gbc, 0,1,1,1,100,100);
bt2.addActionListener(this);
gbl.setConstraints(Z2S1, gbc);
Z2S1.add(bt2);
content.add(Z2S1);
//Zeile 2 Spalte 2
JPanel Z2S2 = new JPanel();
Z2S2.setBackground(Color.gray);
buildConstraints(gbc, 1,1,1,1,100,100);
bt3.addActionListener(this);
gbl.setConstraints(Z2S2, gbc);
Z2S2.add(bt3);
content.add(Z2S2);
//Zeile 2 Spalte 3
JPanel Z2S3 = new JPanel();
Z2S3.setBackground(Color.gray);
buildConstraints(gbc, 2,1,1,2,100,100);
bt4.addActionListener(this);
gbl.setConstraints(Z2S3, gbc);
Z2S3.add(bt4);
content.add(Z2S3);
//Zeile 3 Spalte 1
JPanel Z3S1 = new JPanel();
Z3S1.setBackground(Color.gray);
buildConstraints(gbc, 0,2,1,2,100,100);
bt5.addActionListener(this);
gbl.setConstraints(Z3S1, gbc);
Z3S1.add(bt5);
content.add(Z3S1);
//Zeile 3 Spalte 2
JPanel Z3S2 = new JPanel();
Z3S2.setBackground(Color.gray);
buildConstraints(gbc, 1,2,1,1,100,100);
bt6.addActionListener(this);
gbl.setConstraints(Z3S2, gbc);
Z3S2.add(bt6);
content.add(Z3S2);
//Zeile 4 Spalte 3
JPanel Z4S3 = new JPanel();
Z4S3.setBackground(Color.gray);
buildConstraints(gbc, 2,3,2,1,100,100);
bt7.addActionListener(this);
gbl.setConstraints(Z4S3, gbc);
Z4S3.add(bt7);
content.add(Z4S3);
}
public void actionPerformed(ActionEvent evt)
{
Object src = evt.getSource();
if(src == bt1) {System.out.println("Frohe");}
else if(src == bt2) {System.out.println("Weihnachten");}
else if(src == bt3) {System.out.println("und");}
else if(src == bt4) {System.out.println("einen");}
else if(src == bt5) {System.out.println("guten");}
else if(src == bt6) {System.out.println("Rutsch");}
else if(src == bt7) {System.out.println("ins neue Jahr");}
}
static GridBagConstraints buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy)
{
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
gbc.insets = new Insets(2,2,2,2);
return gbc;
}
public static void main(String[] arg)
{
Action a = new Action();
a.pack();
a.setVisible(true);
}
}