import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Baby extends JFrame
{
private static final int WIDTH = 600;
private static final int HEIGHT = 500;
private int intBold = Font.PLAIN;
private int intItalic = Font.PLAIN;
private JCheckBox leg1CB, leg2CB, arm1CB,
arm2CB, headCB, torsoCB, faceCB
;
private JRadioButton midgetRB, averageRB, tallRB, giantRB;
private JRadioButton subParRB, parRB, overParRB;
private ButtonGroup babySizeBGroup, babyIntelligenceBGroup;
private JTextArea selectionTextArea;
private JButton priceBabyB;
private JLabel orderL;
private EventHandler eHandler;
public Baby()
{
super("Baby Builder");
Container pane = getContentPane();
setLayout(null);
eHandler = new EventHandler();
leg1CB = new JCheckBox("Left Leg ");
leg2CB = new JCheckBox("Right Leg");
arm1CB = new JCheckBox("Left Arm ");
arm2CB = new JCheckBox("Right Arm ");
headCB = new JCheckBox("Head");
torsoCB = new JCheckBox("Torso");
faceCB = new JCheckBox("Face");
leg1CB.setSize(120, 35);
leg2CB.setSize(120, 35);
arm1CB.setSize(120, 35);
arm2CB.setSize(120, 35);
headCB.setSize(120, 35);
torsoCB.setSize(120, 35);
faceCB.setSize(120, 35);
leg1CB.setLocation(35, 100);
leg2CB.setLocation(35, 125);
arm1CB.setLocation(35, 150);
arm2CB.setLocation(35, 175);
headCB.setLocation(35, 200);
torsoCB.setLocation(35, 225);
faceCB.setLocation(35, 250);
add(leg1CB);
add(leg2CB);
add(arm1CB);
add(arm2CB);
add(headCB);
add(torsoCB);
add(faceCB);
midgetRB = new JRadioButton("Midget: $250", true);
averageRB = new JRadioButton("Average: $350");
tallRB = new JRadioButton("Tall: $500");
giantRB = new JRadioButton("Giant: $800");
midgetRB.setSize(120, 35);
averageRB.setSize(120, 35);
tallRB.setSize(120, 35);
giantRB.setSize(120, 35);
midgetRB.setLocation(220, 90);
averageRB.setLocation(220, 130);
tallRB.setLocation(220, 170);
giantRB.setLocation(220, 210);
babySizeBGroup = new ButtonGroup();
babySizeBGroup.add(midgetRB);
babySizeBGroup.add(averageRB);
babySizeBGroup.add(tallRB);
babySizeBGroup.add(giantRB);
add(midgetRB);
add(averageRB);
add(tallRB);
add(giantRB);
subParRB = new JRadioButton("Sub Par", true);
parRB = new JRadioButton("Par");
overParRB = new JRadioButton("Over Par");
subParRB.setSize(120, 65);
parRB.setSize(120, 65);
overParRB.setSize(120, 65);
subParRB.setLocation(370, 90);
parRB.setLocation(370, 130);
overParRB.setLocation(370, 170);
babySizeBGroup = new ButtonGroup();
babySizeBGroup.add(subParRB);
babySizeBGroup.add(parRB);
babySizeBGroup.add(overParRB);
add(subParRB);
add(parRB);
add(overParRB);
priceBabyB = new JButton("Price my baby~!");
priceBabyB.setSize(250, 50);
priceBabyB.setLocation(240, 255);
add(priceBabyB);
priceBabyB.addActionListener(eHandler);
orderL= new JLabel("Your baby:");
orderL.setSize(100, 30);
orderL.setLocation(40, 300);
add(orderL);
selectionTextArea = new JTextArea();
selectionTextArea.setVisible(true);
selectionTextArea.setSize(525, 100);
selectionTextArea.setLocation(40, 330);
add(selectionTextArea);
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(
Color.blue);
g.setFont(new Font("Ariel", intBold + intItalic, 24));
g.drawString("Hello and welcome to Build Your Baby!", 30, 75);
g.setFont(new Font("Ariel", intBold + intItalic, 12));
g.drawString("Perfect Body Parts", 40, 110);
g.drawString("150$ each", 40, 130);
g.drawRect(30, 90, 170, 240);
g.drawString("Size When Grown", 220, 110);
g.drawRect(200, 90, 160, 180);
g.drawString("Intelligence: 200$ Per Increase", 370, 110);
g.drawRect(360, 90, 200, 180);
}
// left,up,right,Bottom part
private class EventHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double amountDue = 0.0;
String strOut = "";
if (e.getSource() == priceBabyB)
{
strOut += "Intelligence: ";
if (subParRB.isSelected())
{
strOut += "sub par \n";
}
else if (parRB.isSelected())
{
strOut += "par \n";
amountDue += 200;
}
else
{
strOut += "over par \n";
amountDue += 400;
}
strOut += "Body size: ";
if (midgetRB.isSelected())
{
strOut += "small \n";
amountDue += 250;
}
else if (averageRB.isSelected())
{
strOut += "medium \n";
amountDue += 350;
}
else if (tallRB.isSelected())
{
strOut += "large \n";
amountDue += 500;
}
else
{
strOut += "giant \n";
amountDue += 800;
}
strOut += "Perfect Body Parts: ";
if (leg1CB.isSelected())
{
strOut += "left leg, ";
amountDue += 150;
}
if (leg2CB.isSelected())
{
strOut += "right leg, ";
amountDue += 150;
}
if (arm1CB.isSelected())
{
strOut += "left arm, ";
amountDue += 150;
}
if (arm2CB.isSelected())
{
strOut += "right arm, ";
amountDue += 150;
}
if (headCB.isSelected())
{
strOut += "head, ";
amountDue += 150;
}
if (torsoCB.isSelected())
{
strOut += "torso, ";
amountDue += 150;
}
if (faceCB.isSelected())
{
strOut += "face ";
amountDue += 150;
}
strOut += "\nAmount Due: $" + amountDue;
selectionTextArea.setText(strOut);
}
repaint();
}
}
public static void main(String[] args)
{
Baby babyShop = new Baby();
}
}