这是我做的一个课程设计,做好了,老师没给讲评,希望哪个朋友帮我看看,给我点建议和看法,谢谢!

 这是我做的一个课程设计,老师没讲评,希望哪个朋友能帮我看看,给我点意见,在这里先谢谢了!

 


 

我的课程设计要求:

 http://hosted.filefront.com/yjx479/(可以down下来)

我的程序:

 

import  java.awt. * ;
import  java.awt.event. * ;
import  javax.swing. * ;
import  java.util. * ;
import  java.util.Date;
import  java.awt.event.ActionListener;
import  java.awt.event.ActionEvent;
import  java.awt.event.WindowListener;
import  java.awt.event.WindowEvent;
import  java.awt.event.FocusListener;
import  java.awt.event.FocusEvent;

public   class  mcdonaldHomework                           // 主类
{    
    
public static void main(String []args)
        
{
            
new orderFrame();
        }

}


class  orderFrame  extends  JFrame                        // JFrame
{
    myPanelone mp1 
= new myPanelone();
    myPanelsecond mp2 
= new myPanelsecond();
    myPanelthree mp3 
= new myPanelthree(this);
    
    
public orderFrame()
    
{
        
super("麦当劳订餐系统!");
            
        setLayout(
new BorderLayout());                //采用BorderLayout布局
        add(mp1,BorderLayout.NORTH);                  //添加面板
        add(mp2,BorderLayout.CENTER);
        add(mp3,BorderLayout.SOUTH);
            
        setSize(
430,550);                             //初始化窗体的样式
        setVisible(true);
        setResizable(
false);                          //不能改变窗体大小
    }

}




class  myPanelone  extends  JPanel  implements  Runnable             // 顶层面板类
{
    ImageIcon icon;                            
//图片
    JLabel imgLabel;                           //存放图片的JLabel框
    JLabel timeLabel;                          //日期JLabel框
    Thread th;                                 //线程
    
    
public myPanelone()                        //myPanelone的构造函数
    {
        icon 
= new ImageIcon("images/mc_logo.gif");              
        imgLabel 
= new JLabel(icon);                        //定义图片的JLabel框
        timeLabel = new JLabel();
        
        th 
= new Thread(this);                                 //定义线程
        setLayout(new FlowLayout());
        add(imgLabel);                                         
//添加组件
        add(timeLabel);
        th.start();                                            
//启动线程
    }

        
    
public void run()                                          //重写run()方法
    {
        
while(true)
        
{
            Date dd
=new Date();                                //获取当前时间
             timeLabel.setText(dd.toGMTString());
            
try
            
{
                Thread.sleep(
1000);
            }

            
catch(InterruptedException e)
            
{
                
            }

        }

    }

}


class  myPanelsecond  extends  JPanel                            // 中间面板定义
{
    GridBagLayout gb;                                       
//使用GridBagLayout布局
    GridBagConstraints gbc;
    
