Basic event handling

C

Colin Hemmings

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);
}
}
 
T

Thomas Weidenfeller

Colin said:
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
 
R

Roedy Green

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?
 
T

Thomas Weidenfeller

Colin said:
ok, thanks for that, is there not a mouse click event for a label then?

The API documentation easily answers such questions.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,841
Latest member
WilmerBelg

Latest Threads

Top