can't do this.. can anyone check it out pleaseeee? thank you =)

import javax.swing.*;

import java.awt.event.*;

publicclass Cookingimplements ActionListener{

JFrame frame;

JPanel contentPane;

JLabel label;

JButton button;

public Cooking(){

frame =new JFrame("Cooking");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

contentPane =new JPanel();

contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));

contentPane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));

button =new JButton(new ImageIcon("spaghetti.jpg"));

button.setAlignmentX(JButton.LEFT_ALIGNMENT);

button.addActionListener(this);

contentPane.add(button);

label =new JLabel(" ");

label.setAlignmentX(JLabel.LEFT_ALIGNMENT);

label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

contentPane.add(label);

frame.setContentPane(contentPane);

frame.pack();

frame.setVisible(true);

}

publicvoid actionPerformed(ActionEvent event){

String eventName = event.getActionCommand();

if (eventName.equals("spaghetti.jpg")){

label.setText("Recipe: (for 10 servings)");

label.setText("500 g of magaroni, 100 g of garlic, 500 g of chopped chicken, 250 g of tomato sauce, 1 kg of tomatoes, 250 g of onions, 500 g of mushroom, 100 g of olive oil, 50 g of butter");

}

}

privatestaticvoid runGUI(){

JFrame.setDefaultLookAndFeelDecorated(true);

Cooking food =new Cooking();

}

publicstaticvoid main(String[] args){

javax.swing.SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

runGUI();

}

});

}

}

[3192 byte] By [wiwia] at [2007-11-27 5:16:20]
# 1
the text supposed to show up when you click the spaghetti button... that's it.. = =when i click.. no text showed up ..Message was edited by: wiwi
wiwia at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...
# 2
Can't do what?
abillconsla at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...
# 3
button.setActionCommand(...);
Hippolytea at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...
# 4

Well the obvious thing is that you check for an action command of "spaghetti.jpg", but you never specify that is the command on the button.

The ImageIcon just loads that image file. The button class does not do anything except use the icon, it doesn't know the name of the file used. It can't get that information anyway.

bsampieria at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...
# 5
Are you sure you want to write spaghetti code?;-)
Hippolytea at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...
# 6
hey!!! thank you so much!!i was so careless, i thought i had that already.. = =anyway, thank you for all your help !! =D
wiwia at 2007-7-12 10:38:54 > top of Java-index,Java Essentials,New To Java...