/*
* 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について愚かです.. そして、「食べ物の注文」と「飲み物の注文」はウィンドウではなく、ネットビーンでの出力..私の壊れた英語で申し訳ありません。