    namePanel nameP 
= new namePanel();                       //引用子类
    addressPanel addressP = new addressPanel();
    phonePanel phoneP 
= new phonePanel();
    emailPanel emailP 
= new emailPanel();
    foodPanel foodP 
= new foodPanel();
    
    
    
public myPanelsecond()
    
{
        gb 
= new GridBagLayout();
        setLayout(gb);
        
        gbc 
= new GridBagConstraints();
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(nameP,
0,0,2,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(addressP,
2,0,4,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(phoneP,
6,0,2,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(emailP,
8,0,2,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(foodP,
10,0,3,2);
        
    }

    
public void addComponent(Component c,int row,int col,int nrow,int ncol)       //定义函数
    {
        gbc.gridx 
= col;
        gbc.gridy 
= row;
        
        gbc.gridwidth 
= ncol;
        gbc.gridheight 
= nrow;
        
        gb.setConstraints(c,gbc);
        add(c);
    }

}


class  namePanel  extends  Panel                             // customer名字类
{
    Label customerJLabel;
    TextField customerJTxt;
    
    
public namePanel()
    
{
        customerJLabel 
= new Label("Customer Name:");
        customerJTxt 
= new TextField("",23);
        
        setLayout(
new GridLayout(1,2));
        add(customerJLabel);
        add(customerJTxt);
    }

}


class  addressPanel  extends  Panel                             // 地址类
{
    Label addressJLabel;
    TextArea addressJTxtarea;
    
int SCROLLBARS_VERTICAL_ONLY = 1;                       //确定滚动条的样式
    
    
public addressPanel()
    
{
        addressJLabel 
= new Label("Current Address:");
        addressJTxtarea 
= new TextArea("",4,24,SCROLLBARS_VERTICAL_ONLY);

        setLayout(
new GridLayout(1,2));
        add(addressJLabel);
        add(addressJTxtarea);
    }

}


class  phonePanel  extends  Panel                            // 电话类
{
    Label phoneJLabel;
    TextField phoneJTxt;
    
    
public phonePanel()
    
{
        phoneJLabel 
= new Label("Phone Number:");
        phoneJTxt 
= new TextField("",23);
        
        setLayout(
new GridLayout(1,2));
        add(phoneJLabel);
        add(phoneJTxt);
    }

}


class  emailPanel  extends  Panel  implements   FocusListener                              // Email类
{
    Label emailJLabel;
    TextField emailJTxt;
    
char flag='n';                                    //判断变量
    
    
public emailPanel()
    
{
        emailJLabel 
= new Label("Email ID:");
        emailJTxt 
= new TextField("",23);
    
        
        setLayout(
new GridLayout(1,2));
        add(emailJLabel);
        add(emailJTxt);
        emailJTxt.addFocusListener(
this);        
    }


    
public void focusGained(FocusEvent e) {
        
// TODO: Add your code here
    }


    
public void focusLost(FocusEvent e)               // 当emailJTxt失去焦点时
    {
        
if(e.getComponent() == emailJTxt)
        
{
            
for(int i=0;i<emailJTxt.getText().length();i++)
            
{
                
if(emailJTxt.getText().charAt(i) == '@')
                
{
                    
for(int j=i+1;j<emailJTxt.getText().length();j++)
                    
{
                        
if(emailJTxt.getText().charAt(j) == '.')
                        
{
                            flag 
= 'y';
                            
break;
                        }

                    }

                }

            }

            
if(flag == 'n')
            
{
                
new dataDialog();
            }

        }

    }
        
}


class  foodPanel  extends  JPanel  implements  ActionListener             // 食物类
{
    ButtonGroup bg1 
= new ButtonGroup();                   //单选按钮(一组)
    JRadioButton btnPizza;
    JRadioButton btnHurger;
    
    JCheckBox capcicum_pizza;                             
//复选按钮(pizza)
    JCheckBox cheese_pizza;
    JCheckBox onion_pizza;
    JCheckBox tomato_pizza;
    
    JCheckBox cheese_hurger;
    JCheckBox kampung_burger;
    JCheckBox loveburger_burger;
    JCheckBox mcpepper_burger;
    
    GridBagLayout gb;                                         
//按钮布局为GridBagLayout
    GridBagConstraints gbc;
    
    Label costJLabel;                                       
//组件(cost)
    TextField costJtxt;
             
    Label order_timeLabel;                                  
//交付日期
    Choice order_timeChoice = new Choice();

                            
//食物图片
    JLabel foodImage;
    ImageIcon icon_pizza 
= new ImageIcon("images/pizza.jpg");         //图片pizza                                           
    ImageIcon icon_pizza_capcicum = new ImageIcon("images/pizza_cap.jpg");         //图片Capcicum Pizza 
    ImageIcon icon_pizza_cheese = new ImageIcon("images/pizza_cheese.jpg");         //图片Cheese Pizza 
    ImageIcon icon_pizza_onion = new ImageIcon("images/pizza_oni.jpg");         //图片Onion Pizza
    ImageIcon icon_pizza_tomato = new ImageIcon("images/pizza_toma.jpg");         //图片Tomato Pizza
    
    ImageIcon icon_hurger 
= new ImageIcon("images/mctowkay_burger.jpg");         //图片hurger 
    ImageIcon icon_hurger_cheese = new ImageIcon("images/burger_cheese.jpg");         //图片Cheese Hurger
    ImageIcon icon_hurger_kampung = new ImageIcon("images/kampungburger_burger.jpg");         //图片Kampung Hurger 
    ImageIcon icon_hurger_love = new ImageIcon("images/loveburger_burger.jpg");         //图片Love Hurger 
    ImageIcon icon_hurger_mcpepper = new ImageIcon("images/mcpepper_burger.jpg");         //图片Mcpepper Hurger 

///    
    public foodPanel()
    
{
        btnPizza 
= new JRadioButton("Pizza");
        btnHurger 
= new JRadioButton("Hurger");
        
        bg1.add(btnPizza);                                 
//单选按钮在一个ButtonGroup中
        bg1.add(btnHurger);
        
        
        foodImage 
= new JLabel(icon_pizza); 
        
        capcicum_pizza 
= new JCheckBox("Capcicum Pizza");
        cheese_pizza 
= new JCheckBox("Cheese Pizza");
        onion_pizza 
= new JCheckBox("Onion Pizza");
        tomato_pizza 
= new JCheckBox("Tomato Pizza");
    
        cheese_hurger 
= new JCheckBox("Cheese Hurger");
        kampung_burger 
= new JCheckBox("Kampung Hurger");
        loveburger_burger 
= new JCheckBox("Love Hurger");
        mcpepper_burger 
= new JCheckBox("Mcpepper Hurger");
        
        costJLabel 
= new Label("Cost:");
        costJtxt 
= new TextField("",23);
        
        order_timeLabel 
= new Label("When You Want Delivery:");
        order_timeChoice.addItem(
"");
        order_timeChoice.addItem(
"Today");
        order_timeChoice.addItem(
"Tomorrow");
        order_timeChoice.addItem(
"The Day After Tomorrow");
/        
                                
//开始添加组件
        gb = new GridBagLayout();                           
        setLayout(gb);
        
        gbc 
= new GridBagConstraints();
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;                  //单选按钮添加
        addComponent(btnPizza,0,0,1,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(btnHurger,
0,2,1,1);
    
/    
        gbc.fill = GridBagConstraints.HORIZONTAL;                //各个pizza的复选框的添加
        addComponent(capcicum_pizza,1,0,1,2);                 
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(cheese_pizza,
1,2,1,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(onion_pizza,
2,0,1,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(tomato_pizza,
2,2,1,2);
        
        gbc.fill = GridBagConstraints.HORIZONTAL;                  //各个hurger的复选框的添加
        addComponent(cheese_hurger,1,0,1,2);                  
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(kampung_burger,
1,2,1,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(loveburger_burger,
2,0,1,2);
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(mcpepper_burger,
2,2,1,2);

//
        gbc.fill = GridBagConstraints.HORIZONTAL;                    //添加食物图片
        addComponent(foodImage,0,4,3,2);        
        

        gbc.fill = GridBagConstraints.HORIZONTAL;
        addComponent(costJLabel,
3,0,1,2);                     //添加cost的组件
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(costJtxt,
3,2,1,6);
        

        gbc.fill = GridBagConstraints.HORIZONTAL;
        addComponent(order_timeLabel,
4,0,2,2);                //添加发货日期
        
        gbc.fill 
= GridBagConstraints.HORIZONTAL;
        addComponent(order_timeChoice,
4,2,2,6);

        capcicum_pizza.setVisible(false);                        //初始化各个复选按钮的状态
        cheese_pizza.setVisible(false);
        onion_pizza.setVisible(
false);
        tomato_pizza.setVisible(
false);    
        
        cheese_hurger.setVisible(
false);
        kampung_burger.setVisible(
false);
        loveburger_burger.setVisible(
false);
        mcpepper_burger.setVisible(
false);    
        
    

        btnPizza.addActionListener(
this);                       //给单选按钮添加监听器
        btnHurger.addActionListener(this);
        
        capcicum_pizza.addActionListener(
this);
        cheese_pizza.addActionListener(
this);
        onion_pizza.addActionListener(
this);
        tomato_pizza.addActionListener(
this);
        
        cheese_hurger.addActionListener(
this);
        kampung_burger.addActionListener(
this);
        loveburger_burger.addActionListener(
this);
        mcpepper_burger.addActionListener(
this);
        
    }



/
    public void actionPerformed(ActionEvent ae)              //监听事件
    {
        
if(ae.getActionCommand().equals("Pizza"))
        
{
            capcicum_pizza.setVisible(
true);
            cheese_pizza.setVisible(
true);
            onion_pizza.setVisible(
true);
            tomato_pizza.setVisible(
true);
            
            cheese_hurger.setVisible(
false);
            kampung_burger.setVisible(
false);
            loveburger_burger.setVisible(
false);
            mcpepper_burger.setVisible(
false);
            
            foodImage.setIcon(icon_pizza);                    
//改变图片,重新刷新
            foodImage.repaint();
        }

        
else if(ae.getActionCommand().equals("Hurger"))
        
{
            cheese_hurger.setVisible(
true);
            kampung_burger.setVisible(
true);
            loveburger_burger.setVisible(
true);
            mcpepper_burger.setVisible(
true);
            
            capcicum_pizza.setVisible(
false);
            cheese_pizza.setVisible(
false);
            onion_pizza.setVisible(
false);
            tomato_pizza.setVisible(
false);
            
            foodImage.setIcon(icon_hurger);
            foodImage.repaint();            
        }

        
///
                
//显示食物的图片以及价格
        else if(ae.getActionCommand().equals("Capcicum Pizza"))
        
{
            foodImage.setIcon(icon_pizza_capcicum);
            foodImage.repaint();
            costJtxt.setText(
"10$");
        }

        
else if(ae.getActionCommand().equals("Cheese Pizza"))
        
{
            foodImage.setIcon(icon_pizza_cheese );
            foodImage.repaint();
            costJtxt.setText(
"12$");
        }

        
else if(ae.getActionCommand().equals("Onion Pizza"))
        
{
            foodImage.setIcon(icon_pizza_onion);
            foodImage.repaint();
            costJtxt.setText(
"14$");
        }

        
else if(ae.getActionCommand().equals("Tomato Pizza"))
        
{
            foodImage.setIcon(icon_pizza_tomato);
            foodImage.repaint();
            costJtxt.setText(
"16$");
        }


        
else if(ae.getActionCommand().equals("Cheese Hurger"))
        
{
            foodImage.setIcon(icon_hurger_cheese);
            foodImage.repaint();
            costJtxt.setText(
"11$");
        }

        
else if(ae.getActionCommand().equals("Kampung Hurger"))
        
{
            foodImage.setIcon(icon_hurger_kampung);
            foodImage.repaint();
            costJtxt.setText(
"13$");
        }

        
else if(ae.getActionCommand().equals("Love Hurger"))
        
{
            foodImage.setIcon(icon_hurger_love);
            foodImage.repaint();
            costJtxt.setText(
"15$");
        }

        
else if(ae.getActionCommand().equals("Mcpepper Hurger"))
        
{
            foodImage.setIcon(icon_hurger_mcpepper);
            foodImage.repaint();
            costJtxt.setText(
"17$");
        }

        
    }

    
    
public void addComponent(Component c,int row,int col,int nrow,int ncol)
    
{
        gbc.gridx 
= col;
        gbc.gridy 
= row;
        
        gbc.gridwidth 
= ncol;
        gbc.gridheight 
= nrow;
        
        gb.setConstraints(c,gbc);
        add(c);
    }


}


class  myPanelthree  extends  JPanel  implements  ActionListener            // 底层JPanel
{
    JButton btnOrder;                      
//订购以及退出按钮
    JButton btnExit;
    orderFrame orderF;
    myPanelsecond mps;
    String str;
    
    
    
public myPanelthree(orderFrame of)
    
{
        mps 
= (myPanelsecond)of.mp2;                  //类型转换
        btnOrder = new JButton("Order");
        btnExit 
= new JButton("Exit");
        
        add(btnOrder);
        add(btnExit);
        
        btnOrder.addActionListener(
this);                  //给按钮添加监听器
        btnExit.addActionListener(this);
        
    
    }

    
    
public void actionPerformed(ActionEvent ae) 
    
{
        
if(ae.getActionCommand().equals("Order"))
        
{    
            
if(mps.nameP.customerJTxt.getText().equals(""|| mps.addressP.addressJTxtarea.getText().equals(""|| mps.phoneP.phoneJTxt.getText().equals(""|| mps.emailP.emailJTxt.getText().equals(""|| mps.foodP.costJtxt.getText().equals(""|| mps.foodP.order_timeChoice.getSelectedItem().equals(""))
            
{
                javax.swing.JOptionPane.showMessageDialog(
this,"Valid Data must be enter!","Waring!",JOptionPane.WARNING_MESSAGE);
            }

            
else
            
{
                
if(mps.foodP.btnPizza.isSelected())
                
{
                    
//使用JOptionPane的Message框
                    str = new String("Thanks " + mps.nameP.customerJTxt.getText() + " for buying Pizza for the cost" + mps.foodP.costJtxt.getText() + ",Pizza will be delivered " + mps.foodP.order_timeChoice.getSelectedItem());
                    javax.swing.JOptionPane.showMessageDialog(
this,str,"Welcome!",JOptionPane.INFORMATION_MESSAGE);
                }

                
else if(mps.foodP.btnHurger.isSelected())
                
{
                    str 
= new String("Thanks " + mps.nameP.customerJTxt.getText() + " for buying Hurger for the cost " + mps.foodP.costJtxt.getText() + ",Hurger will be delivered" + mps.foodP.order_timeChoice.getSelectedItem());
                    javax.swing.JOptionPane.showMessageDialog(
this,str,"Welcome!",JOptionPane.INFORMATION_MESSAGE);
                }

            }

        }

        
else if(ae.getActionCommand().equals("Exit"))
        
{
            System.exit(
0);
        }

    }


}


class  dataDialog  extends  JDialog  implements  ActionListener          // email错误提示Dialog
{
    JLabel error_dataJLabel;
    JButton error_dataJButton;

    
public dataDialog()
    
{
        
this.setTitle("The Email is Wrong!");
        error_dataJLabel 
= new JLabel("Valid Email must be enter!");
        error_dataJButton 
= new JButton("OK");

        setLayout(
new FlowLayout());
        add(error_dataJLabel);
        add(error_dataJButton);
        
        setSize(
200,100);    
        setVisible(
true);
        setResizable(
false);
        error_dataJButton.addActionListener(
this);
    }


    
public void actionPerformed(ActionEvent e) 
    
{
        
if(e.getActionCommand().equals("OK"))
        
{
            
this.hide();
        }

    }

}

 


真心希望有人能帮我看看,给我建议,提出我需要改进的地方,谢谢!
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值