actionlistener - ingen reaktion
Hej eksperter :)har følgende java kode til min GUI side:
package betalingsnet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUIForside implements ActionListener {
private JFrame frame;
private static ImageIcon topLogo;
private static JLabel logoLabel;
private JButton button1;
public static void main(String[] args) {
GUIForside gui = new GUIForside();
}
public GUIForside()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension (1016,600));
frame.setTitle("Über Banke forside");
// BorderLayout til det ydre design
frame.setLayout(new BorderLayout());
// Top logoet - Sættes til NORTH i BorderLayout
topLogo = new ImageIcon("topLogo.png");
logoLabel = new JLabel(topLogo);
frame.add(logoLabel, BorderLayout.NORTH);
// Menu punkter - centerpanel
JPanel centerPanel = new JPanel(new FlowLayout());
JButton button1 = new JButton();
button1.setIcon(new ImageIcon("button1.png"));
button1.addActionListener(this);
JButton button2 = new JButton();
button2.setIcon(new ImageIcon("button1.png"));
JButton button3 = new JButton();
button3.setIcon(new ImageIcon("button1.png"));
JButton button4 = new JButton();
button4.setIcon(new ImageIcon("button1.png"));
JButton button5 = new JButton();
button5.setIcon(new ImageIcon("button1.png"));
centerPanel.add(new JLabel(" "));
centerPanel.add(button1);
centerPanel.add(button2);
centerPanel.add(button4);
centerPanel.add(button5);
centerPanel.add(new JLabel(" "));
frame.add(centerPanel, BorderLayout.CENTER);
// Nederste del af siden - Sættes som South
JPanel southPanel = new JPanel(new BorderLayout());
southPanel.add(new JLabel(" North! "), BorderLayout.NORTH);
southPanel.add(new JLabel(" South! "), BorderLayout.SOUTH);
southPanel.add(new JLabel(" Center! "), BorderLayout.CENTER);
southPanel.add(new JLabel(" East! "), BorderLayout.EAST);
southPanel.add(new JLabel(" West! "), BorderLayout.WEST);
frame.add(southPanel, BorderLayout.SOUTH);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == button1)
{
frame.dispose();
}
}
}
Nogen ide om hvorfor actionlisteneren ikke fungerer?
Har ingen fejlmeddelelser o.l.