f



Basic event handling

Can anybody tell me why this isnt working. I get two error both saying 
"cannot find symbol" I have denoted them witha comment



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
  * Write a description of class gridLayout here.
  *
  * @author (your name)
  * @version (a version number or a date)
  */
public class gridLayout extends JFrame implements ActionListener
{
     private JPanel grid = new JPanel( new GridLayout(3, 3));

     public void actionPerformed(ActionEvent event)
     {
         System.out.println("Item: " + event.getActionCammand());
// get an error here saying "cannot find symbol"
         System.out.println("Item: ");
     }

     public gridLayout()
     {
         JPanel panel1 = new JPanel();


         JLabel labelOne = new JLabel("one");
         //labelOne.addActionListener(this);
// get an error here saying "cannot find symbol"
         panel1.add(labelOne);
         grid.add(panel1);


         grid.add(new JButton("2"));
         grid.add(new JButton("3"));
         grid.add(new JButton("4"));
         grid.add(new JButton("5"));
         grid.add(new JButton("6"));
         grid.add(new JButton("7"));
         grid.add(new JButton("8"));
         grid.add(new JButton("9"));

         //JTabbedPane tp = new JTabbedPane();
         //tp.addTab("Grid", grid);
         setContentPane(grid);
         setSize(300,175);
         setVisible(true);
     }
}
0
2/17/2006 1:13:59 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

5 Replies
224 Views

Similar Articles

[PageSpeed] 32

Colin Hemmings wrote:
> Can anybody tell me why this isnt working. I get two error both saying 
> "cannot find symbol" I have denoted them witha comment

>         System.out.println("Item: " + event.getActionCammand());
> // get an error here saying "cannot find symbol"

Spelling error Command, not Cammand.

>         //labelOne.addActionListener(this);
> // get an error here saying "cannot find symbol"

A label doesn't have an addActionListener() method.

/Thomas
-- 
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
0
nobody89 (1641)
2/17/2006 1:23:02 PM
ok, thanks for that, is there not a mouse click event for a label then?

Thomas Weidenfeller wrote:
> Colin Hemmings wrote:
> 
>> Can anybody tell me why this isnt working. I get two error both saying 
>> "cannot find symbol" I have denoted them witha comment
> 
> 
>>         System.out.println("Item: " + event.getActionCammand());
>> // get an error here saying "cannot find symbol"
> 
> 
> Spelling error Command, not Cammand.
> 
>>         //labelOne.addActionListener(this);
>> // get an error here saying "cannot find symbol"
> 
> 
> A label doesn't have an addActionListener() method.
> 
> /Thomas
0
2/17/2006 5:11:53 PM
Colin Hemmings <colin.hemmings1@ntlworld.com> wrote in news:ttnJf.5118
$bw1.4887@newsfe2-win.ntli.net:

> ok, thanks for that, is there not a mouse click event for a label then?
> 

use Component:addMouseListener(MouseListener)
0
zero15 (442)
2/17/2006 6:02:02 PM
On Fri, 17 Feb 2006 13:13:59 GMT, Colin Hemmings
<colin.hemmings1@ntlworld.com> wrote, quoted or indirectly quoted
someone who said :

>  JLabel labelOne = new JLabel("one");
>         //labelOne.addActionListener(this);
>// get an error here saying "cannot find symbol"

JLabels are inert things. They don't generate
 ActionEvents. Perhaps you meant JButton?
-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
0
2/18/2006 10:31:52 PM
Colin Hemmings wrote:
> ok, thanks for that, is there not a mouse click event for a label then?

The API documentation easily answers such questions.

/Thomas
0
nobody89 (1641)
2/20/2006 9:01:44 AM
Reply: