How do you make an array of image icons and then call them?

How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
Any help would be greatly appreciated, some code or link to tuturial, ect.
/** DiceRoller.java
* Roll, print, Gui
import javax.swing.*;
public class DiceRoller extends JFrame
     private ImageIcon[] image  ;
     public String[] images = { "empty", "dice1.jpg",
               "dice2.jpg", "dice3.jpg", "dice4.jpg",
               "dice5.jpg", "dice6.jpg" };
     public Dice die;
     private int rollVal;
     public int rollNum;
     private JLabel j1;
     public DiceRoller(){
          j1= new JLabel("");
       die =new Dice();
       int rollVal;
       rollVal = die.roll();     
       image = new  ImageIcon[images.length];
     for(int i = 0; i < images.length; i++){
      image[i] = new ImageIcon(images);
     if (image!=null){
          j1.setIcon(image[rollVal]);
     System.out.println("Roll = "+die.roll());

Demo:
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class IconExample {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable(){
            public void run() {
                launch();
    static void launch() {
        try {
            Icon[] icons = new Icon[6];
            for(int i=0; i<icons.length; ++i) {
                String url = "http://www.eureka-puzzle.be/cast/images/dice" + (i + 1) + ".jpg";
                icons[i] = new ImageIcon(new URL(url));
            display(icons);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
    static void display(Icon[] icons) {
        JPanel cp = new JPanel();
        for(Icon icon : icons) {
            cp.add(new JLabel(icon));
        JFrame f = new JFrame();
        f.setContentPane(cp);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}

Similar Messages

  • I have used Image Capture to scan images/documents and then saved them as either PDFs or PNG files.  For some reason, just this past week Image Capture will no longer save the file.  It scans, and the Scan Results window pops up, but it won't save file.

    I have used Image Capture to scan images/documents and then saved them as either PDFs or PNG files.  For some reason, just this past week, Image Capture will no longer save the file.  It scans, and the Scan Results window pops up, but it won't save file.
    The file name has no special character in it, just letters and no spaces.
    I have done this in the past and it has worked, but now it will not.
    I have not upgraded any software, that I am aware of.
    After scanning, the Image Capture pops up the Scan Results with the file name in the window, but neither the Scan Results nor the Image Capture window responds to inputs.  The Image Capture window is frozen, with only the "Overview" and "Cancel" buttons active (but non-responsive).
    Is this a software issue or a scanner hardware issue?  I am using a HP Photosmart C6200 series printer/scanner on a network using a Time Capsule airport.
    Thanks.

    I had the same problem.
    Got a 90% fix.  Apparently the Mavericks preferences won't work with Yosemite, so I just deleted the Image Capture preferences.
    Unfortunately, the "Scan to" folder seems to be permanently set to the Pictures folder.
    1.  Quit Image Capture
    2.  Go to Finder > Go > Home, which opens up your home folder (named after your user name)
    3.  Open Library > Preferences > com.apple.ImageCapture.plist - Drag this file to the Trash
    4.  Start "Image Capture", click "Details" and change all your settings as you prefer
    5.  Quit and restart "Image Capture".   Notice it remembers all your settings except "Scan to" folder.  It insists on saving to "Pictures".
    That's as far as I was successful.  I tried changing the "Scan to" folder to "Desktop", but on launch, Image Capture always sets it back to "Pictures".
    This is what I tried:
    6.  Download and install "Pref Setter" from http://www.nightproductions.net/prefsetter.html
    7.  Quit "Image Capture".  Right-click on "com.apple.ImageCapture.plist" and open with Pref Setter.
    8.  Search for "Pictures", which finds "~/Pictures" (the tilde character at the start means your home directory).
    9.  Double-click on "~/Pictures" and change it to the folder you prefer.  I like "~/Desktop"
    10. Choose File > Save then Quit from Pref Setter.  Note that re-opening the plist file still shows "~/Desktop"
    11. Start up "Image Capture" -- on startup, "Image Capture" sets "Scan to" folder to "Pictures"
    I consider this a bug.

  • I know how to add lyrics to a song in iTunes and then see them on my iPod. But now I'm interested in watching those lyrics on my windows pc...can I and how do I do that ?

    I know how to add lyrics to a song in iTunes and then see them on my iPod. But now I'm interested in watching those lyrics on my windows pc...can I ? What do I do so than I can see the lyrics of the song while it plays ?

    This is the correct behavior. When you play a song, the play count and last played time gets updated. When you resync the iPod, the track gets copied to the iPod to update these new changed fields.
    There is no fix for this, this is what it is supposed to do.

  • How do you make a spreadsheet or cells secure and private?

    In using numbers, I want to make a spreadsheet secure (limited access). How do you do this ..... Or how do you make the cells within it secure?

    Password protect the file (although there's some doubt as to the strength of that protection).
    save the file to an encrypted Disk Image. See Mac Help in the Finder's Help menu for details.
    There's no way to fully protect the cells of an open document. Numbers provides for locking "objects," but cells themselves are not objects. Tables are, objects, so you can lock a complete table. That prevents changes to the table until it is unlocked, but does not prevent changes to other tables in the document, nor does it prevent any used from unlocking the table then editing it.
    Jerry has offered a technique which may be used to guard against inadvertent changes to individual cells. You can read it in his responses in Hold Table Position in a Sheet.
    Regards,
    Barry

  • How do you make imessage work? The icon is there. You can type in the recipient but are not allowed to hit the send button

    How do you make imessage work? We upgraded to verision5. The icon is there. You can type the message but the send button is not available.

    There is some instability in  iMessage.  It is a versatile and confusing app even though there are so few options in its use. 
    I had issues trying to get iMessage work on both my iPads and my iPhone. 
    ON the iPhone, turning off WiFi service and then trying iMessage fixed the problem.
    On the iPad 2, same thing.  Turning off WiFi service fixed it.
    On the iPad 1, I took a suggestion from zoomzoom and changed the WiFi network configuration on the iPad to use 8.8.8.8 as a DNS server and then use iMessage.  That fixed it.   Now I put the DNS back to default and it still works.
    I suspect the iPod Touch will have the same fix as the iPad.
    If you have a WiFi and 3G iPad or iPhone, try turing off WiFi and see if that fixes it. 
    Why?  (beware, some of this is guesswork)
    iMessage can talk SMS to cellphones and smartphones (that are using the cell-network).  It can also talk Apple iMessage format to iPhones and iPads whether they are on cell-network or on WiFi.  If you are talking to an SMS cellphone, iMessage figures that out and blindly sends your message.  If you are talking to a iOS5 device, iMessage figures that out too, checks to see that they are on-line, and then does something different if they are or are not on-line.  If you type in an email address, and not a phone number, I think iMessage attempts to see if the email address is registered with Apple (or iCloud or whatever) and if it is not, it does something to let you know, possibly by making the Send button not light up. 
    In order to register iMessage and an email, you have to let the iOS device see whatever service it is that iMessage uses.  That is where the problem happenes.  zoomzoom suggested manually setting the WiFi DNS to google's 8.8.8.8 IP address, then run IMessage, and that seemed to fix the problem.  Setting the iOS device to use 3G-only (by turning off WiFi) also fixed the problem.  I suspect going down to StarBucks or McDonalds and using their WiFi would also fix the problem.  Once the problem is fixed, it doesn't seem to come back so I can't test these 'fixes'. 
    To change the DNS on your iPad find your WiFi networks configuration, click on the blue arrow, touch DNS, backspace over the number that is shown, type in 8.8.8.8    Then click on the WiFiNetworks button at the top of the screen.  Now go run iMessage.  After that, you can delete the DNS entry again and leave it blank.  Your iPad will fill it in from the WiFi router when it needs it.

  • How do you make it print first page first and not the last page first?

    I have a HP Officejet Pro 8600. How do I make the first page print first and not the last page printing first?

    Hi,
    From the application used to print open the print dialog and click Oroperties or Preferences to access the Printing Preferences screen.
    From the Layout tab set Page Order as Back to Front, then the first page will be printed first.
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • How can I store a form name with path and then call form from a table

    Is it possible that any form that I built I store that form in some table in DB and then call that form from table, if yes, then how can i get this functionality. I am not very experience in form and do not know if it can be done because i think if it is possible then this can be a good security for application and easy to handle as well.
    Thanks in advance
    Maz

    If you have a Forms block based on this table:
    declare
      module varchar2(100);
    begin
      module := :block.column;
      call_form ( module ) ;
    end;If you don't have any blok based on that table
    declare
      module varchar2(100);
    begin
      select  module_name
      into module
      from ...
      where ...
      call_form ( module ) ;
    end;Francois

  • How do you make the whites of the eyes and teeth brighter?

    Would someone be able to offer advice on making the "whites" of the eyes and teeth brighter or whiter? Thanks!

    There are a few videos done on this by the Kelby group. Basically, Create a levels adjustment layer, and move the right slider to the left, which would make more of the image go towards white.
    Then create a mask for that adjustment layer. Use the selection tools to create a selection of the white areas of the eyes. When you are done, click on icon at the bottom of the layers panel that looks like a circle inside of a square. That  will convert your selection into a mask. Make sure the adjustment level is selected before clicking the mask icon, as that tells the layers panel which layer to apply the mask to.
    If for some reason the mask is backwards, the eyes are darker than the rest of the person. You can click on the mask thumbnail that was just created on the adjustment layer to make it active, then invert the mask. Invert can be found in the select menu .

  • How do you make a motion tween, mask effect and shape tween, with a flash website?

    More of less, I will have three seperate pages for the motion tween, mask effect and shape tween... would you make the seperately, in a different scene, as a symbol or on the same scene with the website.

    It's not clear what you are after since you start talking about separate pages for the three things, and then ask about how best to put them together.  If they are going to be separate they can't be together.
    If your intention is to have these three things in one Flash file, ut as separate parts of it, then I would have each within a symbol and have each symbol within the same scene (I don't use multiple scenes).

  • How to select entire PDF document (scanned image content) and then edit?

    I have a PDF file of a booklet that was created by scanning the pages as images. Whoever did the job aligned everything nicely, but for some reason ended up with an output where the pages are all too dark. The white parts of the pages are gray. I can go into the Advanced Editing toolbar and use the tool on the far right, right click the page and choose Select All, then Edit Image and it opens in Photoshop. There, I just change the brightness/contrast and save it. Then when I go back to the PDF the page looks great. Problem is, it only does one page at a time under the "Select All" option, and the booklet has more than 40 pages. Is there a way to select all the pages then edit them in Photosop all at once somehow?

    I tried the other things suggested, but they didn't work, either. I ended up creating a new document and copying all of the text into the new document where it can be selected like normal. Go figure...

  • How do you make a CustomUserControl to a movable and resizable one.

    I have made an application where i am thinking i can implement a re-sizable and movable Usercontrol(Image) i tried the following codes but the code has to be also in the main form which will make re-sizing in runtime confusing. I just want to implement the
    codes inside the custom UserControl.
    Thanks in advance!

    Sorry, My previous question was pretty unclear. I have made my own Usercontrol in MS blend4 and i also added dependency property to it as follows
    IMAGECTRL.VB
    Public Property Propx As Integer
    Get
    Return GetValue(PropxProperty)
    End Get
    Set(ByVal value As Integer)
    SetValue(PropxProperty, value)
    End Set
    End Property
    Public Shared PropxProperty As DependencyProperty = _
    DependencyProperty.Register("Propx", _
    GetType(Integer), GetType(New_Window), _
    New PropertyMetadata(Nothing))
    Public Property Propy As Integer
    Get
    Return GetValue(PropyProperty)
    End Get
    Set(ByVal value As Integer)
    SetValue(PropyProperty, value)
    End Set
    End Property
    Public Shared PropyProperty As DependencyProperty = _
    DependencyProperty.Register("Propy", _
    GetType(Integer), GetType(New_Window), _
    New PropertyMetadata(Nothing))
    Public Property imgsrc As String
    Get
    Return GetValue(imgsrcProperty)
    End Get
    Set(ByVal value As String)
    SetValue(imgsrcProperty, value)
    End Set
    End Property
    Public Shared imgsrcProperty As DependencyProperty = _
    DependencyProperty.Register("imgsrc", _
    GetType(String), GetType(New_Window), _
    New PropertyMetadata(Nothing))
    I wanted to bind these dependency property to the elements of the "MainWindow.vb" but i have no clue how to. Since i am a beginner in the vb.net realm :)
    Hello,
    It seems that this is another issue in this thread, I would recommend you separate it in another thread to get help.
    Is there any update about your original issue?
    Regards,
    Carl
    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.
    Click
    HERE to participate the survey.

  • How do you make connection password use single username and password in P/S

    Hi
    I have installed OBIEE as a standalone on a Windows 2003 server using OC4J and AUTHENTICATION_TYPE = BYPASS_NQS.
    I have created a repository using an ODBC connection to a Netezza database. The implementation we have is that we use a single username and password (readonly) to the database.
    I have created the physical, business and presentation layers and the repository is consistent and loadas up into the Presentation Server.
    When I login into presentation server as say "Administrator", the PS passes the username/password of "Administrator" instead of the username and password setup in the connection pool.
    The error is;
    -------------------- Query Status: Query Failed: [nQSError: 16001] ODBC error state: HY000 code: 108 message: Password authentication failed for user 'ADMINISTRATOR'.
    When I create a user with the same username and password as the one used in the connection pool, the requests work. Although thisd lets me work at the moment, it is not a viable solution going forward.
    Please can you advise what I need to setup for this to work correctly for me ie., make PS substitute the correct username password when connecting to the ODBC defined in the connection pool?
    Thanks in advance.
    Danish.

    Apologies if I've misunderstood, but are you trying to implement anything than standard practise, namely:
    1) Using the OBIEE security model to authenticate and log in (i.e. when you log in to Answers you are entering a username as defined in the RPD)
    2) Using a fixed username & password as defined on the database to authenticate & authorise when you read data for your reports?
    If you use BYPASS_NQS then BI Server will take your login details when you login to Answers (Presentation Server) and pass them through to the database and see if they're valid. This is what's happening when you got the error that you initially posted. With setting at BYPASS_NQS try logging into Answers with the database username&password, I bet it will work.
    If you use NQS (the default) then it checks the Answers login against users defined in the RPD, so the reason you couldn't login when you changed it to NQS is that the user/pw you logged in with didn't match what's defined in the RPD.
    Try this:
    1. Create a new user & pw in the RPD, for argument's sake call it TestRPDUser with the same pw
    2. Set authentication to NQS and restart you BI Server
    3. Log in to Answers as TestRPDUser - does it work?

  • How do I make the red-green-yellow icons and the text in window title bars larger?

    The title text is a little too small to just see - I have to concentrate on it to read it - and I can't tell the red-green-yellow icons apart without staring at them. Yes, my sight is quite poor; I'm already sitting as close as I can.

    sorry about the slang display portal, i just mean the entire screen, like a magnifying glass. There is probably a keystroke, and it's probally all in here:
    I do agree it's a concern, as I have a torn retina, and my eye gets strained quickly.

  • Can you use ipad to back up photos and then remove them from iphone?

    I have a 16gb iphone which is reaching its usage limits.  I also have a 120gb ipad and want to use this to store my photos in order to free up space on my iphone.  Is it possible to set this up?

    Solomon.may wrote:
    Thanks for the response.
    I do not yet have IOS8 due to the lack of space on the phone.
    Update via iTunes, it requires much less space than trying to do it over the air.
    However, I presently have sufficient space on the icloud.  If I delete a photo from my camera roll will it fee up space and allow me to retain them on photostream?
    It will free up space, but not enough, hundreds will need to be deleted. Read my previous post.

  • How can you make one button preform different actions in Xcode?

    How can you make one button "preform a click" and "orderfront"? Is that possible? Because what I am doing is making a welcome window to my application for Mac OS X 10.6, and I have two buttons in that window, one says "Connect" which connects a a WebView to a url and the other button opens up the main window. So how can I a make a button do multiple things at once??

    Ah - If you are just using bindings between various objects from Interface Builder, you can reduce your application code a bit (sometimes quite a bit), but there is only so far you can go. Typically variables and routines are defined in your application that Interface Builder hooks into, so that your application code (usually Objective-C, but can be others) can use these variables and routines to determine what is happening in the user interface.
    I'm not sure how up-to-date the project code is (or what programming code you are familiar with), but you can take a look at Apple's Cocoa Application Tutorial to see what is (usually) involved in creating an application.

Maybe you are looking for