this is a small program for sell and ordering in a cake store.it is based on user interface with java. i add a lable of all cakes of this store, but when i execute it,i cannot see the lable on the screen. could you help me to find the problems? thank you so much.
the following is the program.
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
/**
* Title: Sales class
* Description: used to perform sales of bakery shop
* Company: Informatics
* @author Chentong
* @version 1.0 2002.3
*/
interface Items{
public static final int CAKE=1;
public static final int PASTRY=10;
public static final int COOKIES=20;
//ware category and number definition;
public static final int C1_NUM=2;
public static final int C2_NUM=4;
public static final int C3_NUM=2;
public static final int P1_NUM=20;
public static final int P2_NUM=20;
public static final int K1_NUM=100;
public static final int K2_NUM=100;
//ware cost price definition;
public static final double C1_COST_PRI=20.00;
public static final double C2_COST_PRI=16.00;
public static final double C3_COST_PRI=12.00;
public static final double P1_COST_PRI=0.50;
public static final double P2_COST_PRI=0.40;
public static final double K1_COST_PRI=0.20;
public static final double K2_COST_PRI=0.30;
//ware selling price definition;
public static final double C1_SELL_PRI=36.00;
public static final double C2_SELL_PRI=30.00;
public static final double C3_SELL_PRI=28.00;
public static final double P1_SELL_PRI=1.20;
public static final double P2_SELL_PRI=1.20;
public static final double K1_SELL_PRI=0.70;
public static final double K2_SELL_PRI=0.80;
}
class Sales implements Items{
public static int C1_REM;
public static int C2_REM;
public static int C3_REM;
public static int P1_REM;
public static int P2_REM;
public static int K1_REM;
public static int K2_REM;
public static int C1_SOLD;
public static int C2_SOLD;
public static int C3_SOLD;
public static int P1_SOLD;
public static int P2_SOLD;
public static int K1_SOLD;
public static int K2_SOLD;
public static int temp;
public static void init(){
C1_SOLD=0;
C2_SOLD=0;
C3_SOLD=0;
P1_SOLD=0;
P2_SOLD=0;
K1_SOLD=0;
K2_SOLD=0;
C1_REM=C1_NUM;
C2_REM=C2_NUM;
C3_REM=C3_NUM;
P1_REM=P1_NUM;
P2_REM=P2_NUM;
K1_REM=K1_NUM;
K2_REM=K2_NUM;}
public Sales(){
}
public int getre(){return P1_REM;}
public void saleware(String prodcod,int prodquan){
temp=0;
String alert="Your order is too large, we can't afford all,please collect your order at evening";
String alertlessmin="Your order is smaller than our minimal reorder quantity, you can't finished your reorder, but your order is sucessed";
if(prodcod.equalsIgnoreCase("[c1] Cheese"){
if(prodquan>C1_REM) {
if((prodquan-C1_REM)<CAKE) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);C1_SOLD=C1_REM;C1_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);C1_SOLD=C1_REM;C1_REM=0;temp=1;}
}
if(prodquan<=C1_REM){ C1_REM-=prodquan;C1_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[c2] Chocolate"){
if(prodquan>C2_REM){
if((prodquan-C2_REM)<CAKE) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);C2_SOLD=C2_REM;C2_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);C2_SOLD=C2_REM;C2_REM=0;temp=2;}
}
if(prodquan<=C2_REM){ C2_REM-=prodquan;C2_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[c3] Strawberry"){
if(prodquan>C3_REM){
if((prodquan-C3_REM)<CAKE) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);C3_SOLD=C3_REM;C3_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);C3_SOLD=C3_REM;C3_REM=0;temp=3;}
}
if(prodquan<=C3_REM){ C3_REM-=prodquan;C3_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[p1] Egg"){
if(prodquan>P1_REM){
if((prodquan-P1_REM)<PASTRY) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);P1_SOLD=P1_REM;P1_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);P1_SOLD=P1_REM;P1_REM=0;temp=4;}
}
if(prodquan<=P1_REM){ P1_REM-=prodquan;P1_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[p2] Pineapple"){
if(prodquan>P2_REM){
if((prodquan-P2_REM)<PASTRY) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);P2_SOLD=P2_REM;P2_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);P2_SOLD=P2_REM;P2_REM=0;temp=5;}
}
if(prodquan<=P2_REM){ P2_REM-=prodquan;P2_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[k1] Pecan and Nuts"){
if(prodquan>K1_REM){
if((prodquan-K1_REM)<COOKIES) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);K1_SOLD=K1_REM;K1_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);K1_SOLD=K1_REM;K1_REM=0;temp=6;}
}
if(prodquan<=K1_REM){ K1_REM-=prodquan;K1_SOLD+=prodquan;}
}
if(prodcod.equalsIgnoreCase("[k2] Chocolate chips"){
if(prodquan>K2_REM){
if((prodquan-K2_REM)<COOKIES) {JOptionPane.showMessageDialog(null,alertlessmin,"Alert!",0);K2_SOLD=K2_REM;K2_REM=0;}
else {JOptionPane.showMessageDialog(null,alert,"Alert!",0);K2_SOLD=K2_REM;K2_REM=0;temp=7;}
}
if(prodquan<=K2_REM){ K2_REM-=prodquan;K2_SOLD+=prodquan;}
}
}
}
class Drawwindow extends Sales
implements Items{
public static JFrame aWindow=new JFrame("bakery shop manager"
public static Toolkit tools=aWindow.getToolkit();
public static Dimension wndSize=tools.getScreenSize();
public static Drawwindow inswindow=new Drawwindow();
public static Sales inssale = new Sales();
Container content=aWindow.getContentPane();
JMenuItem restart,about,exit;
JMenuBar menuBar=new JMenuBar();
JMenu choiceMenu=new JMenu("Menu"
JMenu otherMenu=new JMenu("About"
JButton mainbutton;
JPanel bottomPanel=new JPanel();
Border edge=BorderFactory.createRaisedBevelBorder();
public static Dimension size=new Dimension(80,20);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
Font myfont1 = new Font("Arial",Font.BOLD,12);
Drawwindow(){aWindow.setVisible(true);}
public void diswin(int c1_rem,
int c2_rem,
int c3_rem,
int p1_rem,
int p2_rem,
int k1_rem,
int k2_rem,int choice){
aWindow.setJMenuBar(menuBar);
restart=choiceMenu.add("restart"
about=choiceMenu.add("about"
exit=choiceMenu.add("exit"
choiceMenu.setMnemonic('M');
otherMenu.setMnemonic('A');
menuBar.add(choiceMenu);
menuBar.add(otherMenu);
content.setLayout(new BorderLayout());
content.add(bottomPanel,BorderLayout.SOUTH);
aWindow.setBounds(0,0,wndSize.width,wndSize.height-50);
aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
aWindow.getContentPane().setLayout(gridbag);
constraints.weightx = constraints.weighty = 10;
constraints.fill = constraints.HORIZONTAL;
constraints.insets = new Insets(0,0,0,0);
aWindow.getContentPane().setLayout(gridbag);
addlabel("Famouse Barkery, Mandamme Memziers",constraints,gridbag);
constraints.gridx = 0;
if(choice==1){
constraints.insets = new Insets(0,wndSize.width/4,50,wndSize.width/4);
addlabel("Category Favorite Qty Prepared Qty Sold Selling Price($)\n"+
"---------------------------------------------------------------------------------------------------------------------------------------------\n"+
"Cake [c1]Cheese "+Integer.toString(c1_rem)+" "+Integer.toString(C1_SOLD)+" "+Double.toString(C1_SELL_PRI)+"\n"+
" [c2]Chocolate "+Integer.toString(c2_rem)+" "+Integer.toString(C2_SOLD)+" "+Double.toString(C2_SELL_PRI)+"\n"+
" [c3]Strawberry "+Integer.toString(c3_rem)+" "+Integer.toString(C3_SOLD)+" "+Double.toString(C3_SELL_PRI)+"\n"+
"\n"+"Pastry [p1]Egg "+Integer.toString(p1_rem)+" "+Integer.toString(P1_SOLD)+" "+Double.toString(P1_SELL_PRI)+"\n"+
" [p2]Pineapple "+Integer.toString(p2_rem)+" "+Integer.toString(P2_SOLD)+" "+Double.toString(P2_SELL_PRI)+"\n"+
"\n"+"Cookie [k1]Pecan and Nuts "+Integer.toString(k1_rem)+" "+Integer.toString(K1_SOLD)+" "+Double.toString(K1_SELL_PRI)+"\n"+
" [k2]Chocolate chips "+Integer.toString(k2_rem)+" "+Integer.toString(K2_SOLD)+" "+Double.toString(K2_SELL_PRI)+"\n",constraints,gridbag);
}
if(choice==2){
constraints.insets = new Insets(0,0,50,0);
addlabel("Category Favorite Qty Prepared Qty Sold Cost Selling Difference($)\n"+
"--------------------------------------------------------------------------------------------------------------------------------------------\n"+
"Cake [c1]Cheese "+Integer.toString(c1_rem)+" "+Integer.toString(C1_SOLD)+" "+Double.toString(C1_COST_PRI*(c1_rem+C1_SOLD))+" "+Double.toString(C1_SELL_PRI*C1_SOLD)+" "+Double.toString(C1_SELL_PRI*C1_SOLD-C1_COST_PRI*(c1_rem+C1_SOLD))+"\n"+
" [c2]Chocolate "+Integer.toString(c2_rem)+" "+Integer.toString(C2_SOLD)+" "+Double.toString(C2_COST_PRI*(c2_rem+C2_SOLD))+" "+Double.toString(C2_SELL_PRI*C2_SOLD)+" "+Double.toString(C2_SELL_PRI*C2_SOLD-C2_COST_PRI*(c2_rem+C2_SOLD))+"\n"+
" [c3]Strawberry "+Integer.toString(c3_rem)+" "+Integer.toString(C3_SOLD)+" "+Double.toString(C3_COST_PRI*(c3_rem+C3_SOLD))+" "+Double.toString(C3_SELL_PRI*C3_SOLD)+" "+Double.toString(C3_SELL_PRI*C3_SOLD-C3_COST_PRI*(c3_rem+C3_SOLD))+"\n"+
"\n"+"Pastry [p1]Egg "+Integer.toString(p1_rem)+" "+Integer.toString(P1_SOLD)+" "+Double.toString(P1_COST_PRI*(p1_rem+P1_SOLD))+" "+Double.toString(P1_SELL_PRI*P1_SOLD)+" "+Double.toString(P1_SELL_PRI*P1_SOLD-P1_COST_PRI*(p1_rem+P1_SOLD))+"\n"+
" [p2]Pineapple "+Integer.toString(p2_rem)+" "+Integer.toString(P2_SOLD)+" "+Double.toString(P2_COST_PRI*(p2_rem+P2_SOLD))+" "+Double.toString(P2_SELL_PRI*P2_SOLD)+" "+Double.toString(P2_SELL_PRI*P2_SOLD-P2_COST_PRI*(p2_rem+P2_SOLD))+"\n"+
"\n"+"Cookie [k1]Pecan and Nuts "+Integer.toString(k1_rem)+" "+Integer.toString(K1_SOLD)+" "+Double.toString(K1_COST_PRI*(k1_rem+K1_SOLD))+" "+Double.toString(K1_SELL_PRI*K1_SOLD)+" "+Double.toString(K1_SELL_PRI*K1_SOLD-K1_COST_PRI*(k1_rem+K1_SOLD))+"\n"+
" [k2]Chocolate chips "+Integer.toString(k2_rem)+" "+Integer.toString(K2_SOLD)+" "+Double.toString(K2_COST_PRI*(k2_rem+K2_SOLD))+" "+Double.toString(K2_SELL_PRI*K2_SOLD)+" "+Double.toString(K2_SELL_PRI*K2_SOLD-K2_COST_PRI*(k2_rem+K2_SOLD))+"\n"+
"---------------------------------------------------------------------------------------------------------------------------------------------\n"+
"Total "+Double.toString(C1_COST_PRI*(c1_rem+C1_SOLD)+C2_COST_PRI*(c2_rem+C2_SOLD)+C3_COST_PRI*(c3_rem+C3_SOLD)+
P1_COST_PRI*(p1_rem+P1_SOLD)+P2_COST_PRI*(p2_rem+P2_SOLD)+K1_COST_PRI*(k1_rem+K1_SOLD)+
K2_COST_PRI*(k2_rem+K2_SOLD))+" "+
Double.toString(C1_SELL_PRI*C1_SOLD+C2_SELL_PRI*C2_SOLD+C1_SELL_PRI*C1_SOLD+
P1_SELL_PRI*P1_SOLD+P2_SELL_PRI*P2_SOLD+K1_SELL_PRI*K1_SOLD+
K2_SELL_PRI*K2_SOLD)+" "+
Double.toString(C1_SELL_PRI*C1_SOLD-C1_COST_PRI*(c1_rem+C1_SOLD)+
C2_SELL_PRI*C2_SOLD-C2_COST_PRI*(c2_rem+C2_SOLD)+
C3_SELL_PRI*C3_SOLD-C3_COST_PRI*(c3_rem+C3_SOLD)+
P1_SELL_PRI*P1_SOLD-P1_COST_PRI*(p1_rem+P1_SOLD)+
P2_SELL_PRI*P2_SOLD-P2_COST_PRI*(p2_rem+P2_SOLD)+
K1_SELL_PRI*K1_SOLD-K1_COST_PRI*(k1_rem+K1_SOLD)+
K2_SELL_PRI*K2_SOLD-K2_COST_PRI*(k2_rem+K2_SOLD)),constraints,gridbag);
}
buttonadd("[S]ales",0,'S');
buttonadd("[D]aily Order",1,'D');
buttonadd("[C]ollection",2,'C');
buttonadd("[D]elete",3,'D');
buttonadd("[E]xit",4,'E');
content.add(bottomPanel,constraints);
bottomPanel.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.blue,1),
BorderFactory.createBevelBorder(BevelBorder.RAISED)));
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void buttonadd(String label,int handcon,char hot){
bottomPanel.add(mainbutton=new JButton(label));
mainbutton.setBorder(edge);
mainbutton.setPreferredSize(size);
mainbutton.addActionListener(new HandleControl(handcon));
mainbutton.setMnemonic(hot);
}
public void addlabel(String label,GridBagConstraints constraints,GridBagLayout layout){
JTextField jl = new JTextField(label);
jl.setBorder(edge);
jl.setFont(myfont1);
layout.setConstraints(jl, constraints);
jl.setHorizontalAlignment(JTextField.CENTER);
aWindow.getContentPane().add(jl);
}
}
class HandleControl extends Drawwindow
implements ActionListener{
private int buttoni;
public int temp1,temp2,temp3;
public HandleControl(int id){
buttoni=id;
}
public HandleControl(){
inssale.init();
inswindow.diswin(C1_NUM,C2_NUM,C3_NUM,P1_NUM,P2_NUM,K1_NUM,K2_NUM,1);
}
public void actionPerformed(ActionEvent e){
switch(buttoni){
case 0:
aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inswindow.diswin(inssale.C1_REM,
inssale.C2_REM,
inssale.C3_REM,
inssale.P1_REM,
inssale.P2_REM,
inssale.K1_REM,
inssale.K2_REM,1);
Dialogbox insDialogbox=new Dialogbox();
try{
insDialogbox.disdilo();
}catch(IllegalArgumentException ex){}
Textbox insTextbox=new Textbox();
try{
insTextbox.distext();
}catch(IllegalArgumentException ex){}
inssale.saleware(insDialogbox.getinp(),insTextbox.getinp());
aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inswindow.diswin(inssale.C1_REM,
inssale.C2_REM,
inssale.C3_REM,
inssale.P1_REM,
inssale.P2_REM,
inssale.K1_REM,
inssale.K2_REM,1);
break;
case 1:
aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inswindow.diswin(inssale.C1_REM+=C1_NUM,
inssale.C2_REM+=C1_NUM,
inssale.C3_REM+=C3_NUM,
inssale.P1_REM+=P1_NUM,
inssale.P2_REM+=P2_NUM,
inssale.K1_REM+=K1_NUM,
inssale.K2_REM+=K2_NUM,1);
Dialogbox insDialogboxorder=new Dialogbox();
try{
insDialogboxorder.disdilo();
}catch(IllegalArgumentException ex){}
Textbox insTextboxorder=new Textbox();
try{
insTextboxorder.distext();
}catch(IllegalArgumentException ex){}
inssale.saleware(insDialogboxorder.getinp(),insTextboxorder.getinp());
aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
int tem[]=new int[8];
for(int i=0;i<tem.length;i++)
tem[i]=0;
switch(inssale.temp){
case 1: tem[1]=insTextboxorder.getinp();
case 2: tem[2]=insTextboxorder.getinp();
case 3: tem[3]=insTextboxorder.getinp();
case 4: tem[4]=insTextboxorder.getinp();
case 5: tem[5]=insTextboxorder.getinp();
case 6: tem[6]=insTextboxorder.getinp();
case 7: tem[7]=insTextboxorder.getinp();
}
inswindow.diswin(inssale.C1_REM+=tem[1],
inssale.C2_REM+=tem[2],
inssale.C3_REM+=tem[3],
inssale.P1_REM+=tem[4],
inssale.P2_REM+=tem[5],
inssale.K1_REM+=tem[6],
inssale.K2_REM+=tem[7],1);
aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inswindow.diswin(inssale.C1_REM,
inssale.C2_REM,
inssale.C3_REM,
inssale.P1_REM,
inssale.P2_REM,
inssale.K1_REM,
inssale.K2_REM,1);
break;
case 2: aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inswindow.diswin(inssale.C1_REM,
inssale.C2_REM,
inssale.C3_REM,
inssale.P1_REM,
inssale.P2_REM,
inssale.K1_REM,
inssale.K2_REM,2);
break;
case 3:aWindow.dispose();
aWindow=new JFrame("bakery shop manager"
inswindow = new Drawwindow();
inssale = new Sales();
inssale.init();
inswindow.diswin(C1_NUM,
C1_NUM,
C3_NUM,
P1_NUM,
P2_NUM,
K1_NUM,
K2_NUM,1);
break;
case 4:System.exit(0);break;
}
}
}
class Dialogbox{
String[] choices={"[c1] Cheese","[c2] Chocolate","[c3] Strawberry","[p1] Egg","[p2] Pineapple","[k1] Pecan and Nuts","[k2] Chocolate chips"};
private String input;
public Dialogbox(){}
public void disdilo(){
input=(String)JOptionPane.showInputDialog(null,"Choose now...",
"Choose a category of bakery",
JOptionPane.QUESTION_MESSAGE,null,
choices,choices[1]);
}
public String getinp(){
return input;}
}
class Textbox{
private int temp;
public Textbox(){}
public void distext(){
String input=(String)JOptionPane.showInputDialog(null,"Please input the quantity","about",JOptionPane.INFORMATION_MESSAGE);
temp=Integer.parseInt(input);
}
public int getinp(){return temp;}
}
class Cs214ass{
public Cs214ass(){
}
public static void main(String[] args) throws Exception {
HandleControl inshan= new HandleControl();
}
}

){
Reply With Quote

