一个java点菜程序

本博客介绍了一个简单的Java程序,通过随机选择功能,实现自动为用户点菜的功能。程序包括用户界面设计,使用按钮触发随机选择,并展示三种不同菜品的示例。
 1 import java.awt.event.ActionEvent;
 2 import java.awt.event.ActionListener;
 3 import java.util.Random;
 4 
 5 import javax.swing.JButton;
 6 import javax.swing.JFrame;
 7 import javax.swing.JLabel;
 8 import javax.swing.JPanel;
 9 
10 /** 
11  * @author Chase QQ: 594126573
12  * @version 创建时间:2011-12-17   下午04:37:40
13  * 点菜机 有时候不知道要吃啥 所以琢磨这这个东西  抽到什么就吃什么吧 嘿嘿
14 *  下个版本出  带数据库的
15  */
16 
17 public class chaocai extends JFrame {
18 
19     public chaocai() {
20         setTitle("自动菜单");
21         JPanel panel = new JPanel();
22         
23         JButton b1 = new JButton("点击");
24         b1.setBounds(100, 300, 100, 50);
25         panel.add(b1);
26         
27         JLabel l1 = new JLabel("第一道菜:");
28         l1.setBounds(30, 25, 60, 25);
29         panel.add(l1);
30         
31         final JLabel l2 = new JLabel("");
32         l2.setBounds(90, 25, 100, 25);
33         panel.add(l2);
34         
35         JLabel l3 = new JLabel("第二道菜:");
36         l3.setBounds(30, 50, 60, 25);
37         panel.add(l3);
38         
39         final JLabel l4 = new JLabel("");
40         l4.setBounds(90, 50, 100, 25);
41         panel.add(l4);
42         
43         JLabel l5 = new JLabel("第三道菜:");
44         l5.setBounds(30, 75, 60, 25);
45         panel.add(l5);
46         
47         final JLabel l6 = new JLabel("");
48         l6.setBounds(90, 75, 100, 25);
49         panel.add(l6);
50         
51         panel.setLayout(null);
52         this.setBounds(300, 400, 300, 400);
53         this.add(panel);
54         this.setVisible(true);
55         
56         /**
57          * 为点击按钮添加监听事件
58          */
59         b1.addActionListener(new ActionListener() {
60             public void actionPerformed(ActionEvent e) {
61                 l2.setText(choose1());
62                 l4.setText(choose2());
63                 l6.setText(choose3());
64             }
65             
66         }); 
67     }
68     
69     public static String choose1() {
70         String[] caidan1 = {"香干回锅肉","攸县香干","老干妈回锅肉"};
71         Random random = new Random();
72         int nextInt = random.nextInt(caidan1.length);
73         return caidan1[nextInt];
74     }
75     
76     public static String choose2() {
77         String[] caidan1 = {"牛腩粉","牛丸粉","红烧肉粉"};
78         Random random = new Random();
79         int nextInt = random.nextInt(caidan1.length);
80         return caidan1[nextInt];
81     }
82     
83     public static String choose3() {
84         String[] caidan1 = {"青菜肉片汤","西红柿蛋汤","三鲜汤"};
85         Random random = new Random();
86         int nextInt = random.nextInt(caidan1.length);
87         return caidan1[nextInt];
88     }
89     
90      public static void main(String args[]){
91          new chaocai();
92     }
93     
94 }

更多:http://www.dream-chase.com

转载于:https://www.cnblogs.com/chasewade/archive/2013/03/20/2971633.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值