1 Star 0 Fork 3

BillchenVip/JAVABASE

forked from wts286010056/JAVABASE 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CoffeeFrame.java 3.13 KB
一键复制 编辑 原始数据 按行查看 历史
package cn.edu.shengda;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CoffeeFrame extends JFrame implements ActionListener {
CoffeeFrame(){
init();
this.setTitle("咖啡");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(0,0,800,600);
this.setVisible(true);
}
public void init(){
radioButtonCoffe=new JRadioButton("咖啡");
radioButtonMilkTea=new JRadioButton("奶茶");
checkBoxMocha=new JCheckBox("摩卡 10");
checkBoxPearl=new JCheckBox("珍珠 15");
checkBoxWhip=new JCheckBox("奶泡 10");
checkBoxChocolate=new JCheckBox("巧克力 20");
labelPrice=new JLabel("价格:");
radioButtonCoffe.addActionListener(this);
radioButtonMilkTea.addActionListener(this);
checkBoxMocha.addActionListener(this);
checkBoxPearl.addActionListener(this);
checkBoxWhip.addActionListener(this);
checkBoxChocolate.addActionListener(this);
add(radioButtonCoffe);
add(radioButtonMilkTea);
add(checkBoxMocha);
add(checkBoxPearl);
add(checkBoxWhip);
add(checkBoxChocolate);
add(labelPrice);
group=new ButtonGroup();
group.add(radioButtonCoffe);
group.add(radioButtonMilkTea);
}
JRadioButton radioButtonCoffe;
JRadioButton radioButtonMilkTea;
JCheckBox checkBoxMocha;
JCheckBox checkBoxPearl;
JCheckBox checkBoxWhip;
JCheckBox checkBoxChocolate;
JLabel labelPrice;
ButtonGroup group;
Beverage beverage;
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(radioButtonCoffe)){
System.out.println("咖啡被选中");
beverage=new DarkRoast();
System.out.println(beverage.getDescription()+"$"+
beverage.cost());
}
if(e.getSource().equals(radioButtonMilkTea)){
System.out.println("奶茶被选中");
beverage=new Espresso();
System.out.println(beverage.getDescription()+"$"+
beverage.cost());
}
if(e.getSource().equals(checkBoxMocha)){
System.out.println("摩卡被选中");
beverage=new Mocha(beverage);
System.out.println(beverage.getDescription()+"$"+
beverage.cost());
}
if(e.getSource().equals(checkBoxPearl)){
System.out.println("珍珠被选中");
}
if(e.getSource().equals(checkBoxWhip)){
System.out.println("奶泡被选中");
beverage=new Whip(beverage);
System.out.println(beverage.getDescription()+"$"+
beverage.cost());
}
if(e.getSource().equals(checkBoxChocolate)){
System.out.println("巧克力被选中");
}
}
public static void main(String[] args){
CoffeeFrame coffeeFrame =new CoffeeFrame();
coffeeFrame.setLayout(new FlowLayout());
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/billchenvip/JAVABASE.git
git@gitee.com:billchenvip/JAVABASE.git
billchenvip
JAVABASE
JAVABASE
master

搜索帮助