Create a GUI java program that will allow the user to 1. Choose the option betwe
ID: 3574780 • Letter: C
Question
Create a GUI java program that will allow the user to
1. Choose the option between a Plain shirt or a sweatshirt.
2. Choose if they are getting that shirt in Youth,.Womans or men's.
3. Choose a size, S, M, L, XL, 2XL
4. Choose a color, Black, Blue, Green or Red.
5. Add a custom message to the Shirt
6. Must be a way to confirm this is the shirt they want before ordering.
7. Place the order by entering their First & Last Name, Address and CC info.
8. One of the Colors and two Shirt sizes need to show out of stock.
9. Finally thank the customer by name for their order.
Explanation / Answer
import java.applet.Applet;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Label;
import java.awt.List;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
* <applet code="Shop.class" width="800" height="800"></applet>
*/
public class Shop extends Applet implements ActionListener {
CheckboxGroup type=null;
CheckboxGroup forr=null;
List size=null;
Label sizeout=null;
Label type1,forr1,size1,color1,cmsg,fn,ln,ad,c;
List color=null;
Label colorout=null;
TextField msg=null;
Checkbox cnfrm=null;
TextField fnm=null;
TextField lnm=null;
TextArea address=null;
TextArea cc=null;
Button submit=null;
Label finalmsg=null;
public void init()
{
setLayout(null);
type1=new Label("Type :");
add(type1);
type1.setBounds(10,10, 200, 80);
type=new CheckboxGroup();
Checkbox plain=new Checkbox("Plain Shirt", type, true);
Checkbox sweat=new Checkbox("SweatShirt", type, false);
plain.setBounds(220, 10, 150, 80);
sweat.setBounds(380, 10, 150, 80);
add(plain);
add(sweat);
forr1=new Label("For:");
forr1.setBounds(10, 100, 200,80);
add(forr1);
forr=new CheckboxGroup();
Checkbox young=new Checkbox("Young", forr, true);
Checkbox men=new Checkbox("Men", forr, false);
Checkbox women=new Checkbox("Women", forr, false);
young.setBounds(220, 100, 150, 80);
men.setBounds(380, 100, 150, 80);
women.setBounds(540, 100, 150, 80);
add(young);
add(men);
add(women);
size1=new Label("Size:");
size1.setBounds(10, 190, 200, 80);
add(size1);
size=new List();
size.add("S");
size.add("M");
size.add("L");
size.add("XL");
size.add("2XL");
add(size);
size.setBounds(220, 190, 150, 80);
sizeout=new Label();
sizeout.setBounds(380,190,150,80);
color1=new Label("Color:");
color1.setBounds(10, 280, 200, 80);
add(color1);
color=new List();
color.add("Blue");
color.add("Black");
color.add("Green");
color.add("Red");
add(color);
color.setBounds(220, 280, 150, 80);
colorout=new Label();
colorout.setBounds(380, 280, 150, 80);
cmsg=new Label("Custom message on shirt:");
cmsg.setBounds(10, 370,200, 80);
add(cmsg);
msg=new TextField();
msg.setBounds(220, 370, 150, 80);
add(msg);
cnfrm=new Checkbox("I confirm to purchase this shirt");
cnfrm.setBounds(10,460, 200, 80);
add(cnfrm);
fn=new Label("First Name:");
fn.setBounds(550, 190,100, 80);
add(fn);
fnm=new TextField();
fnm.setBounds(660, 190, 100, 80);
add(fnm);
ln=new Label("last Name");
ln.setBounds(550, 280, 100, 80);
add(ln);
lnm=new TextField();
lnm.setBounds(660, 280, 100, 80);
add(lnm);
ad=new Label("Address:");
ad.setBounds(550,370, 100, 80);
add(ad);
address=new TextArea();
address.setBounds(660, 370, 150, 80);
add(address);
c=new Label("CC info:");
c.setBounds(550, 460, 100, 80);
add(c);
cc=new TextArea();
cc.setBounds(660, 460, 100, 80);
add(cc);
submit=new Button("Submit");
add(submit);
submit.setBounds(700, 550, 70, 50);
finalmsg=new Label();
finalmsg.setBounds(700, 610, 250, 40);
add(finalmsg);
submit.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(!cnfrm.getState())
return;
colorout.setText("");
sizeout.setText("");
if(color.getSelectedItem().equals("Green")){
colorout.setText("Green is not Available");
}
if(size.getSelectedItem().equals("S")){
sizeout.setText("size S is not available");
}
else if(size.getSelectedItem().equals("2XL")){
sizeout.setText("Size 2XL is not available");
}
else
{
finalmsg.setText("Thatk you "+fnm.getText()+" for placing the order");
}
}
}