Ich hab ein GUI programmiert aber wirft iwie kein event aus warum?!
LISTENER
MENUGUI mit Buttons
Die Konsole ausgaben beim Buttonclick funktioniert nicht wo ist der fheler hab ich was übersehen!?
LISTENER
Java:
package Listener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import GraphicUserInterface.ContentPanel;
public class MenuListener implements ActionListener
{
ContentPanel content = null;
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
JButton button = (JButton) arg0.getSource();
if (button.getText().equals("Create new Contact"))
{
System.out.println("Create a new Contact");
}
if (button.getText().equals("Edit Contact"))
{
System.out.println("Edit Contact");
}
if (button.getText().equals("Delete Contact"))
{
System.out.println("Delete Contact");
}
if (button.getText().equals("Search Contact"))
{
System.out.println("Search Contact");
}
if (button.getText().equals("Import Addressbook"))
{
System.out.println("Import Addressbook");
}
if (button.getText().equals("Export Addressbook"))
{
System.out.println("Export Addressbook");
}
}
public void setContent(ContentPanel content) {
this.content = content;
}
}
MENUGUI mit Buttons
Java:
package GraphicUserInterface;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import Listener.MenuListener;
public class MenuPanel extends JPanel
{
JButton[] button = new JButton[6];
String[] buttonName = new String[] {"Create new Contact", "Edit Contact", "Delete Contact", "Search Contact", "Import Addressbook", "Export Addressbook" };
String[] buttonPfad = new String[] { "contact-new.png", "edit-paste.png", "emblem-unreadable.png", "system-search.png", "document-open.png", "document-save.png" };
MenuListener menuListener = new MenuListener();
ContentPanel content = null;
public MenuPanel()
{
GridLayout layout = new GridLayout(6,1);
setLayout(layout);
for (int i=0; i<button.length; i++)
{
button[i] = new JButton(new ImageIcon("Icons/" + buttonPfad[i]));
button[i].setToolTipText(buttonName[i]);
button[i].setPreferredSize(new Dimension(75,45));
button[i].addActionListener(menuListener);
add(button[i]);
}
}
public void setContent(ContentPanel content) {
this.content = content;
menuListener.setContent(content);
}
}
Die Konsole ausgaben beim Buttonclick funktioniert nicht wo ist der fheler hab ich was übersehen!?