Best place to load Images in applet game

Sorry for the double post but I just realised I originally posted this in completely the wrong forum!
Hello,
I have made a fairly basic game of 21/BlackJack and was wondering where the best place to load the card Images is/was...
Currently I am loading the images into an Image[ ] in the applet class, but was thinking maybe the loading should be done in the deck or card class?
In the applet class I use an ordered version of the deck to assign the cards in the image[ ], then to call an image I generate an index number based on the current cards value and suit....
However this method means I have to create an instance of the deck in the main program, whereas before I had it as a private member of the dealer class, so only the dealer could access it (which seems "safer", no?)
So would a better idea be to have a loadImage() method in the deck class, which populates an Image[ ] with the cards and pass this to the main program?
Thanks

Ken,
Loading images is slow so you only want to do it once... maybe when you generate the deck ... and "image" is definately an attribute of the card, yes... I'd actually implement the loadImage() as a method in the card class so set a private image variable... and then get the the dealer to call the loadImage method for each card as "he" builds the deck.
But that's just how I would do it... and I'm no guru so don't take it as gospel... I'd be surprised if there wasn't atleast one "purer" way of doing it.

Similar Messages

  • Loading Images into Applets

    I've been having problems loading an image into an Applet. I've found that when the getImage() call is put into the init() method it loads the image fine, also implementing an imageUpdate call. However, now I'm trying to expand on this by putting it into a button click, it hangs indefinitely while waiting for the image to load.
    Another interesting point I've noticed is that the Canvas subclass ImageSegmentSelector uses a PixelGrabber in its constructor to put the Image into a buffer - when this class is created from the imageUpdate() call, NOT the init() call, the grabPixels() call hangs indefinitely too!!
    Any feedback, please,
    Jonathan Pendrous
    import java.applet.*;
    import java.net.*;
    import jmpendrous.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    public class XplaneGlobalSceneryDownloader extends Applet implements ActionListener{
    ImageSegmentSelector worldMap;
    Image img;
    URL url;
    int longtitude = 36;
    int latitude = 18;
    boolean imageLoaded;
    TextField t1, t2,t3;
    Label l1,l2,l3;
    Button b1;
    Applet a1;
    public void init() {
    a1 = this;
    l1 = (Label) add(new Label("Number of horizontal sections: "));
    t1 = (TextField) add(new TextField("45",3));
    l2 = (Label) add(new Label("Number of vertical sections: "));
    t2 = (TextField) add(new TextField("45",3));
    l3 = (Label) add(new Label("URL of image file: "));
    t3 = (TextField) add(new TextField("file:///C:/java/work/xplane_project/source/world-landuse.GIF",60));
    b1 = (Button) add(new Button("Load image"));
    b1.addActionListener(this);
    validate();
    // THIS CODE WORKS FINE ...
    /*try { url = new URL("file:///C:/java/work/xplane_project/source/world-landuse.GIF"); }
    catch(MalformedURLException e) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false) { try { Thread.sleep(1000);   } catch(InterruptedException e) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();*/
    //repaint();
    //worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    //repaint();
    public void actionPerformed(ActionEvent e) {
    try { longtitude = Integer.parseInt(t1.getText()); } catch (NumberFormatException ex) {System.exit(0); }
    try { latitude = Integer.parseInt(t2.getText()); } catch (NumberFormatException e2) {System.exit(0); }
    try { url = new URL(t3.getText()); }
    catch(MalformedURLException e3) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false)
    { try { Thread.sleep(1000);   } //KEEPS ON LOOPING
    catch(InterruptedException e4) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(a1, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();
    public boolean imageUpdate(Image i, int flags, int x, int y, int w, int h){
    // THIS NEVER GETS CALLED AT ALL //
    if (((flags & ImageObserver.WIDTH) != 0) && ((flags & ImageObserver.HEIGHT) != 0)) {
    //worldMap = new ImageSegmentSelector(this, i, longtitude, latitude);
    //add(worldMap);
    //validate();
    //repaint();
    imageLoaded = true;
    return false;
    return true;
    }

    Sorry, thought this had been lost.
    You can load a file if the applet itself is run from the local filesystem - it loads it fine from the init(), but not otherwise. But I haven't got the applet to run from a browser yet without crashing (it's OK in the IDE debugger), so that's the next step.

  • Loading Images in Applets

    Is it possible to use the Toolkit class to load images in "unsigned" applets. I tried that but it throws a security exception:
    com.ms.security.SecurityExceptionEx[MyApplet.init]: cannot access file http://localhost/MyApplet/images/Image1.gif
    Though I am reading the image from the server not the client machine.
    Any help would be appreciated.
    Thanks in advance,
    Samer Meqdad

    Here's the code:
    Image img;
    img = Toolkit.getDefaultToolkit ().getImage (getCodeBase() +  "images/MyImage.gif");The exception thrown is:
    com.ms.security.SecurityExceptionEx[Host]: java.io.IOException: bad path: C:\Documents and Settings\samerm\Desktop\file:\C:\MyApplet\images\MyImage.gif
         at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java)
         at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
         at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
         at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
         at com/ms/security/StandardSecurityManager.checkRead (StandardSecurityManager.java)
         at com/ms/awt/WToolkit.getImageFromHash (WToolkit.java)
         at com/ms/awt/WToolkit.getImage (WToolkit.java)
         at DiamondsApplet.init (DiamondsApplet.java:54)
         at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
         at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)

  • Problem with loading image to Applet.

    Hello. Im preety new to Java, and currently ive got problems with adding an image to my applet. I tried to make game, similar to Mario - a platform based one. I found a source code of something close to that, and wanted to test but i couldnt get images loading. Here's the code :
    Main class :
    package pl.wat.edu;
    import java.applet.*;
    import java.awt.*;
    public class Main extends Applet implements Runnable{
         Thread th;
         private final int speed = 15;
         private Level obecny_poziom;
         private Image dbImage;
         private Graphics dbg;
         MediaTracker mt = new MediaTracker(this);
         private Image ziemia1;
         @Override
         public void destroy() {
              // TODO Auto-generated method stub
              super.destroy();
         @Override
         public void init() {
              // TODO Auto-generated method stub
              super.init();
              setSize(stale.wielkosc_apletu_szerokosc, stale.wielkosc_apletu_wysokosc);
              //setBackground(Color.blue);
              //ziemia1 = getImage(getCodeBase(), "g1.GIF");
              obecny_poziom = new Pierwszy(this, this);
         @Override
         public void start() {
              // TODO Auto-generated method stub
              super.start();
              // create new thread
              th = new Thread (this);
              // start thread
              th.start ();
         @Override
         public void stop() {
              // TODO Auto-generated method stub
              super.stop();
              // Thread stop
              th.stop();
              th = null;
         public void run() {
              // TODO Auto-generated method stub
              while (true){
                   repaint();
                   try
                        Thread.sleep(speed);
                   catch (InterruptedException ex)
                   // do nothing
         @Override
         public void paint(Graphics arg0) {
              // TODO Auto-generated method stub
              super.paint(arg0);
              //arg0.drawImage(ziemia1,10,10,this);
              obecny_poziom.paintLevel(arg0);
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint(dbg);
              g.drawImage (dbImage, 0, 0, this);
    }and Level class that have draw levels from String rows :
    package pl.wat.edu;
    import java.applet.Applet;
    import java.awt.*;
    public abstract class Level {
         //private LevelElement [] elements;
         private WorldTile [] tiles;
         private WorldTile[][] tablica_kolizji;
         private Color [] colors;
         private Component parent;
         private int lewa_granica;
         private int prawa_granica;
         private int dlugosclevelu;
         private Image ziemia = null;
         private Image titi;
         private Applet applet;
         public abstract void resetLevel();
         public Level(Component parent, Applet applet) {
              super();
              this.parent = parent;
              this.applet = applet;
              ziemia = applet.getImage(applet.getCodeBase(), "g1.GIF");
         public void initializeLevel(String [] definitions){
              tablica_kolizji = new WorldTile [stale.dlugosclevela] [definitions[0].length()];
              lewa_granica = 0;
              prawa_granica = stale.wielkosc_apletu_szerokosc;
              int licznik_kratek = 0;
              for(int i=0; i<definitions.length; i++){
                   char [] definition_line = definitions.toCharArray();
                   for(int j=0; j<definition_line.length; j++){
                        if (definition_line[j] == ':')
                             tablica_kolizji[i][j] = null;
                        else if (definition_line[j]== 'g'){
                             Ziemia tile = new Ziemia(j*stale.szerokoscTile, i*stale.wysokoscTile, stale.ziemia_id, ziemia, parent);
                             tablica_kolizji[i][j] = tile;
                             licznik_kratek = 0;
              tiles = new WorldTile [licznik_kratek];
              int licznik = 0;
              for (int i = 0; i<tablica_kolizji.length; i++){
                   for(int j=0; j>tablica_kolizji[i].length; j++){
                        if (tablica_kolizji[i][j] != null){
                             tiles[licznik] = tablica_kolizji[i][j];
                             licznik++;
         public void paintLevel(Graphics g)
              try
                   // draw background
                   // draw all elements in elements array
                   for(int i=0; i<tiles.length; i++)
                        tiles[i].rysujTile(g);
              catch(Exception ex)
                   // do nothing
    Any ideas why this Image doesnt show up ?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    michali7x4s1 wrote:
    Thats a code i found somewhere, tried to check how some things work.Have you used exceptions before? If not, please read the sun tutorial on them as they are very very important. Also, whether this is your code or someone else's doesn't matter as it's yours now, and you would be best served by never throwing out exceptions as is done in this code. It's like driving with a blindfold on and then wondering why you struck the tree. It's always best to go through the tutorials to understand code before using it. If it were my project, I'd do it in Swing, not AWT. Fortunately Sun has a great tutorial on how to code in Swing, and I suggest you head there as well. Best of luck.

  • Loading images inside applet JAR

    Hi
    This is my issue: I have an applet which contains images inside the applet JAR. I want to display these images in my applet, but apparently due to browser access restrictions, I'm not allowed.
    My first code was like this:
    //security restrictions on browsers do not allow getResource
    ImageIO.read(MyClass.class.getResource("imgs/img.png"));
    //getResourceAsStream should be allowed by browsers
    ImageIO.read(MyClass.class.getResourceAsStream("imgs/img.png"));Both lines work when I execute the applet locally (command line / programming IDE), but when I deploy it to my web server, the resource "imgs/img.png" becomes a relative URL to my web application context (like /webcontext/MyClass/imgs/img.png). It works locally because the call to getResource returns a URL object with "file:" protocol, but I need it to look for my images bundled inside the JAR, not web hosted images.
    I need to avoid making the applet look for these images as a web resource... how can I do it?
    Thanks!

    dev@java wrote:
    warnerja wrote:
    I'm not convinced the code you posted wouldn't work, but since this is an applet, you have access to the Applet class. Check out the Applet.getImage method in conjunction with Applet.getCodeBase.
    [http://java.sun.com/javase/6/docs/api/java/applet/Applet.html]
    getCodeBase returns my web context, like http://myhost.com/mycontext/ , so it is pretty much the same as above.
    Thanks for your replyThat is the way to load resources though. Hence back to my earlier statement about not being convinced it would not work, with this addition: It should work, assuming you actually do have the resources properly located with the web app, whether they be in a jar, or loose files relative to where the web app is. My guess at this point is that they are not.

  • Loading images in j++

    is there any way to load images in ms j++ other than using the PictureBox function? A friend showed how to load using bitmap class I think, I'm not sure, but I couldn't get the code down. the Image class isn't working either with j++, i'm not sure why.
    Anyone have a good suggest on the best way to load images in j++?

    I would suggest staying with the Java-specific routes, rather than any J++ tools. Unless you have absolutely no need to port this.
    There are many good articles on how to load images, as well as the entire Java Media Framework.
    Just hit up your favorite search engine, as well as java.sun.com

  • Loading Images in Applications

    Hi.
    I know how to load images in applets with the getImage method that comes with the Applet class, but I cant seem to find a way to do it in an application.
    I found a Toolkit class, but that required me to extend it when I am already extending the Frame class.
    The Frame class comes with a getImage method, but that requires a getCodeBase() method that comes with the applet class.
    How would I get an image using an application?
    Thanks in advanced
    Glen.

    You don't need to extends Toolkit to impelement its abstract method. you can get default Toolkit by calling static method in Toolkit, getDefaultToolkit().
    Toolkit kit = Toolkit.getDefaultToolkit();

  • Problem loading images in my applet

    Hi guys,
    When i test my Applet using an IDE the images are loaded fine, however when I run my applet using a browser it wont load the images.
    I think it is because I use this line:
    System.getProperty("java.class.path",".")My question is, how do you load images into an applet without signing it.
    Any help would be great.
    Alex

    Axilliary files like images, properties files etc. which are essentially part of the program are refered to as "resources". The best way to access these files is by the getResource() methods in the Class or ClassLoader objects. If you do it that way then the JVM reads them exactly the same way it reads .class and from the same place.
    Say your using an image, say my.gif from a class called MyClass. You put the image file in the same directory as the MyClass.class file. Then, in MyClass, you do:
    static ImageIcon myImage = new ImageIcon(MyClass.class.getResource("my.gif"), "MY Image");That will pick up the image from a file, from an http connection, from a jar, of from any combination of same.

  • 2 HD laptop setup - Best place to put Catalog, Cache, and Images??

    If I have two 500GB 7200rpm hard drives in my MBP, what is the best place for LR3, the catalog/previews, ACRcache, and the image files themselves?
    SATA3 connection for both HDs
    Should the boot drive hold the app and cache, while the second drive hold the files and catalog?
    Should the catalog and cache always stay on the same drive?
    Does it matter at all where the image (raw) files sit?
    Thanks!!

    I'd just keep the images on a different drive with a 2 internal drive setup.

  • Keep place cursor loaded to repeatedly place the same image

    I'm trying to find a way to keep the place cursor loaded with an image that I want to place many times... an image such as a 'New' graphic (internally we call it a 'New ping') for templated catalogue pages.
    I don't want to constantly have to place or copy and paste, or step and repeat once placed because when I place these pings, I will do is choose several different pings to import at once such as 'New', 'New look', 'Updated' etc, and each of these could be placed three or four times per spread.
    Is there a way?
    Thanks.

    Yeah, we know the conveyor can do that, but we were hoping that there was a way to do it without using the conveyor as it's not quite as fluid for workflow as we would like... but hey, if you don't ask, you don't find out!
    If you've got your cursor loaded with several images, it's easier to using the arrow keys... well to us it would be.
    I'll make a feature request I think.
    Thanks anyway.

  • Looking for best apple software for image extraction i.e. select an image from one photo and place it on another photo

    looking for best apple software for image extraction i.e. select an image from one photo and place it on another phot

    Cannot guarantee it's the best, but it certainly is the least expensive:
    http://www.gimp.org/downloads/

  • Best place for images outside of MS Store App?

    Newbie question? If multiple Apps share many images, where is the best place to keep them? 
    There will be hundreds of images in each App - some of them duplicate between Apps. I do not want to house them in the Images folder of the C# source code because they may change as time goes on. I would like to locate them "outside" the App and
    retrieve them when necessary if possible.
    I tried parking them in a website and accessing them this way: 
    ImagePath="http://mywebsite.com/Cookbooks/Receipts/English/Pages/Receipt1.1.1.png". But Go Daddy says I cannot house them that way for a MS store App. 
    So, where is the *best* place to put these images? Website, Web server, OneDrive, Azure, etc. Any other directions for building a scalable and flexible App would be appreciated. Thanks. 
    FS

    Hi,
    I think that's depend on your scenario.
    you could also use Windows Azure Mobile Services. There's a good Todo app sample on the following site -
    http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started/
    Or you can use web service, we can use httpClient to communicate with it.
    Please follow this document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh761504.aspx
    Best Wishes!
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
    href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

  • Display images in applets

    hi every body.
    I want to display images in an applet when i invoke it from the jsp page . it is not working. the code is as follows.
    <html>
    <body>
    <jsp:plugin type = "applet"
         code ="Welcome.class"
         width="475" height = "350" >
    </jsp:plugin>
    </body>
    </html>
    while the code of "Welcome.java" is as follows.
    ImageIcon image = new ImageIcon("aa.gif");
    JButton button = new JButton(image);
    i have placed the aa.gif file in the same directory where i placed the Welcome.class and the jsp file.
    when i run this program the i recieve the message that the applet is not loaded.
    can some body help me how to place images in applets.
    thanks.

    You should be able to test that applet on you hard drive first. If it works check the case of the image file.
    Web servers look for case. If you are asking for ImageIcon img = new ImageIcon("abc.gif") and what is loaded on your web server is "abc.GIF" it won't find it. Same goes for basic HTML tags like
    <Img src=abc.gif>. But it will find it on you hard drive when you run the applet there.

  • Help with images within applets

    I created a card game applet which calls images placed within the same directory. In appletviewer the game runs fine,not in browsers. I downloaded the browser plugin since i use swing classes. If I remove the image the applet loads up without the grafix. Here is the IO error generated. I thought applets can read files within the same directory and sub directories? Would creating a jar file solve this problem? Anyhelp would be appreciated.
    java.security.AccessControlException: access denied (java.io.FilePermission main2.gif read)

    When running in a browser, your applet must be signed in order to be able to access local resources. Check out the "Signed Applets" forum for many discussions about this, as well as methods for signing applets.

  • IPad safari don't show loaded images until slide the screen

    i have a problem in iPad Safari. when i use Javascript to append image to div using elm.appendChild(img) the images don't appear until the screen is touched. the same code works perfect on IE,Firefox,Chrome,and android browsers.i have uploaded video that shows the problem. http://www.youtube.com/watch?v=nBN9fThDik8is it related to the device ? or there some special code for loading images in iPad safari?or any solution ?

    Hi there and welcome to the User Forums!
    What you are looking for is a full-motion video recording.
    Captivate 2 has full-motion available, but the product is designed
    to use it for only brief periods - for capturing such things as
    grabbing a scroll elevator, or a drag-n-drop of a file object. It
    is definitely not designed for on-going, continuous video capture.
    If you upgrade to Captivate 3 you will find expanded full-motion
    capabilities.
    Other alternatives include the use of software designed
    specifically for creating AVI videos. One popular software package
    for this is Camtasia, but there are hundreds available out there -
    just "Google" for a string like "
    create video".
    Having said that, if you use Captivate as intended, the
    action you describe can be captured easily, and with amazing
    clarity and real-time appearance of your actual activity. This is
    not really the place to conduct a complete seminar on the product,
    but there are more than a half-dozen tutorials (created in
    Captivate) accessible on the main user interface (UI) - look in the
    right-hand column on that UI. The titles tell you what each
    contain. There is also a sample movie or two that was included with
    the install. You might find it helpful to open that and after
    looking at the timeline and other features, use the Preview feature
    to see what a Captivate movie looks like.
    After looking at some of those resources, come on back here,
    as you will probably have more specific questions we can help with.
    Best of luck to you.
    .

Maybe you are looking for