Complete beginners help.using ImageIcon and cant assign images

how do assign the ImageIcon for the front and back to this class.i have two gif files in the same directory. to test the card class i want to press the flip button to display the front and then the back. i am making simple card game but am very new to this and am stumbling at the basics.any help much appreciated. here is my attempt at the code.
( havent put in the paint() )
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class JCard extends JComponent
private int value;
private ImageIcon FrontImg;
private ImageIcon BackImg;
private int size;
private boolean faceup;
     public JCard()
this.value= value;
public int getValue()
return value;
//returns the width of the card
public int getWidth()
return getSize().width;
//returns the height of the card
public int getHeight()
return getSize().height;
//returns true if the card is face up
public boolean faceup()
return faceup;
//flips the card
public void flip()
if(faceup)
faceup = false;
else
faceup = true;
repaint();
public void setBackImg(ImageIcon img)
BackImg = img;
public void setFrontImg(ImageIcon img)
FrontImg = img;
public void paint(Graphics g)
//test JCard
import javax.swing.*;
import java.awt.event.*;
public class TestJCard extends JFrame implements ActionListener
     private JCard card = new JCard();
     private JButton b1 = new JButton("flip");
public TestJCard()
super();
JPanel p = (JPanel)getContentPane();
p.add("Center",card);
p.add("South",b1);
b1.addActionListener(this);
public void actionPerformed(ActionEvent ae)
card.flip();
//** To close window**//
class WindowHandler extends WindowAdapter
public void windowClosing(WindowEvent we)
we.getWindow().hide();
System.exit(0);
     public static void main(String args[])
TestJCard fm = new TestJCard();
fm.setSize(300,300);
fm.setVisible(true);

I'm not sure if I understand exactly what you're asking, but if you're wondering how to create/initialize and ImageIcon from an image file on a local disk, I believe it is as simple as:
ImageIcon i = new ImageIcon("path/filename.ext");
note: the path can be relative (i.e. "images/pict1.gif")
or explicit ("c:/project1/images/pict1.gif").
Hope this is what you're looking for.

