/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pbl2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;
public class Main
{
public static void main(String[] args) {
JFrame f = new JFrame("WELCOME TO ULEQ MAYANG CAFE");
f.setSize(1200, 500);
f.setLocation(0, 0);
f.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent we){System.exit(0);}
});
JPanel entreePanel = new JPanel();
final ButtonGroup entreeGroup = new ButtonGroup();
JRadioButton radioButton;
System.out.print("Please Select Your Food : \n\n");
entreePanel.add(radioButton = new JRadioButton("Uleq Fried Chicken(2 Pieces) = RM6.00"));
radioButton.setActionCommand("Uleq Fried Chicken(2 Pieces) = RM6.00");
entreeGroup.add(radioButton);
entreePanel.add(radioButton = new JRadioButton("Uleq Fried Chicken(5Pieces) = RM15.00"));
radioButton.setActionCommand("Uleq Fried Chicken(5Pieces) = RM15.00");
entreeGroup.add(radioButton);
entreePanel.add(radioButton = new JRadioButton("Panera Bread = RM3.00"));
radioButton.setActionCommand("Panera Bread = RM3.00");
entreeGroup.add(radioButton);
entreePanel.add(radioButton = new JRadioButton("Hoka Hoka Bento = RM4.50"));
radioButton.setActionCommand("Hoka Hoka Bento = RM4.50");
entreePanel.add(radioButton = new JRadioButton("Special Uleq Burger = RM6.00"));
radioButton.setActionCommand("Special Uleq Burger = RM6.00");
entreeGroup.add(radioButton);
final JPanel condimentsPanel = new JPanel();
condimentsPanel.add(new JCheckBox("Orange Pulpy = RM3.80"));
condimentsPanel.add(new JCheckBox("Coca Cola = RM2.50"));
condimentsPanel.add(new JCheckBox("Pepsi = RM2.50"));
condimentsPanel.add(new JCheckBox("Mineral Water = RM1.00"));
condimentsPanel.add(new JCheckBox("Special Uleq Latte = RM3.50"));
condimentsPanel.add(new JCheckBox("Ribena = RM2.00"));
condimentsPanel.add(new JCheckBox("Mango Juice = RM3.00"));
JPanel orderPanel = new JPanel();
JButton orderButton = new JButton("THANK YOU FOR PURCHASING AT ULEQ MAYANG CAFE,PLEASE CLICK AND WE WILL PROCEED YOUR ORDER");
orderPanel.add(orderButton);
Container content = f.getContentPane();
content.setLayout(new GridLayout(3, 1));
content.add(entreePanel);
content.add(condimentsPanel);
content.add(orderPanel);
orderButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String entree =
entreeGroup.getSelection().getActionCommand();
System.out.println(entree + " ");
Component[] components = condimentsPanel.getComponents();
for (int i = 0; i < components.length; i++) {
JCheckBox cb = (JCheckBox)components[i];
if (cb.isSelected())
System.out.println("Drinks order:" + cb.getText());
}
}
});
f.setVisible(true);
}
}
// **幫我!!!! * // 我想計算價格,但我不知道..即時通訊愚蠢的關於Java ..和「食品訂單」和「飲料訂單」不顯示在窗口,而是在淨豆的輸出處。對不起,我的英文破碎。無法計算和netbeans的,而不是窗戶面板中顯示輸出
你在哪裏卡住了?什麼讓你困惑? –