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);
}
}
}
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);
}
}
}
请为这个游戏评分(刷新后可以更改评分)
[评分人数: 0 平均分: 0]
原文链接:【VR游戏网】https://vr.lxybaike.com/blog/10752.html,转载请注明出处。
请先
!