Skip to main content

ActionListener function not being called

1 reply [Last post]
lost
Offline
Joined: 2006-09-11

Hi people, i am doing a project on 2D java that require me to create button and add code to the button,i has search for code online and has use the actionlistener method to act code to the button.When i run my program, it seem that the actionPerformed function has not been called up and so when i click on the button, nothing happen. I hope that you all can help me find out error in my coding.Thank You.

CODE :

/*
* IconGlassPanel.java
*
* Created on August 22, 2006, 3:28 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package Pas2DGUI;
import CobraNet.*;
import DbConnection.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JToolBar;

/**
*
* @author staff
*/
public class IconGlassPanel extends JComponent implements MouseListener,ItemListener,ActionListener{
DAOFactory mySqlFactory = DAOFactory.getMySqlDAOFactory();
ZoneDAO zDao = mySqlFactory.getZoneDAO();
boolean iconSelected = false;
Cursor cursor =null;
Zone []zA = zDao.getAllZone();
int totZone = zA.length;
ZoneIcons []iZone = new ZoneIcons[totZone];

// ButtonActionListener al = new ButtonActionListener();

private Image bgImg;
ArrayList iconList = new ArrayList();
private ImageIcon icon;

private JLabel bgImgLabel;
private Image nImg=null;
private Image img;
private Graphics gGlass;
private Cursor customC;
private int selectedIcon = -1;
/** Creates a new instance of BgmPanel */
public IconGlassPanel() {

this.setOpaque(false);
GridBagLayout gbl = new GridBagLayout();
BorderLayout bl = new BorderLayout();
GridBagConstraints c = new GridBagConstraints();
gGlass = this.getGraphics();
initZoneIcon();
//gbl.
setLayout(bl);
JToolBar tb = new JToolBar("Paging Station");
tb.setFloatable(true);
tb.setRollover(true);
tb.setBorderPainted(true);

tb.setLocation(10,10);
tb.setLayout(gbl);
c.weightx = 0.0;
JButton b1 = new JButton("B1");
tb.add(b1,c);
b1.addActionListener(new ButtonActionListener());
JButton b2 = new JButton("B2");
tb.add(b2,c);
b2.addActionListener(new ButtonActionListener());
JButton b3 = new JButton("B3");
tb.add(b3,c);
b3.addActionListener(new ButtonActionListener());
c.gridwidth = GridBagConstraints.REMAINDER;
JButton b4 = new JButton("B4");
tb.add(b4,c);
b4.addActionListener(new ButtonActionListener());
c.gridwidth = GridBagConstraints.REMAINDER;
JButton emergency = new JButton("Emergency");
tb.add(emergency,c);
emergency.addActionListener(new ButtonActionListener());
JButton talk = new JButton("Talk!");
tb.add(talk,c);
talk.addActionListener(new ButtonActionListener());
//setLayout(new GridBagLayout());
bgImg = Toolkit.getDefaultToolkit().getImage("C:\\TEMP\\Airport.jpg");
icon = new ImageIcon(bgImg,"ChangiAirport");
bgImgLabel = new JLabel(icon);
System.out.println("Inside IconGlassPanel paint! totZone="+totZone);
nImg = Toolkit.getDefaultToolkit().getImage("C:\\TEMP\\12.jpg");

add(tb,BorderLayout.SOUTH);

img= Toolkit.getDefaultToolkit().getImage("C:\\TEMP\\Winter.jpg");
addMouseListener(this);
customC = Toolkit.getDefaultToolkit().createCustomCursor(img,new Point(10,10),"ZonePtr");
this.setDoubleBuffered(true);
}
public void paint(Graphics g){
super.paint(g);
/*
System.out.println("Inside IconGlassPanel paint! totZone="+totZone);
Image nImg = Toolkit.getDefaultToolkit().getImage("C:\\EngChuan\\Winter.jpg");
for (int i = 0;i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lost
Offline
Joined: 2006-09-11

hi people, i have solve my problem.Thanks for those that are reading this thread.