Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
HELP!!!!! Posted by th1991 on 3 Dec 2012 at 7:39 PM
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 \n 2 cawan beras \n timun san salad \n lada merah","1 bungkus mee kuning \n 15 ekor udang \n sos tiram","2 kilo kerang \n bawang merah \n bawang putih \n 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);
}
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.