Similar Messages

  • I HAVE MISTAKENLY BLOCKED ALL MY PHOTOS ON FACEBOOK USING FIREFOX AND CANT ACCESS IT AGAIN.CAN YOU PLEASE HELP ME TO SORT THIS OUT?

    I have just mistakenly blocked my photos on facebook.com using Mozilla.I write clicked one of my photos and the was a portion that says blocked photos.I clicked that and tried to undo but could not work and now i cant see my profile picture and other pictures on facebook.

    With Facebook on display, click on the site identity button (for details on what that is see the [[site identity button]] article) and then on More Information. This will open up the page info dialog.
    First select the Permissions panel, make sure that "Load Images" is set to allow (selecting Use Default should also work)
    Next select the Media panel, then click on the first item in the list. Use the down arrow key to scroll through the list. If any item has the option "Block images from (domain name)" selected, de-select the option.
    This should hopefully resolve your issue, but also see [[Images or animations do not show]].
    Some add-ons can also block images, for example if you have AdBlock Plus installed, make sure that you have not accidentally created a filter to block the images.

  • Help Using Count and SQL statements

    Hello
    This problem has been bugging me incesantly and I would be reaaaaaaally grateful if someone could help here
    I want to create query that woud count the number of times a certain unedited word would be matched against different edited words
    This query works well in MS ACCess but not in java
    query =" SELECT Count(*) AS WordCount, Segmentations.EditedWord FROM [select Segmentations.EditedWord FROM Segmentations where Segmentations.UneditedWord = '"+Word+"']. AS c GROUP BY Segmentations.EditedWord";
    I've tried removing the Segmentations. and changing it to
    query =" SELECT Count(*) AS WordCount, EditedWord FROM [select EditedWord FROM Segmentations where UneditedWord = '"+Word+"']. AS c GROUP BY EditedWord";
    But still nothing
    I think that is due to the fact that you can't call Count(*) and another field at the same time
    pleas eif anyone knows a way around this send it ASAP
    thanx

    Why not use,
    query = "SELECT Count(*) AS WordCount, EditedWord FROM Segmentations WHERE  UneditedWord = ? GROUP BY EditedWord"and use PreparedStatement to optimize.
    HTH

  • Help: Using Record and Collection Methods

    I have created a record and I have to loop for as many records in the "RECORD". However if I attempt using any of the Collection Methods, I get the following error:
    ERROR at line 1:
    ORA-06550: line 41, column 14:
    PLS-00302: component 'EXISTS' must be declared
    ORA-06550: line 41, column 4:
    PL/SQL: Statement ignored
    ORA-06550: line 47, column 26:
    PLS-00302: component 'COUNT' must be declared
    ORA-06550: line 47, column 7:
    PL/SQL: Statement ignored
    Here is the SQL I am trying to execute:
    DECLARE
    TYPE Emp_Rec is RECORD (
    Emp_Id Emp.Emp_no%TYPE
    , Name Emp.Ename%TYPE
    ERec Emp_Rec;
    Cursor C_Emp IS
    SELECT
    Emp_No, Ename
    From Emp;
    begin
    OPEN C_Emp;
    LOOP
    FETCH C_Emp INTO Erec;
    EXIT WHEN C_Emp%NOTFOUND;
    END LOOP;
    IF Erec.Exists(1) THEN
    dbms_output.Put_line('exists' );
    else
    dbms_output.Put_line('does not exists');
    end if;
    CLOSE C_Emp;
    FOR I IN 1..ERec.COUNT
    LOOP
    dbms_Output.Put_Line( 'Row: ' || To_Char(I) || '; Emp: ' || ERec(i).Name) ;
    END LOOP;
    end;
    Can anyone help, please?
    Thanking you in advance,

    You only defined a Record and not a collection, therefore you cannot use .EXISTS
    This is how you would use record, collection and exists together
    DECLARE
    TYPE Emp_Rec is RECORD
             (Emp_Id Emp.Empno%TYPE,
              EName Emp.Ename%TYPE );
    TYPE Emp_tab is table of emp_rec index by binary_integer;
    ERec Emp_tab;
    Idx  INTEGER;
    Cursor C_Emp IS
         SELECT EmpNo, Ename    From Emp;
    begin
    IDX := 1;
    OPEN C_Emp;
    LOOP
           FETCH C_Emp INTO Erec(IDX);
                     EXIT WHEN C_Emp%NOTFOUND;
           IDX := IDX + 1;
    END LOOP;
    IF Erec.Exists(1) THEN
           dbms_output.Put_line('exists' );
    else
           dbms_output.Put_line('does not exists');
    end if;
    CLOSE C_Emp;
    FOR I IN 1..ERec.COUNT  LOOP
            dbms_Output.Put_Line( 'Row: ' || To_Char(I) || '; Emp: ' || ERec(i).eName) ;
    END LOOP;
    end;I hope you realize that this is only an example of how to use RECORD, COLLECTIONS and Collection Methods (.EXISTS, .COUNT)
    and not the best way to display the contents of a table.

  • Help with Query and report assignment

    Hi,
    I am able to attach 2 transactions (e.g. MM03 and ME23) to my SAP Query through report assignment.  My question is how do I skip the selection screen that asks me if I want to Display Material or Display PO?
    What i want to happen is in my report, if I click on the material - MM03 is called and if I click on the PO, ME23 is called.
    Is this even possible through queries?
    Cheers.

    Thanks for replying.
    I did as suggested and added the following at the start of my code.
    AT LINE-SELECTION.
    GET CURSOR FIELD FILD_NAME VALUE F_VALUE.
    I set a breakpoint in AT LINE-SELECTION and when I executed my query, it wasn't passing through it. 
    When I removed the line AT LINE-SELECTION, it passes through GET CURSOR FIELD, but FILD_NAME is not populated.  It's blank.
    Below is my code at the moment:
    data: fild_name(30), F_VALUE(50).
    *AT LINE-SELECTION.
    GET CURSOR FIELD FILD_NAME VALUE F_VALUE.
    if fild_name = 'MAT'.
    PARAMETERS P_MATNR LIKE MARA-MATNR.  "DD ref. as in MM03
    SET PARAMETER ID 'MAT' FIELD P_MATNR. "ID for MARA-MATNR
    CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    endif.
    Appreciate any help.

  • CAML Query help using recursiveall and date filter together

    Hello,
    Please let me know what is wrong with the query below,
    <View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Leq>
    <FieldRef Name='Modified'/>
    <Value Type='DateTime' IncludeTimeValue='FALSE'>date value</Value>
    </Leq>
    </Where>
    </Query>
    </View>
    Above query returns zero items, it should return 3 items in my current scenario.
    If I do just the folllowing, three items are returned
    <View Scope='RecursiveAll'>
    <Query>
    </Query>
    </View>
    I need date filter to work with recursiveall . Not sure what is wrong with the query
    Student For Life

    Hi,
    Per my understanding, you might want to use “RecursiveAll” with date filter in your CAML query statement.
    I suggest you take the code demo below which writes in Server Object Model for a try in your environment to see if it can work for you:
    using (SPSite oSiteCollection = new SPSite("http://yoursite"))
    using (SPWeb web = oSiteCollection.RootWeb)
    SPList list = web.Lists["List1"];
    SPQuery qry = new SPQuery();
    qry.Query =
    @" <Where>
    <And>
    <Leq>
    <FieldRef Name='Modified' />
    <Value Type='DateTime'>2015-03-07T12:00:00Z</Value>
    </Leq>
    <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>0</Value>
    </Eq>
    </And>
    </Where>";
    qry.ViewFields = @"<FieldRef Name='Title' />";
    qry.ViewAttributes = "Scope='RecursiveAll'";
    SPListItemCollection items = list.GetItems(qry);
    foreach (SPListItem item in items)
    Console.WriteLine(item["Title"]);
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Need help using Feedburner and Buzzboost in iWeb site

    Hello.
    I have embedded a blog feed into my iWeb site using Feedburner's Buzzboost. The feed appears correctly, but I cannot for the life of me figure out how to get the customizing CSS codes to work.
    I've found countless tips on using CSS codes to customize the Buzzboost appearance. I cannot get the feed to react to the codes when I insert them inside of iWeb (in an html snippet) or outside of iWeb (when inserting the codes directly into the CSS file for the page).
    I have tried everything I can find in searching this problem. Perhaps it is something very simple that I am simply overlooking.......
    thanks for any help in advance.

    WordPress does not allow custom code. You have their method using Insert Media.
    Mylenium

  • Dreamweaver8 help using layers and Flash8

    I have placed a "layer" on my site and then placed a Flash
    element iside of it. I saved the project as a .dwt and when I open
    the page everything works and look great. Next I made a new page
    "from template" and when I view the new page the flash elements no
    longer work. Has anyone got some ideas that would help me solve
    this issue?
    Thanks ahead,
    Jamie

    Sorry for the delay in this issue. Here are the script files
    //v1.0
    //Copyright 2006 Adobe Systems, Inc. All rights reserved.
    function AC_AddExtension(src, ext)
    if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?');
    else
    return src + ext;
    function AC_Generateobj(objAttrs, params, embedAttrs)
    var str = '<object ';
    for (var i in objAttrs)
    str += i + '="' + objAttrs
    + '" ';
    str += '>';
    for (var i in params)
    str += '<param name="' + i + '" value="' + params +
    '" /> ';
    str += '<embed ';
    for (var i in embedAttrs)
    str += i + '="' + embedAttrs
    + '" ';
    str += ' ></embed></object>';
    document.write(str);
    function AC_FL_RunContent(){
    var ret =
    AC_GetArgs
    ( arguments, ".swf", "movie",
    "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    , "application/x-shockwave-flash"
    AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
    function AC_SW_RunContent(){
    var ret =
    AC_GetArgs
    ( arguments, ".dcr", "src",
    "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
    , null
    AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
    function AC_GetArgs(args, ext, srcParamName, classid,
    mimeType){
    var ret = new Object();
    ret.embedAttrs = new Object();
    ret.params = new Object();
    ret.objAttrs = new Object();
    for (var i=0; i < args.length; i=i+2){
    var currArg = args.toLowerCase();
    switch (currArg){
    case "classid":
    break;
    case "pluginspage":
    ret.embedAttrs[args
    ] = args[i+1];
    break;
    case "src":
    case "movie":
    args[i+1] = AC_AddExtension(args[i+1], ext);
    ret.embedAttrs["src"] = args[i+1];
    ret.params[srcParamName] = args[i+1];
    break;
    case "onafterupdate":
    case "onbeforeupdate":
    case "onblur":
    case "oncellchange":
    case "onclick":
    case "ondblClick":
    case "ondrag":
    case "ondragend":
    case "ondragenter":
    case "ondragleave":
    case "ondragover":
    case "ondrop":
    case "onfinish":
    case "onfocus":
    case "onhelp":
    case "onmousedown":
    case "onmouseup":
    case "onmouseover":
    case "onmousemove":
    case "onmouseout":
    case "onkeypress":
    case "onkeydown":
    case "onkeyup":
    case "onload":
    case "onlosecapture":
    case "onpropertychange":
    case "onreadystatechange":
    case "onrowsdelete":
    case "onrowenter":
    case "onrowexit":
    case "onrowsinserted":
    case "onstart":
    case "onscroll":
    case "onbeforeeditfocus":
    case "onactivate":
    case "onbeforedeactivate":
    case "ondeactivate":
    case "type":
    case "codebase":
    ret.objAttrs[args] = args[i+1];
    break;
    case "width":
    case "height":
    case "align":
    case "vspace":
    case "hspace":
    case "class":
    case "title":
    case "accesskey":
    case "name":
    case "id":
    case "tabindex":
    ret.embedAttrs[args
    ] = ret.objAttrs[args] = args[i+1];
    break;
    default:
    ret.embedAttrs[args
    ] = ret.params[args] = args[i+1];
    ret.objAttrs["classid"] = classid;
    if (mimeType) ret.embedAttrs["type"] = mimeType;
    return ret;

  • Chess game variant - help using JLayeredPane and the drag layer.

    Hi there!
    I'm making a game based on chess, but with slightly different rules. The code at the bottom of this thread...
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=518707
    ... forms the basis of the game board, and this is how I have implemented the dragging and dropping of pieces. My game, however is slightly different as there is a single neutral piece (the ball), which players can manipulate by moving one of their pieces to the square containing the ball, then moving the ball to another location.
    When a player clicks and drags a piece to the ball square, then releases, I want to attach the 'ball' JLabel to the mouse so that the player can move it around the board WITHOUT holding down the mouse button. Then, when the player clicks again the ball is moved to the new square.
    The only problem I have is attaching the 'ball' to the mouse so I can move it around (without the user having to hold the mouse button down). I thought about tried using the drag layer, but I couldn't quite get that working. I also thought about using the mouseMoved(MouseEvent e) and mouseClicked(MouseEvent e) methods.
    I'm pretty new to this coding stuff, so any suggestions would be great.
    Thanks!

    Using the drag layer isn't going to work unless you are using an honest to goodness component for the ball. Your other option might be to try to use the glasspane, which is a pain in the neck, or a floating window component.
    In any case,I built the code below for dragging Windows around in a frame. You're free to use it but please site me in your school or business work
    package tjacobs.ui;
    import java.awt.*;
    import java.awt.event.*;
    public abstract class WindowUtilities {
    public static Point getBottomRightOfScreen(Component c) {
         Dimension scr_size = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension c_size = c.getSize();
         return new Point(scr_size.width - c_size.width, scr_size.height - c_size.height);
         public static class Draggable extends MouseAdapter implements MouseMotionListener {
    Point mLastPoint;
    Window mWindow;
    public Draggable(Window w) {
    w.addMouseMotionListener(this);
    w.addMouseListener(this);
    mWindow = w;
    public void mousePressed(MouseEvent me) {
    mLastPoint = me.getPoint();
    public void mouseReleased(MouseEvent me) {
    mLastPoint = null;
    public void mouseMoved(MouseEvent me) {}
    public void mouseDragged(MouseEvent me) {
    int x, y;
    if (mLastPoint != null) {
    x = mWindow.getX() + (me.getX() - (int)mLastPoint.getX());
    y = mWindow.getY() + (me.getY() - (int)mLastPoint.getY());
    mWindow.setLocation(x, y);
    }

  • HT5312 i cant remember answers to secrutity questions help !! and cant seem to find a way to change them

    cant remember the answers to secruity questions and dont know how to change them HELP

    Select Movies and double click the movie.

  • Help with Importing and Editing an Image

    Hello All,
    I am working on a project where I need to import an image into LabView and edit it. The gist of my program is that I want to create a VI that generates an interactive floorplan.
    I want to be able to import the bitmap or png into my file so I can edit the file by assigning flashing colors to each room, etc.
    I tried to import the .png by wiring "Read png" --> "Draw Flattened Pixmap" --> "new picture".
    When I run the program I get a "general I/O" error in the "Read PNG" block even though it lets me select which png I can import.
    Does LabVIEW 8.5 not allow for importing PNG files? Does anyone have any idea why I am getting this error?
    On another note, I was reading about some of the IMAQ VI's and they seem like they may work for importing an image and creating graphics, etc. Should I try to delve a little deeper into the IMAQ stuff?
    Thanks much for the help!

    Great call on checking whether it was just a bad file.
    I tried to convert it from a .bmp to a .png by simply renaming it which LabVIEW did not like...
    So I just opened it up and re-saved it with photo editing software and it worked!
    Now I just have to play around with my editing options to get the graphics I want. 
    I'll post some sample code just for suggestions that anyone may have. This is just my preliminary structure without most of my condition statements. All the code inside the case structures will be added when I figure all this stuff out.
    My goal is to have each strobe and interlock correspond to a different graphic on the floorplan. For example, when strobe 1 reads red, I want the corresponding room to flash red and vice versa with green and yellow. Also, when interlock 1 reads false, I want a flashing light to pop up next to the corresponding door.  
    Anyone have any ideas for how to make these kinds of graphics? I figured I may be able to use a color box for the solid colors and LEDs for the flashing lights but I would rather edit the pixels to make it look more professional.
    Thanks for all the help!
    Attachments:
    LabStatusProgram.vi ‏9 KB

  • I am creating an Apple book of photos using iPhoto and a panoramic image.

    I am creating an Apple book of photos using iPhoto.  I have a panoramic image that I have split into two 9.5X2.583 in pieces in PhotoShop.  I want to paste them into facing pages.  When I try to move the images to the book I get images much larger which won't fit on the page.  I am using Mac OS X 10.7.4 and iPhoto 11 (9.3.2). 
    What do I need to do to make this work?
    Thanks for your help.

    Why not just use the full panoramic photo in one of the "spread" layouts which span two pages.
    It's look something like this depending on the image size and theme and layout used:
    OT

  • Help me drag and drop my image please

    my image is in JLbel
    i want to MOVE image between JLabel (JPanel too) not COPY
    like the chees game
    but i look at the chess game source in "search"
    it's use JLayer on JFrame
    but i use only JFrame
    can you give me sample
    move image between JLabel
    i think JLayer must have something differ from JFrame

    but i look at the chess game source in "search" it's use JLayer on JFrameYes, thats one approach.
    but i use only JFrame can you give me sample move image between JLabel And you where given the link to the Swing tutorial on using DnD that shows you how to do this.
    So you have two working solutions. Choose the approach you want to use.
    I hope you don't expect us to write the code!

  • I used to be able to use the reduce picture ( middle button ) using Firefox and dragging the image to another screen. How do I restore this as the reduce button will not work ?

    The top right corner of the screen allows you to reduce the size of your entire image on Firefox . I used to be able to do this so I could drag the image to another screen . Suddenly I cannot do so anymore from my laptop. What can I do ?

    Could you clarify where you are doing your search?
    ''For Firefox's "Search bar",'' which is the box on the right end of the main navigation toolbar with the icon indicating your currently selected search engine, there is a hidden setting for this:
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''sear''' and pause while the list is filtered
    (3) Double-click the '''browser.search.openintab''' preference to switch it from false to true.
    If you test, does it work?
    ''For searches from other places,'' could you be more specific about where you are entering your query (e.g., address bar, built-in home page, on a search engine site)?

  • Need Help With ASR and Deploying InstaDMG Image

    Hi,
    Okay, so I got my client machine to boot up from a netinstall image over my network. It sounds like I might be able to do this in a more efficient way, but for now, I'm happy with the way I got it to work.
    Now, I'm perplexing over how to deploy the installation packages and operating system I've prepared with InstaDMG. I'm totally confused. On the client machine, using the netinstall image, I went to Disk Utility. There, I can select my client machine hard drive, and choose the Restore tab. But, the only image in the list to choose from, is the netinstall image. How can I use the InstaDMG set up I've created and put on my server? Is there a way to "add" that folder and its materials to the Disk Utility window?

    Hello,
    Okay, so I ended up remaking my instaDMG, because for some reason there seemed to be an issue with it. Here is where I am.
    InstaDMG image created (started with only the Operating System and OS Updates). Put this on the server and mounted it. Opened System Image Utility and turned the InstaDMG into a NetInstall image. Saved NetInstall image into the same folder as my previous netinstall image (that I'm booting my client machines from), which is in /Library/Netboot/NetBootSP0 folder. Enabled the new netinstall image using system admin tool.
    Rebooted my client machine to the network. I expected it to give me a choice about which netinstall image I wanted to boot the machine from. It only sees the first netinstall image I made (which was just to boot the machine from an OS so I could install my instaDMG image).
    What am I doing wrong and how can I make my client machine see the new instaDMG netinstall image?
    Thanks!

Maybe you are looking for