Swing using Images?

Hi, I'm a complete noob at swing to begin with, but I just need to know how to do one thing. Make a little window that has an image in it and a text box with a button underneath. So the user will see the image and type it in the box and click submit. It's like a macro detection thingy.
Except the image is from the internet, so how do I create an image swing object from an online image? Oh, and the image is dynamic so I'll need cookies to be working when I retrieve the image...

KrimsonEagl wrote:
Make a little window that has an image in it and a text box with a button underneath.for your window.
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.htmlfor your Image
http://java.sun.com/docs/books/tutorial/uiswing/components/label.html
http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#examplefor your text box.
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.htmlfor your button.
http://java.sun.com/docs/books/tutorial/uiswing/components/button.htmlSwing Components
http://java.sun.com/docs/books/tutorial/uiswing/components/index.html

Similar Messages

  • Fastest and simplest way to display a 2D grid in Swing, using images?

    Hi,
    I'm trying to draw a game-board in Swing. I've already figured out how to draw it in my teachers turtle-graphics thing, but I want to make my game a little prettier.
    I've managed to draw the entire GUI in Swing, and it has full functionality, I'm just missing the "drawMap()" method that should display the game in the level-JPanel.
    One of my friends at school already managed to do this, but he used -400- lines of code and two objects/classes. I hope there is a better way.
    The turtle version of my code is like this:
         void turtle() {
              int width = game.getGrid()[0].length;
              int height = game.getGrid().length;
              STG.home(true);
              String url = null;
              STG.up();
              for (int y = 0; y < game.getGrid().length; y++) {
                   for (int x = 0; x < game.getGrid()[y].length; x++) {
                        switch (game.getGrid()[y][x]) {
                        case WALL:
                             url = "/sokoban/icons/wall.png";               
                             break;
                        case EMPTY:
                             url = (game.getTargets()[y][x]) ? "/sokoban/icons/target.png" : "/sokoban/icons/tile.png"; // url = (boolean) ? iftrue dothis : elseiffalse dothis
                             break;
                        case MOVER:
                             url = (!game.getWinner()) ? "/sokoban/icons/mover.png" : "/sokoban/icons/happyMover.png";                         
                             break;
                        case CRATE:     
                             url = (!game.getTargets()[y][x]) ? "/sokoban/icons/crate.png" : "/sokoban/icons/crateOnTarget.png";
                             break;
                        default:
                             break;
                        STG.image(url, 30, 30, (width/2-x)+0.40, -height/2+y);
              }I'm pretty sure there has to be a similar way of doing this in Swing, without using hundreds of lines of code.
    Here's a screen-shot so there's absolutely no confusion about what I'd like to achieve:
    [http://img198.imageshack.us/img198/2815/40317025.png]
    I want to draw the game-board in the JPanel titled 'Level: 1'.
    Please point me in the right direction =)

    Thanks. The values of getGrid and iIcon are correct.
    I did make a working class that could draw up a map, what I'm having trouble with is implementing it in my GUI.
    I'm pretty new to this, and I'm miles ahead of what I am supposed to be doing at this time.. I guess I'm in way over my head, but still, I think it's a lot of fun, and I want to finish :)
    This is the working example
    package sokoban1;
    import java.awt.*;
    import javax.swing.*;
    public class DrawMap extends JFrame {
         private static final long serialVersionUID = 1L;
         ImageIcon tile           = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/tile.png");
         ImageIcon wall           = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/wall.png");
         ImageIcon target     = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/target.png");
         ImageIcon mover      = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/mover.png");
         ImageIcon happyMover      = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/happyMover.png");
         ImageIcon crate      = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/crate.png");
         ImageIcon crateOnTarget = new ImageIcon("C:/Users/David/Desktop/OOP/Workspace/ovinger/resources/sokoban/icons/crateOnTarget.png");
         char [][] testGrid = {{'#', '#', '#', '#', '#'}, {'#', ' ', ' ', ' ', '#'}, {'#', '$', '$', '$', '#'}, {'#', '@', '@', '@', '#'}, {'#', '#', '#', '#', '#'}};
         int height = testGrid.length;
         int width = testGrid[0].length;
         GridLayout sokobanMap = new GridLayout(height,width);
         final char WALL = '#' , EMPTY = ' ', MOVER = '@', CRATE = '$';
         public DrawMap() {}
         public void addComponentsToPane(final Container pane) {
              setResizable(false);
              final JPanel gamePanel = new JPanel();
              gamePanel.setLayout(sokobanMap);
              JPanel controls = new JPanel();
              controls.setLayout(new GridLayout(height ,width));
              ImageIcon iIcon = null;
              boolean b = true;
              for (int y = 0; y < height; y++) {
                   for (int x = 0; x < width; x++) {
                        switch (testGrid[y][x]) {
                        case WALL:
                             iIcon = wall;               
                             break;
                        case EMPTY: // url = (boolean) ? ifTrue this : ifFalse this
                             iIcon = (b) ? target: tile;     //game.getTargets()[y][x]
                             break;
                        case MOVER:
                             iIcon = (b) ? happyMover : mover; //game.getWinner()
                             break;
                        case CRATE:     
                             iIcon = (b) ? crateOnTarget : crate; //game.getTargets()[y][x]
                             break;
                        gamePanel.add(new JLabel(iIcon));
              pane.add(gamePanel, BorderLayout.NORTH);
          * Create the GUI and show it.  For thread safety,
          * this method is invoked from the
          * event dispatch thread.
         public void draw() {
              //Schedule a job for the event dispatch thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        //Create and set up the window.
                        DrawMap sokoFrame = new DrawMap();
                        sokoFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        //Set up the content pane.
                        sokoFrame.addComponentsToPane(sokoFrame.getContentPane());
                        //Display the window.
                        sokoFrame.pack();
                        sokoFrame.setVisible(true);
    }And this is my GUI [http://pastebin.com/RqprGWSy] (Well, NetBeans did most of the work, which might add to my confusion :p)
    The gamePanel is probably added, since I can see its frame, or maybe I'm misunderstanding something. I'll take a closer look.
    Thanks for all your help so far :)

  • When i use images in an applet, it shows the image url, how do i remove it?

    Ok, so when i open up an applet, and it uses images, it shows the url for each image, which is not good because my graphics could get stolen. Is there anyway to disable this?, i have never noticed it before.

    I notice the following from the documentation for one of the [ImageIcon constructors|http://java.sun.com/javase/6/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.net.URL)]: "Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image. The icon's description is initialized to be a string representation of the URL."
    I guess if you are using this - or something similar - Java runtimes might decide to show the string representation of the URL while they are loading the image. In this particular case there is another form of the constructor which allows you to actually set the description string.

  • How to use images from ADFLib

    Hello OTN,
    My application is devided into several ADFLibs, one of them is CommonUI. It includes common skin and it is imported into every application part.
    There are some images which should be available in different parts, so I decided to put them in CommonUI.
    After deploying adflibCommonUI adn refreshing Resource Palette, somehow I expected to see this image there, but it isn't.
    Could someone, please, explain me, how to use images contained in imported ADFLib, for example, as imageLink icon?
    Thanks.
    ADF 11.1.2.1

    Hi,
    images need to be saved in a specific file structure in the JAR file to be accessible. See:
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/86-images-from-jar-427953.pdf
    Frank

  • How to Use Image Processor for Multiple Sizes

    I'm trying to use Image Processor to work on a folder of images and to create several sizes of .jpg's . I find an option to Save as JPEG in one size only. Is there any way to set up Image Processor to save JPEG to multiple sizes?
    Thanks in advance for your help!!!

    Hi Mehtap,
    Using the script will give you multiple selections.
    This is how I did it and it works well. It just separated the values by semicolon ";" .
    TEXT_1.setText(DS_1.getFilterText("0CUSTOMER"));
    When selected only one value:
    When selected more than one value:

  • Using Images in Spry Dropdown Menus??????

    I am in the middle of making a web site that needs a drop down menu for one of the top navigation menu buttons, when I designed the web site I created my  own buttons (images) in photo shop. When I went to create me navigation bar I tried to insert images in the spry menu bar, so that I can have my imaged and have the drop down menu but that didn't work, so then I tried to use a table and insert the images there and in the cell that needs the drop down bar I put in a spry menu bar but that through the whole navigation bar off. Can anyone help or does anyone know how to use images in spry drop down menus that can help me have the look I want and the drop down menu?

    Have a look here http://www.adobe.com/devnet/dreamweaver/articles/spry_widgets_design_04.html
    I hope it helps.
    Ben

  • Using "Image/Transform/Perspective" on a layer?

    Hi,
    I'm new at this.  I have a shot of a big room with empty art frames on the walls.  I have rectangular layers that are shots of paintings that I want to drop into the frames, but of course the paintings layers have to be skewed to show the perspective angle (trapezoid) that matches the room.  Problem is, it seems that I can only use Image/transform/perspective on the painting files before they become layers.  This means guessing the perspective, then moving them into the background, which is trial&error at best.  It's very hard to guess the appropriate perspective when the file isn't a layer. It seems that once the painting files become layers, the "perspective" option is no longer available.  I can use "skew," or "free transform," but not "perspective."    "Skew" doesn't work, because while it will allow changing the rectangle into a paralellogram, it won't allow me to change the rectangle into a trapezoid. "Free Transform" doesn't work for the same reason.  So, How do you apply the "perspective" function to a layer?
    If I knew how to change the rectangle by grabbing one of a selection's corner anchor boxes and fixing it place, that would help because I could create my own trapezoid, but I don't know how to do that.  Does anyone?
    Thanks!

    I've no idea why all the transform options aren't available; they are here.
    Anyway, try this:
    Drag or copy/paste the painting in. It will come in as a new layer.
    Convert that layer to a smart object (Layer > Smart Object > Convert..). Reduce the smart object opacity to 50%.
    Choose Transform > Distort and move the corners individually into place.
    When you're happy, set opacity back to 100% and rasterize the smart object.
    The beauty of the smart object in this case is that you can transform repeatedly without any additional quality loss; it will be rendered only once when you rasterize.

  • Error message when trying to use image processor in CS2

    Hi
    I am trying to use image processor to condense 500 proofs for my website - however although I have done many times before with no problem, now when I hit the Image processor button before I even get to key in details it is bringing up the sorry something major has happened message and I can't continue - the details of this message are as follows - ref error : this.dlgMain.ddset on Change is not a function :810 - does this mean anything to anyon? Any ideas on how to overcome would be much appreciated.
    thanks

    Go to Russell Brown's website and download his package for CS2. His 1-2-3 Processor is much more flexible than the one provided by Photoshop.

  • Why can I no longer import EDITED photo from my iPad to my Mac using Image Capture from Snapseed app?

    Why can I no longer import EDITED photo from my iPad to my Mac using Image Capture? This is farcical and a real problem having to email them individually to myself and is totally inefficient time wise compared to previously using image capture! Why change this when it was working well and very quickly until the latest change. Now I have to move files from downloads into an appropriate folder, after emailing each individual edited image to myself, then I have to open in Photoshop and rename the file. This is ludicrous and takes forever to do!

    Thank you! I suppected it would be in the settings somewhere. I' ve much to learn...get myself into trouble pushing buttons I don't really understand.

  • Why is the scan size of our epson 15Mb for PDF using image capture?

    Hi All-
    This has been plaguing us since Snow Leopard when we lost the Epson Scanner tool from Epson to Image Capture scanning using our Epson 835 Artisan.
    PDF sizes are ridiculous using Image Capture. 
    For example, 3 pages of text using Image Capture =
         15Mb
    Using the same printer, same 3 pages and the builtin Epson Scanner (from the printer panel) and a USB stick =
         1.2Mb
    This has been happening since the SL upgrade (as mentioned) but I had hoped that Epson/Apple could get their act together on the Epson drivers for ML.  Seems not to be the case.  It is kind of a drag to have a Network available Scanner only to have the built in software be a bum steer.  Not only that, but no relief from Epson since their Scanner program (as bad as it was UI wise, but at least you got a mail-able document) has been discontinued...
    Any ideas?
    jp

    This doesn't answer the question but it is a workaround.
    How is the quality if you do this:
    Open the PDF in Apple Preview
    Choose File/Export
    In Export, choose PDF format with the Quartz Filter option "Reduce File Size"
    If it's ugly, there's a way to adjust the compression settings by using Apple ColorSync Utility to make a modified copy of the Reduce File Size filter with different settings. By playing with this I was able to start with a 7.1MB PDF scan from Image Capture, and export variations based on different Reduce File Size settings:
    5.3MB (JPEG Max) - looks great
    188KB (JPEG Min) - looks good as the 5.3 MB copy actually
    40K (Automatic) - too blurry to be usable
    If you were to perfect your own compression filter you could just export each PDF through Preview after scanning it, or presumably you could build some kind of drag-and-drop conversion utility in Automator although I don't know anything about Automator.
    It's a workaround because I could not determine a way to apply a Quartz filter from Image Capture itself when saving a PDF.

  • Colour washed out when using image processor in Bridge CS6

    Hi there
    I hope somebody can help please?!
    I am editing raw files in Camera Raw 8.2, then using image processor through Bridge CS6 to save them as both jpegs and tiffs.
    I am finding the colour on the saved files is coming out a little washed out and faded.
    If I open them individually and save them in PS6 as jpeg and tiffs, the colour remains vibrant and true to the original raw file.
    I have thousands of these files to go through and don't have time to open each one individually in this way so I am desperate to automate this process while still retaining the great colour in the original shots.
    Can anyone tell me why the shots are coming out this way and help offer a solution for me please?
    Any advice would be massively appreciated!
    Many thanks
    Benny P

    Hi,
    Do you have Include ICC Profile checked at the bottom of the Image Processor dialog?

  • Any way to open new browser window without using image maps?

    Is there any way to open new browser window without using image maps? My code works fine in Firefox, but not in IE. There are 2 problems in IE: 1st is that the thumbnail images move up within their own borders & 2nd that when you click on an image it does open up a new browser window, but also redirects to the index page (in this case it's just a placeholder index page - the new one I've called index_new.html for the time being).
    Here is the link:
    http://www.susieharperdesigns.com/gallery_beads.html
    Any help is greatly appreciated.

    Your missing a value on the HREF.  In your code you have this:
    <area shape="rect" coords="-24,-9,106,144" href=" " onclick="MM_openBrWindow('gallery_bead1.html','','width=255,height=360')" />
    </map></div>
    and it should be this:
    <area shape="rect" coords="-24,-9,106,144" href="javascript:void()" onclick="MM_openBrWindow('gallery_bead1.html','','width=255,height=360')" />
    </map></div>
    If you fix the code on all your beads, it should work.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com

  • I am importing videos from my canon sl1 to my macbook when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item 'MVI_1040

    I am importing videos from my canon sl1 to my macbook air when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item ‘MVI_1040'' Thanks in advance

    Can you access the images on the phone with Image Capture (in the Applications Folder) ?

  • I make greetings cards and use images downloaded from cardmaking websites eg - cently I find I cannot copy and paste an image from adobe reader which is the how the images are downloaded. Why is this and how do I copy and paste an image on a  adobe reader

    copying and pasting images from adobe.     I make greetings cards and use images downloaded from cardmaking websites eg - printable heaven. Recently I find I am unable to copy and paste the images which are opened in adobe reader. Why ?  How can I overcome this problem.

    Check the document properties; is copying allowed?

  • How do scan strip negatives via my Epson 4990 scanner using Image Capture since upgrade to OS X Mavericks

    Hello Everyone. OK I upgraded to OS X Mavericks without thinking that by doing this would stop me using my Epson 4990 scanner as no driver / software currently available - OK my fault. Anyway as Epson have not yet provided an update (yet?), all advice being recieved is use "Image Capture" for the time being. I have tried this along with using the "Help" files but unfortunately dont seem to be be any assistance. In simples terms I just wish to scan film negative strips (and transparencies) but it dont seem to be possible. Could any member advised how to get solve this problem as I am in the middle of a major scanning exercise with the worst case senario that I wil have to revert to my Windows based laptop to carry on and temporary reduntant my iMac which defeats the point of the exercise. Thank you in advance (hopefully) 

    Replay I received from Epson today:-
    "In response to your email, we unfortunately do not have any update available for your model at present. We have no confirmed date for this but as far as we are aware this is likely to be in the next two weeks"

Maybe you are looking for