• 一个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

  • 相关阅读:
    iOS开发基础-UITableView基本属性
    iOS开发基础-UITableView控件简单介绍
    iOS开发基础-UIScrollView实现图片缩放
    iOS开发基础-UIScrollView基础
    iOS开发基础-序列帧动画之Tom猫
    iOS开发基础-KVC简单介绍
    iOS开发基础-九宫格坐标(6)
    iOS开发基础-九宫格坐标(5)
    iOS开发基础-九宫格坐标(4)
    iOS开发基础-九宫格坐标(3)之Xib
  • 原文地址:https://www.cnblogs.com/chasewade/p/2971633.html
Copyright © 2020-2023  润新知