码迷,mamicode.com
首页 > 其他好文 > 详细

老八秘制小汉堡

时间:2020-01-17 20:55:26      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:except   string   inf   ext   event   panel   ntc   input   get   

先来成品图:技术图片

 

 

 

package 老八汉堡;

import java.awt.*;

import javax.swing.*;

public class Window extends JPanel {
    JFrame frame;
    static JButton but[][] = new JButton[2][6];
    private String str[][] = { { "臭豆腐", "俘虏", "老干妈", "美汁汁儿", "底儿", "盖儿" },
            { "扒鸭屁股", "胡萝贝", "粑粑", "白带", "黄瓜丝儿", "柠檬" } };
    static final Image bg = new ImageIcon("images/背景.png").getImage();
    Hamburg hum = new Hamburg();
    /**
     * 
     */
    public Window() {
        new Music("D://Java//老八汉堡//music//开场.mp3").start();
        frame = new JFrame("老八秘制小汉堡");
        frame.setSize(1000, 800);
        frame.setLocation(100, 100);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(this);
        frame.setVisible(true);
        this.setLayout(null);
        Font f = new Font("微软雅黑", Font.BOLD, 30);

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 6; j++) {
                but[i][j] = new JButton(str[i][j]);
                but[i][j].setFont(f);
                but[i][j].setBounds(j * 166, i * 85 + 600, 166, 85);
                this.add(but[i][j]);
                but[i][j].addActionListener(hum);
            }
        }
        hum.setG(getGraphics());

    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        this.setBackground(Color.BLACK);// 背景色
        drawBg(g);
    }

    public static void main(String[] args) {
        new Window();
    }
    public static void drawBg(Graphics g){
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 4; j++)
                g.drawImage(bg, j * 300, i * 200, null);// 老八背景图
        g.setColor(new Color(0, 0, 0, 150));
        g.fillRect(0, 0, 1000, 600);
    }
}
package 老八汉堡;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

import 老八汉堡.Music;

class Hamburg implements ActionListener {
    Graphics g;
    static final Image cdf = new ImageIcon("images/臭豆腐.png").getImage();
    static final Image fn = new ImageIcon("images/俘虏.png").getImage();
    static final Image lgm = new ImageIcon("images/老干妈.png").getImage();
    static final Image mzz = new ImageIcon("images/美汁汁儿.png").getImage();
    static final Image d = new ImageIcon("images/底儿.png").getImage();
    static final Image ge = new ImageIcon("images/盖儿.png").getImage();
    static final Image bypg = new ImageIcon("images/扒鸭屁股.png").getImage();
    static final Image hlb = new ImageIcon("images/胡萝贝.png").getImage();
    static final Image bb = new ImageIcon("images/粑粑.png").getImage();
    static final Image bd = new ImageIcon("images/白带.png").getImage();
    static final Image hgs = new ImageIcon("images/黄瓜丝.png").getImage();
    static final Image nm = new ImageIcon("images/柠檬.png").getImage();
    
    int h = 530+d.getHeight(null);
    boolean start=false;

    public Hamburg() {

    }

    public void setG(Graphics g) {
        this.g = g;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == Window.but[0][0]) {
            new Music("D://Java//老八汉堡//music//臭豆腐.mp3").start();
            h = h - cdf.getHeight(null);
            g.drawImage(cdf, 350, h, null);
        } else if (e.getSource() == Window.but[0][1]) {
            new Music("D://Java//老八汉堡//music//俘虏.mp3").start();
            h = h - fn.getHeight(null);
            g.drawImage(fn, 350, h, null);
        } else if (e.getSource() == Window.but[0][2]) {
            new Music("D://Java//老八汉堡//music//老干妈.mp3").start();
            h = h - lgm.getHeight(null);
            g.drawImage(lgm, 350, h, null);
        } else if (e.getSource() == Window.but[0][3]) {
            new Music("D://Java//老八汉堡//music//美汁汁.mp3").start();
            h = h - mzz.getHeight(null);
            g.drawImage(mzz, 350, h, null);
        } else if (e.getSource() == Window.but[0][4]&&start==false) {//
            new Music("D://Java//老八汉堡//music//小汉堡.mp3").start();
            h = h - d.getHeight(null);
            g.drawImage(d, 350, h, null);
        } else if (e.getSource() == Window.but[0][5]) {
            new Music("D://Java//老八汉堡//music//汉堡行不行.mp3").start();
            h = h - ge.getHeight(null);
            g.drawImage(ge, 350, h, null);
            h = 530+d.getHeight(null);
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }    
            Window.drawBg(g);
        } else if (e.getSource() == Window.but[1][0]) {
            new Music("D://Java//老八汉堡//music//扒鸭屁股.mp3").start();
            h = h - bypg.getHeight(null);
            g.drawImage(bypg, 350, h, null);
        } else if (e.getSource() == Window.but[1][1]) {
            new Music("D://Java//老八汉堡//music//胡萝卜.mp3").start();
            h = h - hlb.getHeight(null);
            g.drawImage(hlb, 350, h, null);
        } else if (e.getSource() == Window.but[1][2]) {
            new Music("D://Java//老八汉堡//music//粑粑.mp3").start();
            h = h - bb.getHeight(null);
            g.drawImage(bb, 350, h, null);
        } else if (e.getSource() == Window.but[1][3]) {
            new Music("D://Java//老八汉堡//music//白带.mp3").start();
            h = h - bd.getHeight(null);
            g.drawImage(bd, 350, h, null);
        } else if (e.getSource() == Window.but[1][4]) {
            new Music("D://Java//老八汉堡//music//黄瓜丝.mp3").start();
            h = h - hgs.getHeight(null);
            g.drawImage(hgs, 350, h, null);
        } else if (e.getSource() == Window.but[1][5]) {
            new Music("D://Java//老八汉堡//music//柠檬.mp3").start();
            h = h - nm.getHeight(null);
            g.drawImage(nm, 350, h, null);
        }

    }

}
package 老八汉堡;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.*;

class Music extends Thread {
    Player player;
    String music;

    public Music(String file) {
        this.music = file;
    }

    public void run() {
        try {
            play();
        } catch (FileNotFoundException | JavaLayerException e) {
            e.printStackTrace();
        }
    }

    public void play() throws FileNotFoundException, JavaLayerException {
        BufferedInputStream buffer = new BufferedInputStream(
                new FileInputStream(music));
        player = new Player(buffer);
        player.play();    
    }
    
}

原谅我做的时候忍不住笑了..

老八秘制小汉堡

标签:except   string   inf   ext   event   panel   ntc   input   get   

原文地址:https://www.cnblogs.com/yanzi404/p/12207341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!