美酒换咖啡用java编写_我的Java程序想换一下运行框上面的咖啡图标。谁能帮我看看程序?...

importstaticjava.lang.Math.random;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassMainFrameextendsJFrame{privatestaticlongscore=0;//分数privatestat...

import static java.lang.Math.random;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class MainFrame extends JFrame {

private static long score = 0;//分数

private static Integer ammoNum = 5;//子弹数量

private static JLabel scoreLabel;//分数

private BackgroundPanel backgroundPanel;

private static JLabel ammoLabel;

private static JPanel infoPane;

/**

* 构造方法

*/

public MainFrame() {

super();//调用父类构造函数

setResizable(false);//进制调整窗体大小

setTitle("打猎游戏");//设置游戏名

infoPane = (JPanel) getGlassPane();//获取窗体信息

JLabel label = new JLabel("装载子弹……");//定义一个对象并调用构造函数

label.setHorizontalAlignment(SwingConstants.CENTER);//设置水平线

label.setFont(new Font("楷体", Font.BOLD, 32));//设置字体

label.setForeground(Color.RED);//设置前背景色

infoPane.setLayout(new BorderLayout());//设置容器面板布局

infoPane.add(label);//添加提示标签组件到玻璃面板

setAlwaysOnTop(true);//是窗体保持在最顶成

setBounds(100, 100, 573, 411);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

backgroundPanel = new BackgroundPanel();//创建带背景的面板

backgroundPanel.setImage(new ImageIcon(getClass()

.getResource("background.jpg")).getImage());//设置背景图片

getContentPane().add(backgroundPanel,BorderLayout.CENTER);

// 添加鼠标事件适配器

addMouseListener(new FrameMouseListener());//鼠标监听

scoreLabel = new JLabel();//初始化对象

/*窗体设置*/

scoreLabel.setHorizontalAlignment(SwingConstants.CENTER);

scoreLabel.setForeground(Color.ORANGE);

scoreLabel.setText("分数:");

scoreLabel.setBounds(25, 15, 120, 18);

backgroundPanel.add(scoreLabel);

ammoLabel = new JLabel();//初始化对象

/*窗体设置*/

ammoLabel.setForeground(Color.ORANGE);

ammoLabel.setHorizontalAlignment(SwingConstants.RIGHT);

ammoLabel.setText("子弹数量:" + ammoNum);

ammoLabel.setBounds(422, 15, 93, 18);

backgroundPanel.add(ammoLabel);

}

/**

* 加分方法

*/

public synchronized static void appScore(int num) {

score += num;

scoreLabel.setText("分数:" + score);

}

/**

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值