所以我决定把编程作为一种爱好,现在我正在努力创建一个老虎机,并在教程的帮助下.但是,我遇到了重叠图像的问题.我使用照片编辑器创建了一个.png文件,我想要成为背景,有三个透明盒子供插槽动画师使用.
绘制背景的代码:
public class SlotMachineBackground extends JPanel
{
private ImageIcon image;
public void paintComponent (Graphics g)
{
super.paintComponent (g);
image = new ImageIcon ("/Users/Documents/slotmachine.png");
image.paintIcon (this, g, 0,0);
}
}//end class
Run Code Online (Sandbox Code Playgroud)
然后我做了插槽动画师:
public class SlotAnimator extends JPanel implements ActionListener
{
private Timer animator;
private ImageIcon imageArray []= new ImageIcon [22];
int currentFrame = 0;
int slotNumber = 1;
int box = 1;
SlotMachine m = new SlotMachine ();
String [] mP = m.returnTurn();
public SlotAnimator (int delay)
{
for (int …Run Code Online (Sandbox Code Playgroud)