[color=Black][size=2]how to show the ingredients for each recipe???
or how to write the action listener for a jlist???
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class ques1 extends JFrame
{
JButton jbtView;
JList menuList;
JTextArea jtfRecipe;
JPanel p1,p2,p3;
String[] listContent={"Nasi Ayam","Mee Goreng","Rendang Karang"};
String[] recipe={"1 ekor ayam
2 cawan beras
timun san salad
lada merah","1 bungkus mee kuning
15 ekor udang
sos tiram","2 kilo kerang
bawang merah
bawang putih
rempah"};
public ques1()
{
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
jbtView = new JButton("View Secret Ingredient");
menuList = new JList(listContent);
jtfRecipe = new JTextArea(5,20);
jtfRecipe.setEditable(false);
p1 = new JPanel();
p1.add(menuList);
p2 = new JPanel();
p2.add(jbtView);
p3 = new JPanel();
p3.add(jtfRecipe);
pane.add(p1,"North");
pane.add(p2,"Center");
pane.add(p3,"South");
jbtView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String output = jtfRecipe.getText();
if (jbtView.isSelected())
{
if (e.getActionCommand().equals("View Secret Ingredient"))
{
int index = menuList.getSelectedIndex();
jtfRecipe.setText(output);
}
}
}
});
}
public static void main (String []args)
{
ques1 frame = new ques1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("MasterChef");
//frame.setSize(300,240);z
frame.pack();
frame.setVisible(true);
}
}
[size=2][color=Black][/color][/size][/size][/color]