【1024程序员节】 节日快乐!

import javax.swing.*;
 import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
 class ClickableDice extends JFrame {
 int value1 = 4;
 MyPanel dice;
 public ClickableDice() {
 dice = new MyPanel(); dice.setBackground(Color.pink); dice.setBorder(BorderFactory.createTitledBorder(投掷色子面板));
 setContentPane(dice);
 setSize(300, 200);
 setVisible(true);
 dice.addMouseListener(new MouseAdapter() {
 public void mousePressed(MouseEvent evt) { value1 = (int) (Math.random() * 6) + 1; dice.repaint();
 }
 }
);
 }
 public static void main(String args[]) {
 new ClickableDice();
 }
 void draw(Graphics g, int val, int x, int y{
 g.setColor(Color.black);
 g.drawRect(x, y, 34, 34);
 if (val % 2 == 1) g.fillOval(x + 13, y + 13, 9, 9);
 if (val == 6) g.fillOval(x + 23, y + 13, 9, 9);
 if (val > 3) g.fillOval(x + 3, y + 23, 9, 9);
 if (val > 1) g.fillOval(x + 23, y + 23, 9, 9);
 } class MyPanel extends JPanel { public void paintComponent(Graphics g) { //super.paintComponent(g); draw(g, value1, 40, 40);
 }
 }
}

原文链接:【VR游戏网】https://vr.lxybaike.com/blog/10752.html,转载请注明出处。

0
分享海报

评论0

请先

站点公告

好消息!双11大促,终身VIP只要98元,限量200个名额,抢完即止!因为专业,所以专注,提供网页+PC客户端+一体机客户端直链高速下载,不需要另外开通网盘会员
没有账号?注册  忘记密码?

社交账号快速登录