slot game
I'm making a vegas game as my first attempt at game programming in java. I've posted some of the questions that I have come across on other boards but I think that you all would be able to help me a bit more. The problem that I am having is with one of my slot machines. First I need to put some JButtons on the screen to acept the bet and spin and so on. Layout managers are no good for me because I need them at precise locations on the screen, problem is that the only method that I know is to set the layout to null, then I can set the size and location of my buttons, the drawback is that my background and reels are lost. Obviously I need a way to have everything on the screen at the same time, here is my code so far...
import java.awt.*;
import javax.swing.*;
import java.util.Random;
import javax.swing.JOptionPane;
publicclass SpudSlotTestextends JComponentimplements Runnable
{
Image[] images =new Image[10];
int x = (int)(Math.random()*10);
int y = (int)(Math.random()*10);
int z = (int)(Math.random()*10);
int frame = x;
int frame2= y;
int frame3= z;
int counter = 12;
publicvoid paint(Graphics g)
{
Image background =new ImageIcon("background1.png").getImage();
Image image = images[frame];
Image image2 = images[frame2];
Image image3 = images[frame3];
g.drawImage(background, 0, 0,this);
g.drawImage(image, 199, 150,this);
g.drawImage(image2, 475, 150,this);
g.drawImage(image3, 750, 150,this);
}
publicvoid run()
{
images[0] =new ImageIcon(
"spud1.png").getImage();
images[1] =new ImageIcon(
"blank2.png").getImage();
images[2] =new ImageIcon(
"cherries.png").getImage();
images[3] =new ImageIcon(
"blank3.png").getImage();
images[4] =new ImageIcon(
"triplebone.png").getImage();
images[5] =new ImageIcon(
"blank4.png").getImage();
images[6] =new ImageIcon(
"doublebone.png").getImage();
images[7] =new ImageIcon(
"blank5.png").getImage();
images[8] =new ImageIcon(
"bone.png").getImage();
images[9] =new ImageIcon(
"blank6.png").getImage();
int delay = 30;
try
{
int t = (int)(Math.random() * 10);
while (t<150)
{
int a = (int)(Math.random()*10);
int s = (int)(Math.random()*10);
int d = (int)(Math.random()*10);
frame = (frame+a)%images.length;
frame2 = (frame2+s)%images.length;
frame3 = (frame3+d)%images.length;
Thread.sleep(5);
repaint();
++t;
}
PayoutTest();
}
catch (Exception e){}
}
publicstaticvoid main(String[] args)
{
SpudSlotTest slot =new SpudSlotTest();
JFrame frame =new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1280, 800);
ImageIcon spin =new ImageIcon("spin.png");
JButton button =new JButton(spin);
button.setSize(110, 90);
button.setLocation(958, 487);
frame.getContentPane().add(slot);
frame.getContentPane().add(button);
frame.setVisible(true);
(new Thread(slot)).start();
}
}
Message was edited by:
Dr_Spud

