Rolling Images for poker Game

Hello everybody,
i m trying to make poker game in java. it is some what like this, there will three labels which will show continuos scrolling images or numbers. there will a button "HIT" button to stop moving images.after that those images will stop one by one.if all images are same then he will get message of congratulation. first of all i m trying to show numbers in labels. but it should look like it is rolling. with settext method it is directly printing the number. can anybody suggest me how to print number in Jlabel with rolling effect? . Thanks in advance

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class SpinningGeeks extends JPanel implements ActionListener,
                                                     Runnable {
    BufferedImage image;
    Rectangle[] rects;
    int[] yPos;
    int dy = 3;
    Random seed = new Random();
    boolean[] runs = new boolean[3];
    Thread thread;
    long delay = 25;
    boolean stopping = false;
    public void actionPerformed(ActionEvent e) {
        String ac = e.getActionCommand();
        if(ac.equals("START"))
            start();
        if(ac.equals("STOP"))
            stopping = true;
    public void run() {
        int[] ds = new int[yPos.length];
        for(int j = 0; j < yPos.length; j++) {
            ds[j] = dy -1 + seed.nextInt(3);
        int runIndex = 0;
        boolean countingDown = false;
        long time = 0;
        while(runs[runs.length-1]) {
            try {
                Thread.sleep(delay);
            } catch(InterruptedException e) {
                break;
            if(stopping && !countingDown) {
                int remainder = yPos[runIndex] % rects[runIndex].height;
                boolean atEdge = remainder < ds[runIndex]/2;
                if(atEdge) {
                    // Stop here, start waiting 2 seconds before
                    // moving on to stop the next image.
                    countingDown = true;
                    time = 0;
                    runs[runIndex] = false;
                    runIndex++;
                    if(runIndex > runs.length-1) {
                        continue;
            } else if(countingDown) {
                // Wait 2 seconds before stopping the next image.
                time += delay;
                if(time > 2000) {
                    countingDown = false;
            // Advance all images that have not been stopped.
            for(int j = 0; j < yPos.length; j++) {
                if(runs[j]) {
                    yPos[j] += ds[j];
                    if(yPos[j] > image.getHeight()) {
                        yPos[j] = 0;
            repaint();
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        int pad = 5;
        int x = (getWidth() - (3*rects[0].width + 2*pad))/2;
        int y = (getHeight() - rects[0].height)/2;
        for(int j = 0; j < rects.length; j++) {
            rects[j].setLocation(x, y);
            x += rects[j].width + pad;
        Shape origClip = g2.getClip();
        for(int j = 0; j < yPos.length; j++) {
            x = rects[j].x;
            y = rects[j].y - yPos[j];
            // Comment-out next line to see what's going on.
            g2.setClip(rects[j]);
            g2.drawImage(image, x, y, this);
            if(yPos[j] > image.getHeight() - rects[j].height) {
                y += image.getHeight();
                g2.drawImage(image, x, y, this);
        g2.setClip(origClip);
        g2.setPaint(Color.red);
        for(int j = 0; j < rects.length; j++) {
            g2.draw(rects[j]);
    private void start() {
        if(!runs[runs.length-1]) {
            Arrays.fill(runs, true);
            stopping = false;
            thread = new Thread(this);
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
    private void stop() {
        runs[runs.length-1] = false;
        if(thread != null) {
            thread.interrupt();
        thread = null;
    private JPanel getContent(BufferedImage[] images) {
        // Make a film strip assuming all images have same size.
        int w = images[0].getWidth();
        int h = images.length*images[0].getHeight();
        int type = BufferedImage.TYPE_INT_RGB;
        image = new BufferedImage(w, h, type);
        Graphics2D g2 = image.createGraphics();
        int y = 0;
        for(int j = 0; j < images.length; j++) {
            g2.drawImage(images[j], 0, y, this);
            y += images[j].getHeight();
        g2.dispose();
        // Initialize clipping rectangles.
        rects = new Rectangle[3];
        for(int j = 0; j < rects.length; j++) {
            rects[j] = new Rectangle(w, images[0].getHeight());
        // Initialize yPos array.
        yPos = new int[rects.length];
        for(int j = 0; j < yPos.length; j++) {
            yPos[j] = 2*j*images[0].getHeight();
        return this;
    private JPanel getControls() {
        String[] ids = { "start", "stop" };
        JPanel panel = new JPanel();
        for(int j = 0; j < ids.length; j++) {
            JButton button = new JButton(ids[j]);
            button.setActionCommand(ids[j].toUpperCase());
            button.addActionListener(this);
            panel.add(button);
        return panel;
    public static void main(String[] args) throws IOException {
        String[] ids = { "-c---", "--g--", "---h-", "----t", "-cght" };
        BufferedImage[] images = new BufferedImage[ids.length];
        for(int j = 0; j < images.length; j++) {
            String path = "images/geek/geek" + ids[j] + ".gif";
            images[j] = javax.imageio.ImageIO.read(new File(path));
        SpinningGeeks test = new SpinningGeeks();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test.getContent(images));
        f.add(test.getControls(), "Last");
        f.setSize(400,300);
        f.setLocation(200,200);
        f.setVisible(true);
}geek images from [Using Swing Components Examples|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html]

Similar Messages

  • Using disk images for learning games?

    Hello, I've 2 g3 imacs running 9.2.2, and they are for the grandkids to use learning games on.
    The kids are very hard on the software disks. When I found out about disk images I made them up, now to install them properly. The games are installed, but where to store the disk images? The desk top icons for the games will work after the disk images have been double clicked and the mounted disk image appears on the desktop, but when the imacs are turned off the mounted disk image is lost. How or where does one put the disk images in a safe place so the kids don't get at them, and the disks are mounted every time, without actually starting, when the Mac is started? Start up menu?
    I'm planning on multiple accounts with them having a standard account with game privileges so they don't mess the whole thing up. If their accounts get too messed up for me to repair I figured on maybe deleting the account and opening up a new one? Any Ideas are very welcome.
    Thank you,
    EZ

    Hi, EZ -
    You're quite welcome.
    I had a thought with regard to the disk image files. Are they in a .smi format, or are they in a .img format?
    The .img format requires the assistance of the Disk Copy utility in order to mount the image. This is the standard format generated by the user version of Disk Copy. It requires that Disk Copy be available to Finder to act as a helper app in order to mount the image.
    The .smi format does not - .smi stands for Self-Mounting Image. The user version of Disk Copy can not make this format; but I have seen a utility to convert .img format to .smi format. The slight advantage with this format is that Disk Copy does not need to be available to Finder.
    In both cases the default is to run a checksum verification before the image is finally mounted. The delay caused by this verification can be inconvenient - verification is intended to confirm the integrity of the image after it has been copied, transported, or downloaded, but is usually not necessary when the image resides on a hard drive.
    The checksum verification for .img file types can be removed. With the image not mounted, open Disk Copy. In Disk Copy's Preferences (Edit menu), uncheck the Verify Checksum item. Save the Preferences window. Then select Convert Image from the Image menu, navigate to the disk imge file from which you want to remove the verifiaction, select it and click the Open button. A new window will appear, similar to a Save As type window. Leave everything in that window untouched (unless you want to change the base name of the file - the extension .img should be left intact) and click the Save button. The image will be mounted, the original disk image file will be deleted, and a new disk image file created. Unfortunately creating the new image file takes quite a while since it is creating a new one, not actually modifying the old one - but it does get rid of the intrusion of the checksum verification requirement.
    I verified on my G4/500 running OS 9.1 that a .img file (one I had made from a game CD years ago) dropped into the Startup Items folder will be mounted automatically at the end of the startup sequence. I also tested with an alias to the .img file, and it, too, worked fine - the disk image was mounted automatically at the conclusion of the startup sequence.
    When you make the alias to the disk image file (the .img one), be sure you are placing it into the Startup Items folder, and not the Startup Items (disabled) folder.
    If you have the machine set to use Simple Finder (which removes Finder's keyboard commands and many menu options for Finder), that may interfere with items in the Startup Items folder being run at startup. Or, it may not - I have not checked that.
    *** Edit ***
    I have verified that the alias to a .img file will mount the disk image even when the machine is booted using Simple Finder.
    Another thought, related to Multiple Users - if you do decide to set up Multiple Users, and the disk images are of type .img, be sure to authorize Disk Copy for each of the accounts for which the disk images are to be mounted. If you have the disk image files in a .smi format, since Finder views that file type as being an application, you would need to authorize each of those disk image files for each account which is to have access to them.

  • Optimal communication strategy for poker game

    Hi,
    I'm designing a client/server poker game, and I'm trying to decide on the best protocol for client/sever comms. It's a personal project, so it doesn't need to be 100% robust or extensible.
    I was thinking of the following model:
    Client(s) and server communicate via Object Input/Output Streams over a socket. Client opens a Listener thread which listens in a while(true) loop, and Server also listens in a while(true) and processes incoming messages. The communication workflow will follow a request-response model.
    I will create my own Message class(String sender, int msgType, Object msgValue), and both listening classes will use switch(msgType) statements to process requests.
    Does anybody have any recomendations/stipulations regarding this model? There are a couple of issues I can think of:
    1. Use of while(true) loops should be avoided
    2. What happens to forever-listening ObjectInputSrteams when the client disconnects unsafely?
    3. How should the server handle client disconnects? Is it sufficient to use the onWindowClose method in the client GUI?
    Any feedback appreciated, thanks in advance,
    Sean

    Why not use RMI instead of plain sockets? The server part can be a
    simple facade to the real poker server (which can be a simple POJO).
    The 'business logic' (the poker game itself) is handled by the real
    poker server while all communication stuff is handled by RMI. That way
    the clients don't have to be aware of the fact that they're talking to some
    thing remote and it frees you from implementing that communication
    layer with all its burden.
    kind regards,
    Jos

  • HT203433 I want to buy chips for a poker game and it keeps telling me to visit itunes/support

    I want to buy chips for a poker game and it keeps telling me to visit www.apple.com/support/support/itens/ww/. My credit card doesn't have a hold and it is a good credit card.  please someone help

    You need to contact itunes support.

  • Wanting to make a poker game for a message board

    I'm trying to start a java app that will be a poker game (texas holdem) where members of a message board can join and play each other. Is there a good tutorial on how to embed this type of project into a message boar/forum?
    thanks for any information.

    Most message boards use some kind of server side technology (servlet, jsp, asp,...) and most games use some kind of client side technology (applets, activex,...), so there's probably not a lot out there about it. It should be possible and sounds kind of interesting though.

  • My Mac Pro is not displaying any images for videos or games, it is showing sound and working but nothing else. DVD player is also coming up with an error.

    My Mac Pro is not displaying any images for videos or games, it is showing sound and working but nothing else. DVD player is also coming up with an error. I'm not sure why neither is working, it just suddenly happened. I have done nothing different.

    Lao Bo,
    yes, you can locate and copy a file from your HD to a USB key using UNIX commands. If you know the exact name of the file which you’re trying to locate, try this:
    find / -iname filename -print
    This command will search your entire internal disk for the particular filename. If you know that it’s within a particular user account, then you can save search time with this variation:
    find /Users/username -iname filename -print
    Either variation of this command will print all files found which have the given filename. Presuming that you’re able to identify the correct file, you can copy it to a USB key using the command
    cp -p filename_returned_by_find /Volumes/USB_volume
    If you’re not sure which volume name your USB key has, this command will show you what the possibilities are:
    ls /Volumes
    Please let me know if you have any trouble with these commands.

  • Images in Card Game

    Hi there,
    I have been programming a variation of a Poker game in Java and have finished most of it in command-line. I need to port it over into a JApplet now and am having a few problems with the images.
    As the layout is similar to Hearts, I wanted to use a JFrame, with JPanels for containing each part of the screen. I wanted to have a set of cards overlapping for the N, E, and W panels, but I cannot seem to get the images to show properly... I just get a grey box...
    Can someone help and give me some advice on how to do the layout and use the paint facility?

    Hi there,
    I have been programming a variation of a Poker game in Java and have finished most of it in command-line. I need to port it over into a JApplet now and am having a few problems with the images.
    As the layout is similar to Hearts, I wanted to use a JFrame, with JPanels for containing each part of the screen. I wanted to have a set of cards overlapping for the N, E, and W panels, but I cannot seem to get the images to show properly... I just get a grey box...
    Can someone help and give me some advice on how to do the layout and use the paint facility?

  • Images in my game applet

    I am having problems changing an image for buttons in my game applet. I can give them initial images but when i cant figure out how to change them.
    The method that houses the statement is static - but i cant use static method when i am getting images using getClass(). PLEASE HELP!
    P.S. My applet is housed in a jar!
    d6 = new ImageIcon(getClass().getResource("images/dom"+ active.playerDominoes[0].x + active.playerDominoes[0].y + ".gif"));
    domino6.setIcon(d6);
    //ERROR.............
    non-static method getClass() cannot be referenced from a static context
            d6 = new ImageIcon(getClass().getResource("images/dom"+ active.playerDominoes[0].x + active.playerDominoes[0].y + ".gif"));

    another easier way is:
    exchange getClass() with
    any class, like ImageIcon.class(The thing is that static classes "has no this" but the method
    getClass() returns the class of the this-object.)
    /n

  • New stream, low upload rate... Optimal Settings for streaming games?

    I've been fiddling around with FMLE for the past few days/weeks and trying to find the best quality to stream quality games such as Bad Comapny 2, Starcraft 2, Mass Effect 2, etc
    I am able to play games at max settings, but when I do the stream will lag so I choose to make the settings low enough so I can stream.
    The only probably right now is they seem quite blurry/pixelated - which is probably due to my upload rate of 0.8mbps from SpeedTest.net1
    My specs are:
    Resolution of 1680x1050 (Most of my games like Bad Company 2 are played at 1280x720 windowed mode)
    i5-2500K
    GTX 560 Ti
    12GB Ram
    1TB Hard Disk Space
    Windows 7 64bit
    Upload rate of 0.8mbps (and 5.0mbps download incase it is needed)
    http://www.justin.tv/mrshotzzzz/videos - Bad Company 2 at the moment... There seems to be a LOT of blurryness, but it seems quite smooth.
    http://www.twitch.tv/mrshotzzzz/b/293073526?id=293073526&channel=mrshotzzzz - This is my latest... (skip to 1:25 where I configure it to be good)
    When I fullscreen it, around the edges mainly, I see it is pixleted.
    I use 1280x720 input, and 640x360 output with 800kbps. Is it possible to make it better?
    Would an output of 640x360 with a bitrate of 650kbps be better?
    Would an output of 854x480 be better?
    Could changing my input size to 1920x1080 make my quality better?
    tl;dr What is the optimal settings for a good specced computer, but with a low upload rate (0.8mbps)?

    Hi,
    In iChat 3 or iChat 4 setting System Preferences > Quicktime > Streaming to 1.5Mbps is quite important.
    In Tiger (10.4.x) the Automatic Setting here is read as Zero by iChat and can cause issues even when the Speed is high enough.
    In Leopard for iChat 4 this Automatic setting is read as 384k by iChat (although this is the Minimum for a 4 way Video chat it may still cap your Internet Speed).
    If you have to change this iChat will need a restart if open.
    The real controlling factor is the Upload speed the Internet Connection speed has.
    There is one other place to help with the Bandwidth/Internet Connection speed.
    This is in iChat menu > Preferences > Video Section > Bandwidth Limit drop down.
    This can be changed during A/V chat and changes to the Bit rate iChat is using is shown in the Connection Doctor (Video Menu).
    This is best used when Really Fast Buddies (Processors and Internet Speeds) can tend to "Over-run" lesser speeded Buddies. It can also help if your ISP manages the Bandwidth/Internet Connection speed making it run slower or faster at different times of the day (Also look at Fair Usage Policies).
    There is no independent way to reduce the Frame rate that would have a direct effect on this.
    There are other apps that do use less demanding picture quality that in turn effects the Frame rate which can effect the Bandwidth needed/Used
    See this link http://www.ralphjohns.co.uk/page5.html#_other
    Scroll to numbers 5 through 8 for Apps, 9 through 12 for Web Browser options.
    13 is a PC app.
    14 & 15 works in Video only to MSN Buddies.
    The list does not have a reference to the Yahoo Beta 3 for Mac
    http://messenger.yahoo.com/mac/
    7:23 PM Wednesday; August 5, 2009
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"

  • Best workflow for creating games for pc and starling games in AIR

    best workflow for creating games for pc and starling games in AIR.
    I need to develop for tablets with starling and AIR as well as for pc without starling ie: downloading from a server.
    In starling you have to
    1. instantiate starling
    2. use texture atlases for loading graphic assets - well its the recommended way
    3. use juggler
    etc...
    ie: with all these differences is it best to:
    1. create completely different projects
    2. just create different classes for the starling specific parts
    3. use a conditional compile constant
        eg: CONFIG::STARLING
                "then do this"
    or      CONFIG::CPU
              "then do this"
    I currently have the latter but it feels a little messy. I would prefer separate classes for each platform where the image loading is concerned.
    There must be so many game developers out there but in large gaming companies that know exactly what to do. Perhaps you can point me in the right direction with a book or something.
    CHEERS

    The other thing is that I can't see the games being very different as you suggest. I have downloaded Lee Brimelows tut on creating a starling game on Lynda.com and the code is great for creating games using states for menu, play, gameover etc... The only difference is that he uses texture atlas and there is a great difference in loading them etc... so technically you would only need to handle them in a different class as collision and the rest of game play should be the same in both. I think!!!
    Well, actually not exactly but near enough - maybe it might be easier to create separate projects and just cut and paste the new code introduced.

  • Poker game experiencing lag problems

    I've recently written a semi-functional Poker game however I'm experiencing problems with the game slowing down drastically as game play continues. I only have some basic high school programming knowledge so please forgive me for my extremely poor coding practice. Included are are the source files and jar. Any help would be appreciated. Thanks

    Ducky24 wrote:
    Upon using the Net Beans profiler I am finding myself quite shocked. The results show that invoke my formatJButton some 181000 times however I have no idea why it is invoked such.You have your swingComponent() method being called from inside of your paintComponent() method, and that seems like a bad idea to me. Every time your screen redraws, it will call this method, and it seems to me that it should be the other way around -- Your swingComponent should be involved with changing things and then call revalidate() and repaint() to relayout and redraw things.
    Again, I can't force myself to look at all of your code, but I wonder if you should be using a CardLayout here to swap JPanels rather than removing and repositioning and such.

  • Poker game logic

    has anybody ever tried to make a poker game
    if you have, please help me.
    if you have not, please help me if you can.
    how would you check weather there is a winning hand.
    the possibilities are Royal Flush, Straight Flush, 4 of a kind, full house, flush, straight, 3 of a kind, 2 pair, pair.
    pseudocode would be very nice.
    also, if you know a website where i could find some examples, that would also be very nice.
    Thanks.

    Although I dislike using ints for enums, I might do it here on the groups that maps from Object to int aren't readily available, and constantly boxing and unboxing is nice. Anyway...
    Each Card should have a getSuit() method and a getValue() method. Have two arrays, int[] suitCount = new int[4], and int[] valueCount = new int[13]. Go through the five cards incrementing the various indices. Then e.g. you have a flush if one of the suitCount elements is 5; a full house if one of the valueCount elements is 3 and one is 2, etc. Straights are slightly more work - you could check them by initialising an int straightCount = 0 and then for i = 0 to 13 (because A counts high and low) if valueCount[i % 13] == 1 then {straightCount++; if straightCount == 5 you have a straight} else straightCount = 0.

  • Poker game logic(again)

    i think that this will be the last thread that i will start on the subject of poker.
    if you have not looked at the other poker game logic threads, it might help.
    if figured out ways to check for repeaded cards(2,3,4,2&2,2&3) and how to do the flush. I am only having trouble figuring out if ther is one of the straights(cards in ascending order).
    you can check the suit and the rank of each card and there are 5. how do you figure if they are in a particular order?
    THANX!

    Sort the card array by face value of card. then
    boolean straight()
    if( ((a[0]+1) == a[1]) && ((a[1]+1) == a[2]) && ... etc. )
    return true;
    You will have to account for ace-2-3-4-5 too though. or 10-j-q-k-ace depending on the value you assign an ace.

  • Why can,t i load the poker game fantasy poker

    why cant i not load the fantasy poker game poker

    Hello,
    What type of computer and internet connection are you using?
    MrMatthew - HP Support Forums Moderator
    Click the Kudos star as a way to say "thank you" for helpful posts.
    Be sure to come back and click the 'Accept as Solution' button on the post that solved your issue - it may help someone else.

  • Please make changes for contact image for for full screen... I bought Iphone Only for full screen contact image so please make changes for full screen contact image...

    Please make changes for contact image for for full screen... I bought Iphone Only for full screen contact image so please make changes for full screen contact image...

    I bought Iphone Only for full screen contact image
    Is that so? So you don't use ANY of the other features of the iPhone? You don't use the internet, apps, play games, make calls, take pictures, or ANYTHING else at all? You just wanted full-screen contact image?
    I don't believe you...
    Please make changes for contact image for for full screen
    Tell Apple: http://www.apple.com/feedback/

Maybe you are looking for