java基礎教程案例:[68]java滿漢樓專案5?

/*

* 這是一個

* 結賬介面

* */

package ProjectofMHL;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.awt.image.ImageObserver;

import java.awt.image.ImageProducer;

public class Charge extends JFrame implements ActionListener ,MouseListener

{

MyImagePanel charge_mip;

Image im;

String str1="",str2="";

JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7,jp8;

JPanel jp11,jp12,jp13,jp14,jp15,jp16,jp17,jp18;

JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8;

JLabel jl9,jl10;

JLabel jl11,jl12,jl13;

JLabel j1,j2,j3,j4,j5;

JButton jb1,jb2,jb3,jb4;

CardLayout c1,c2,c3,c4;

CardLayout c5,c6,c7,c8;

CardLayout c9,c10,c11,c12;

CardLayout c13,c14,c15,c16;

//String str="";

//獲得當前視窗的大小

int w=Toolkit.getDefaultToolkit().getScreenSize().width;

int h=Toolkit.getDefaultToolkit().getScreenSize().height;

public void initCharge1()

{

jp1=new JPanel();

c1=new CardLayout();

jp1.setLayout(c1);

jl1=new JLabel(new ImageIcon("image//1.jpg"));

jl2=new JLabel(new ImageIcon("image//a.jpg"));

jp1.add(jl1,"0");

jp1.add(jl2,"1");

jp1.setBounds(250, 210, 60, 60);

jp1.addMouseListener(this);

jp2=new JPanel();

c2=new CardLayout();

jp2.setLayout(c2);

jl3=new JLabel(new ImageIcon("image//2.jpg"));

jl4=new JLabel(new ImageIcon("image//b.jpg"));

jp2.add(jl3,"0");

jp2.add(jl4,"1");

jp2.setBounds(250, 320, 60, 60);

jp2.addMouseListener(this);

jl11=new JLabel("A區");

jl11.setFont(MyTools.f);

jl11.setBounds(200,380, 100, 50);

jp3=new JPanel();

c3=new CardLayout();

jp3.setLayout(c3);

jl5=new JLabel(new ImageIcon("image//3.jpg"));

jl6=new JLabel(new ImageIcon("image//c.jpg"));

jp3.add(jl5,"0");

jp3.add(jl6,"1");

jp3.setBounds(250, 430, 60, 60);

jp3.addMouseListener(this);

jp4=new JPanel();

c4=new CardLayout();

jp4.setLayout(c4);

jl7=new JLabel(new ImageIcon("image//4.jpg"));

jl8=new JLabel(new ImageIcon("image//d.jpg"));

jp4.add(jl7,"0");

jp4.add(jl8,"1");

jp4.setBounds(250, 540, 60, 60);

jp4.addMouseListener(this);

this.add(jp1);

this.add(jp2);

this.add(jp3);

this.add(jp4);

this.add(jl11);

}

public void initCharge2()

{

jp5=new JPanel();

c5=new CardLayout();

jp5.setLayout(c5);

jl1=new JLabel(new ImageIcon("image//5.jpg"));

jl2=new JLabel(new ImageIcon("image//e.jpg"));

jp5.add(jl1,"0");

jp5.add(jl2,"1");

jp5.setBounds(400, 210, 60, 60);

jp5.addMouseListener(this);

jp6=new JPanel();

c6=new CardLayout();

jp6.setLayout(c6);

jl3=new JLabel(new ImageIcon("image//6.jpg"));

jl4=new JLabel(new ImageIcon("image//f.jpg"));

jp6.add(jl3,"0");

jp6.add(jl4,"1");

jp6.setBounds(400, 320, 60, 60);

jp6.addMouseListener(this);

jp7=new JPanel();

c7=new CardLayout();

jp7.setLayout(c7);

jl5=new JLabel(new ImageIcon("image//7.jpg"));

jl6=new JLabel(new ImageIcon("image//g.jpg"));

jp7.add(jl5,"0");

jp7.add(jl6,"1");

jp7.setBounds(400, 430, 60, 60);

jp7.addMouseListener(this);

jp8=new JPanel();

c8=new CardLayout();

jp8.setLayout(c8);

jl7=new JLabel(new ImageIcon("image//8.jpg"));

jl8=new JLabel(new ImageIcon("image//h.jpg"));

jp8.add(jl7,"0");

jp8.add(jl8,"1");

jp8.setBounds(400, 540, 60, 60);

jp8.addMouseListener(this);

this.add(jp5);

this.add(jp6);

this.add(jp7);

this.add(jp8);

}

public void initCharge3()

{

jp11=new JPanel();

c9=new CardLayout();

jp11.setLayout(c9);

jl1=new JLabel(new ImageIcon("image//01.jpg"));

jl2=new JLabel(new ImageIcon("image//a.jpg"));

jp11.add(jl1,"0");

jp11.add(jl2,"1");

jp11.setBounds(550, 210, 60, 60);

jp11.addMouseListener(this);

jp12=new JPanel();

c10=new CardLayout();

jp12.setLayout(c10);

jl3=new JLabel(new ImageIcon("image//02.jpg"));

jl4=new JLabel(new ImageIcon("image//b.jpg"));

jp12.add(jl3,"0");

jp12.add(jl4,"1");

jp12.setBounds(550, 320, 60, 60);

jp12.addMouseListener(this);

jl12=new JLabel("B區");

jl12.setFont(MyTools.f);

jl12.setBounds(500,380, 100, 50);

jp13=new JPanel();

c11=new CardLayout();

jp13.setLayout(c11);

jl5=new JLabel(new ImageIcon("image//03.jpg"));

jl6=new JLabel(new ImageIcon("image//c.jpg"));

jp13.add(jl5,"0");

jp13.add(jl6,"1");

jp13.setBounds(550, 430, 60, 60);

jp13.addMouseListener(this);

jp14=new JPanel();

c12=new CardLayout();

jp14.setLayout(c12);

jl7=new JLabel(new ImageIcon("image//04.jpg"));

jl8=new JLabel(new ImageIcon("image//d.jpg"));

jp14.add(jl7,"0");

jp14.add(jl8,"1");

jp14.setBounds(550, 540, 60, 60);

jp14.addMouseListener(this);

this.add(jp11);

this.add(jp12);

this.add(jp13);

this.add(jp14);

this.add(jl12);

}

public void initCharge4()

{

jp15=new JPanel();

c13=new CardLayout();

jp15.setLayout(c13);

jl1=new JLabel(new ImageIcon("image//05.jpg"));

jl2=new JLabel(new ImageIcon("image//e.jpg"));

jp15.add(jl1,"0");

jp15.add(jl2,"1");

jp15.setBounds(700, 210, 60, 60);

jp15.addMouseListener(this);

jp16=new JPanel();

c14=new CardLayout();

jp16.setLayout(c14);

jl3=new JLabel(new ImageIcon("image//06.jpg"));

jl4=new JLabel(new ImageIcon("image//f.jpg"));

jp16.add(jl3,"0");

jp16.add(jl4,"1");

jp16.setBounds(700, 320, 60, 60);

jp16.addMouseListener(this);

jp17=new JPanel();

c15=new CardLayout();

jp17.setLayout(c15);

jl5=new JLabel(new ImageIcon("image//07.jpg"));

jl6=new JLabel(new ImageIcon("image//g.jpg"));

jp17.add(jl5,"0");

jp17.add(jl6,"1");

jp17.setBounds(700, 430, 60, 60);

jp17.addMouseListener(this);

jp18=new JPanel();

c16=new CardLayout();

jp18.setLayout(c16);

jl7=new JLabel(new ImageIcon("image//08.jpg"));

jl8=new JLabel(new ImageIcon("image//h.jpg"));

jp18.add(jl7,"0");

jp18.add(jl8,"1");

jp18.setBounds(700, 540, 60, 60);

jp18.addMouseListener(this);

this.add(jp15);

this.add(jp16);

this.add(jp17);

this.add(jp18);

}

public void initright()

{

//用於得到當前登入使用者

jl9=new JLabel("當前使用者名稱: "+str1);

jl9.setFont(MyTools.f);

jl9.setBounds(1025, 150, 300, 50);

jl10=new JLabel("職位: "+str2);

jl10.setFont(MyTools.f);

jl10.setBounds(1025, 180, 300, 50);

jl13=new JLabel("當前最新預定狀態:");

jl13.setFont(MyTools.f);

jl13.setBounds(920,210, 300, 50);

//System.out.println("charge"+str1+" "+str2+"jl9:"+jl9.getText());

j1=new JLabel("");

j1.setFont(MyTools.f);

j1.setBounds(1050, 230, 200, 50);

j2=new JLabel("");

j2.setFont(MyTools.f);

j2.setBounds(1050, 280, 200, 50);

j3=new JLabel("");

j3.setBounds(1050, 330, 200, 50);

j3.setFont(MyTools.f);

j4=new JLabel("");

j4.setBounds(1050, 380, 200, 50);

j4.setFont(MyTools.f);

j5=new JLabel("");

j5.setBounds(1050, 430, 200, 50);

j5.setFont(MyTools.f);

this.add(jl9);

this.add(jl10);

this.add(jl13);

this.add(j1);

this.add(j2);

this.add(j3);

this.add(j4);

this.add(j5);

jb1=new JButton("預定");

jb1.setFont(MyTools.ff);

jb1.setBounds(1050, 500, 80, 35);

jb1.addActionListener(this);

jb2=new JButton("退訂");

jb2.setFont(MyTools.ff);

jb2.setBounds(1150, 500, 80, 35);

jb2.addActionListener(this);

jb3=new JButton("點菜");

jb3.setFont(MyTools.ff);

jb3.setBounds(1050, 550, 80, 35);

jb3.addActionListener(this);

jb4=new JButton("結賬");

jb4.setFont(MyTools.ff);

jb4.setBounds(1150, 550, 80, 35);

jb4.addActionListener(this);

this.add(jb1);

this.add(jb2);

this.add(jb3);

this.add(jb4);

}

public Charge(String name,String post)

{

im=Toolkit.getDefaultToolkit().getImage("image//ChargeBack.jpg");

charge_mip=new MyImagePanel(im);

this.str1=name;

this.str2=post;

//初始化餐桌

this.initCharge1();

this.initCharge2();

this.initCharge3();

this.initCharge4();

//初始化有半部分

this.initright();

this.add(charge_mip);

this.setSize(w,h-45);

this.setTitle("滿漢樓餐飲系統");

this.setIconImage(Toolkit.getDefaultToolkit().getImage("image//title.gif"));

this.setVisible(true);

//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

@Override

public void actionPerformed(ActionEvent e)

{

//響應預訂按鈕

if(e.getSource()==jb1)

{

//System.out.println("aaaa");

new ofChargeClient(this);

}

if (e.getSource()==jb2)

{

j1.setText("");

j2.setText("");

j3.setText("");

j4.setText("");

j5.setText("");

}

}

@Override

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

if(e.getClickCount()==2&&e.getSource()==jp1)

{

this.c1.show(jp1,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp2)

{

this.c2.show(jp2,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp3)

{

this.c3.show(jp3,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp4)

{

this.c4.show(jp4,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp5)

{

this.c5.show(jp5,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp6)

{

this.c6.show(jp6,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp7)

{

this.c7.show(jp7,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp8)

{

this.c8.show(jp8,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp11)

{

this.c9.show(jp11,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp12)

{

this.c10.show(jp12,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp13)

{

this.c11.show(jp13,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp14)

{

this.c12.show(jp14,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp15)

{

this.c13.show(jp15,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp16)

{

this.c14.show(jp16,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp17)

{

this.c15.show(jp17,"1");

}

if(e.getClickCount()==2&&e.getSource()==jp18)

{

this.c16.show(jp18,"1");

}

if(e.getClickCount()==1&&e.getSource()==jp1)

{

this.c1.show(jp1,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp2)

{

this.c2.show(jp2,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp3)

{

this.c3.show(jp3,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp4)

{

this.c4.show(jp4,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp5)

{

this.c5.show(jp5,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp6)

{

this.c6.show(jp6,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp7)

{

this.c7.show(jp7,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp8)

{

this.c8.show(jp8,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp11)

{

this.c9.show(jp11,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp12)

{

this.c10.show(jp12,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp13)

{

this.c11.show(jp13,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp14)

{

this.c12.show(jp14,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp15)

{

this.c13.show(jp15,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp16)

{

this.c14.show(jp16,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp17)

{

this.c15.show(jp17,"0");

}

if(e.getClickCount()==1&&e.getSource()==jp18)

{

this.c16.show(jp18,"0");

}

}

@Override

public void mouseEntered(MouseEvent e)

{

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseReleased(MouseEvent e) {

// TODO Auto-generated method stub

}

}

java基礎教程案例 (共54篇) 上一篇:java滿漢樓專案4 下一篇:java滿漢樓原始碼...

專案, 案例, 基礎教程, 滿漢樓,
相關問題答案