Giving a Class an ImageIcon

hello all,
i am a relative beginner to java and am having a small bit of difficulty in a small venture, and was wondering if someone could help.
I am in the middle of creating a top-down tile-based turn-based engine. I am currently at very early stages.
- i have a class called "tile". This only contains code for two ints (TerrainType and MovementCost).
- I make a grid of references, and then apply a whatever.tile to each reference, using an array, which defines the map.
- The trouble is at the nestedloop, where i cannot apply an "ImageIcon" to class.tile.
How should i change my code? By the way, this is my 2nd version of this - The first version, used jLabels instead of class.tile, and it worked fine. However i couldnt figure out how to apply attributes to it.
*****CODE******
ImageIcon block = new ImageIcon("block.gif");
ImageIcon grass = new ImageIcon("grass.gif");
tile t0 = new tile();
tile t1 = new tile();
tile t2 = new tile();
tile t3 = new tile();
ArrayList tt = new ArrayList();
tt.add("0");
tt.add("0");
tt.add("0");
tt.add("1");
tt.add("x");
int max_rows = 2;
int max_cols = 2;
int x = 0;
tile[][] grid = new tile[max_rows][max_cols];
grid[0][0] = t0;
grid[0][1] = t1;
grid[1][0] = t2;
grid[1][1] = t3;
for (int r = 0; r < max_rows; r++) {
for (int c = 0; c < max_cols; c++) {
if (tt.get(0).equals("0")){
grid[r][c].setIcon(grass); <<<<error
tt.remove(0);}
else if (tt.get(0).equals("1")){
grid[r][c].setIcon(block); <<<<error
tt.remove(0);}
**********class code*****
package mapalpha;
public class tile {
int TerrainType;
int MovementCost;
public tile() {
}

To add an 'attribute' to a JLabel: since JLabel extends from JComponent you can use the 'putClientProperty' and the 'getClientProperty' methods to store/retrieve attribute-type information in the component. See the method detail section for each method in the JComponent api.
On your current design: you can put anything you want in your custom Tile class - ImageIcon, JLabel, JPanel, an image...
class Tile
    int terrainType, movementCost;
    BufferedImage image;
    ImageIcon icon;
    JLabel label;
    public Tile(args for instantiation if you like...)
    protected void setIcon(ImageIcon icon)
        this.icon = icon;
        // other activity if you like
}If you want an image/graphics component you could have Tile extend JPanel or JLabel. Then you could override the 'paintComponent' method in JPanel and draw your image/graphics. If extending JLabel simply call 'setIcon' which will be a JLabel method - not the same as in the pseudo code above (which is a 'set' method for the Tile class).

Similar Messages

  • Giving a class name and href to shape

    Hello there, is my first time im working whit edge i hope have some help. I created a animation, and in the end of animation there is a computer wich is suppose to be clicked and appear a pop up contact form. So i created a shape whit 0% opacity to be invisible than crea this code to link:
    "window.open("http://www.google.com", "_self");"
    But i have a problem, for my pop up contact form to be trigget this should have a class in my link like this:
    <a class="modalbox" href="#inline">click to open</a>
    so i just need to put my code linke this:
    "window.open("#inline", "_self");"
    But the problem is for my popupbox to be trigger i need to pass the class (modalbox) to the link, does someone have any ideia how coul i achieve it?
    REgards

    Here's a quote from the Java language spec:
    "The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (�7.6) declared in that package."
    So your book was not quite correct, or maybe you just misremembered it (clearly you are typing from memory there). It isn't illegal for a package to have the same name as a class, as in your example. But it is illegal for a package to contain a subpackage and a class with the same name.

  • - Giving a class its own "A" link color...

    .title, .title a:link, .subtitle, subtitle a:link {
    color: #FFFFFF;
    Wouldn't this give the color white to all links located
    within a paragraph
    that had TITLE or SUBTITLE assigned to it, even if nothing
    was assigned to
    the A tag itself?
    Links within the cell are still getting the default link
    color... despite
    the cell having class="title"
    Where did I go wrong in my syntax?

    "Reese" <[email protected]> wrote in message
    news:es81kg$svh$[email protected]..
    > .title, .title a:link, .subtitle, subtitle a:link {
    > color: #FFFFFF;
    > }
    >
    > Wouldn't this give the color white to all links located
    within a
    > paragraph that had TITLE or SUBTITLE assigned to it,
    even if nothing
    > was assigned to the A tag itself?
    >
    > Links within the cell are still getting the default link
    color...
    > despite the cell having class="title"
    A couple of potential problems:
    1. If you set a:link, without a visited class, then if that
    link was
    visited, it will be purple
    Test by changing your rule to this:
    .title, .title a:link, .title a:visited,
    .subtitle, subtitle a:link, subtitle a:visited {
    color: #FFFFFF;
    2. You have a conflicting style. Look for any other <a>
    selectors in
    your page styles.
    Al Sparber - PVII
    http://www.projectseven.com
    Extending Dreamweaver - Nav Systems | Galleries | Widgets
    Authors: "42nd Street: Mastering the Art of CSS Design"

  • 'Class Cast Exception' while invoking a EJB from a Servlet

              Hi,
              I am working on J2EE applications.I am using Webgain studio and weblogic server.I
              got a problem while invoking EJB from the servlet.
              While calling an EJB from the servlet, it is giving that "Class Cast Exception".This
              is because, the remote home reference is not able to type casted to the"Home Interface"
              of the EJB, even if I type casted explicitly. It is creating the context and able
              to identify the EJB with the JNDI name.
              Could please help me in solving this problem.I am pasting the code here.
              Thanks in advance,
              Dharma
              public void doGet(HttpServletRequest req, HttpServletResponse resp)
                   throws ServletException, IOException
                        resp.setContentType("text/html");
                        PrintWriter out = new PrintWriter(resp.getOutputStream());
              try
              Context context=getInitialContext();
              Object reference=context.lookup("ArlProjContractorAppletSession");
              ArlProjContractorAppletSessionHome home=(ArlProjContractorAppletSessionHome)PortableRemoteObject.narrow(reference,ArlProjContractorAppletSessionHome.class);
              //Exception is occuring in the above statement. It is unable
              //to cast to the home interface          
                        ArlProjContractorAppletSession the_ejb=null;
              try
              the_ejb=home.create();
              System.out.println("the_ejb = " + the_ejb.toString());
              catch(Exception e)
              e.printStackTrace();
              catch(Exception e)
              e.printStackTrace();
                        // to do: code goes here.
                        out.println("<HTML>");
                        out.println("<HEAD><TITLE>Contractor TimeTracker</TITLE></HEAD>");
                        out.println("<BODY>");
                        // to do: your HTML goes here.
                        out.println("</BODY>");
                        out.println("</HTML>");
                        out.close();
              

              I came across this kind of problem once. My problem went away after I upgraded
              from 5.1 SP6 to 5.1 SP8.
              "Dharma" <[email protected]> wrote:
              >
              >Hi,
              >
              >I am working on J2EE applications.I am using Webgain studio and weblogic
              >server.I
              >got a problem while invoking EJB from the servlet.
              >
              >While calling an EJB from the servlet, it is giving that "Class Cast
              >Exception".This
              >is because, the remote home reference is not able to type casted to the"Home
              >Interface"
              >of the EJB, even if I type casted explicitly. It is creating the context
              >and able
              >to identify the EJB with the JNDI name.
              >
              >Could please help me in solving this problem.I am pasting the code here.
              >
              >Thanks in advance,
              >Dharma
              >
              >
              >public void doGet(HttpServletRequest req, HttpServletResponse resp)
              >     throws ServletException, IOException
              >     {
              >          resp.setContentType("text/html");
              >          PrintWriter out = new PrintWriter(resp.getOutputStream());
              >
              > try
              > {
              >
              > Context context=getInitialContext();
              >
              > Object reference=context.lookup("ArlProjContractorAppletSession");
              >
              > ArlProjContractorAppletSessionHome home=(ArlProjContractorAppletSessionHome)PortableRemoteObject.narrow(reference,ArlProjContractorAppletSessionHome.class);
              >
              >//Exception is occuring in the above statement. It is unable
              >//to cast to the home interface          
              >
              >          ArlProjContractorAppletSession the_ejb=null;
              >
              > try
              > {
              > the_ejb=home.create();
              >
              > System.out.println("the_ejb = " + the_ejb.toString());
              >
              > }
              > catch(Exception e)
              > {
              > e.printStackTrace();
              > }
              > }
              > catch(Exception e)
              > {
              > e.printStackTrace();
              > }
              >          // to do: code goes here.
              >
              >          out.println("<HTML>");
              >          out.println("<HEAD><TITLE>Contractor TimeTracker</TITLE></HEAD>");
              >          out.println("<BODY>");
              >
              >          // to do: your HTML goes here.
              >
              >          out.println("</BODY>");
              >          out.println("</HTML>");
              >          out.close();
              >     }
              >
              >
              >
              >
              >
              

  • Problems when trying to add a class

    Hi all,
    I realise that this might belong more as a bug file, but I thought I would ask here first.
    I have a web application, with a few packages, some code, nothing out of the ordinary. But today, when I started up the IDE and loaded the project, the IDE complained about a particular class in the project with the error: (truncated, as there was alot of info)
    Annotation: Exception occurred in Request Processor
    java.lang.IllegalStateException: Recursive call to getElementInfo()
    and the next error was: (again truncated)
    java.lang.ClassCastException: org.netbeans.jmi.javamodel.JavaPackage$Impl
    The IDE thows about 6 or 7 of these messages in a row.
    Now, I deleted the class (there was not much code in it anyway), and the rest of the project is fine. But when I try and add a new class again to the same package with the same name as the old class, then these errors occur again.
    I can add new classes, no problem, but this class name now only produces errors. I get the feeling that this class name "AddPalletAction.java" is being stored somewhere where it should not be, and so when I try and add this class anew, an error occurs.
    How can I stop this (without giving the class a different name)? Is there somewhere I can look where this name might be stored?
    thanks in advance
    Keith Thorne

    Please try cleaning the IDE cache - delete <userdir>/var/cache
    This might help.

  • JSP-class not found

    My server already working properly in internet.It's a travel agent site.there after i include one more page for audio guide which is JMF with in the applet and it is plugin to my jsp page.It's work very fine in my local system.my server is Tomcat .But if i hosted to our server means it's giving applet class not found exception.
    It is already having com package ,now i include my jmf package wol to it.
    My root directory of this class file is
    web-inf/classes/wol/PlaySongs.class
    My server doesn't have JMF pack so,i just copy JMF.jar and Sound.jar to my web-inf/lib/ folder.and also to my server folder like tomcat/common/lib/ .Now i restart my server it's giving applet class not found exception.but it's working fine in local system.
    I have using following jsp code.
    <body>
    <%
    String fname = "file:" + request.getRealPath("AudioF") + "/button-1.mp3";
    %>
    <jsp:plugin type="applet" code="PlaySongs.class" codebase="/wol" width="300" height="20">
    <jsp:params>
    <jsp:param name="file" value="<%=fname%>" />
    </jsp:params>
    <jsp:fallback>
    <p> Unable to start Plug-in. </p>
    </jsp:fallback>
    </jsp:plugin>Any one help me.
    Regards
    K.Suresh

    the codebase should be a path into the webdir, not the WEB-INF dir. Your browser needs to be able to reach the applet class like any other resource.
    My server doesn't have JMF pack so,i just copy JMF.jar and Sound.jar to my web-inf/lib/ folder.and also to my server folder like tomcat/common/lib/If you are already copying it to your common/lib folder, you don't need it in the lib folder of your webapp.

  • How to create an object of a class?

    plz read the question carefully ..
    how to create the object of a class by giving the class name as an String
    suppose i have a java file name:" java1.java ".
    so now how to create an object of this class "java1"by passing a string "java1"..

    kajbj wrote:
    rajeev-usendi wrote:
    thanks but still i have problem..
    i have created the object but now i m unable to do anything with that created object..
    i have coded like this..
    Object o= Class.forName("java1").new Instance();
    after this i m unable to do anything with the object 'o'..So why did you create the instance? You can also get all methods using reflection, but that is probably not what you want to do. You should instead let the class implement an interface and cast the created object into that interface ans call the methods that you want to call.
    KajI agree with Kaj. If you need to use a class that's unavailable at compile time, you should create an appropriate interface by which to refer to the class and then you create instances reflectively and access them normally via their interface (which is called reflective instantiation with interface access)

  • Class not found...applet

    Hi all,
    I am trying to load applet from remote machine, the applet giving the Class not found even though the is proper path setting. It also giving the error..
    open http connection failed...
    Wating for reply.
    Sandeep Kutwal.

    Hi,
    First of all thanks to you for replying for my request.
    I had tried the option given by u but it will not work at all on remote server ,it work without any error on my local tomcat (Linux Server) .
    But sometimes it displays on remote server,showing random behaviour of showing, not showing. Is there any Security permission issue ? .
    I am using winXP,JRE version 1.5.0_06 Java HotSpot(TM) Client VM.
    It is giving error when i upload it to my remote server also path is correct .
    Please reply me for this dought . The remote applet shows following errors on the applet java console .
    basic: Stopping applet ...
    basic: Removed progress listener: sun.plugin.util.GrayBoxPainter@15aee9
    basic: Finding information ...
    basic: Releasing classloader: sun.plugin.ClassLoaderInfo@ca8327, refcount=0
    basic: Caching classloader: sun.plugin.ClassLoaderInfo@ca8327
    basic: Current classloader cache size: 1
    basic: Done ...
    basic: Joining applet thread ...
    basic: Destroying applet ...
    basic: Disposing applet ...
    basic: Quiting applet ...
    basic: Joined applet thread ...
    basic: Unregistered modality listener
    basic: Registered modality listener
    basic: Referencing classloader: sun.plugin.ClassLoaderInfo@ca8327, refcount=1
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter@1103a97
    basic: Loading applet ...
    basic: Initializing applet ...
    basic: Starting applet ...
    network: Connecting h/NewsApplet.class with proxy=DIRECT
    basic: WARNING: error reading http:cache.
    network: Connecting with proxy=DIRECT
    network: Connecting .....proxy=DIRECT
    load: class NewsApplet.class not found.
    java.lang.ClassNotFoundException: NewsApplet.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    basic: Exception: java.lang.ClassNotFoundException:
    Message was edited by:
    SandeepKutwal
    Message was edited by:
    SandeepKutwal

  • Class type in classification Tab

    Hi frnds,
         I want to know the table name where the class type details are fetched while clicking the classification tab in mm01 transaction.Four class types are displaying. I know there are many class types are exixting. But only 4 of the class types are fetched on selecting the classification Tab. Ho w it is fetching and from which table the entries can be retrieved.
      Please help me.
    Thanks in advance

    Hi frnds,
         I got this function module to solve my issue. 'CLAF_CLASSIFICATION_OF_OBJECTS' . But I am not able to get all the class type values when I provide an empty value for the corresponding parameter. It is giving only class type 001 value. If I entered class type parameter with 300 it is giving the corresponding value. How can I use this function module to get all class type values by providing the value to material number and table name fields of function module.
    Thanks in advance..

  • Class to Characteristic Values

    In a development I want to give input of Class and in output should be all the characterstics assigned to class and all the equipments where class is assigned and the characteristics values of equipments. For ex:
    CLASS - MOTOR
    Characterstics - KW
                               VOLTAGE
                                CURRENT
                                HP
    Equipment - 1000001435
    Characteristic Values- KW - 100KW
                                         Voltage - 440 Volt
                                         Current - 30 Ampere
                                          HP -  134 HP
    Now we will give input of MOTOR and get equipment, characteristci and char values in output.
    I am looking for the Functiuon Module which can be used to get the characteristics values.
    Thanx in advance.
    VM

    Hi,
    I don't know you know this option or not. In IH08 report you can see the same for various equipment.
    Execute the IH08 report by giving your class, after getting out put in main menu follow the given path,
    Select all the equipment then
    Settings>Show/hide classification  you can see the same.
    Regards,
    N.Nagaraju

  • Applet not loading correctly (likely due to ImageIcon)

    So I have a Tetris game that I made and I'm trying to publish it to the web. I made it an applet, and the thing plays in the appletviewer fine. However, when I load it in an actual browser it just has an X, so I right click and click "Open Java Console" and it gives me the error I listed below
    I think it has to do with me using ImageIcons that load other files (the actual images). These images are on the server, not the users system, so im not sure why its a problem, plus the fact that it loads in the java applet viewer fine.
    Any ideas?
    Thanks,
    Graeme
    Java Plug-in 1.5.0_02
    Using JRE version 1.5.0_02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Main
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    p: reload proxy configuration
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    java.security.AccessControlException: access denied (java.io.FilePermission sprite.gif read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
         at sun.awt.SunToolkit.getImage(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at Tetris.<init>(Tetris.java:60)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    java.security.AccessControlException: access denied (java.io.FilePermission sprite.gif read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
         at sun.awt.SunToolkit.getImage(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at Tetris.<init>(Tetris.java:60)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    waiting
    done
    java.security.AccessControlException: access denied (java.io.FilePermission sprite.gif read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
         at sun.awt.SunToolkit.getImage(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at Tetris.<init>(Tetris.java:60)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    java.security.AccessControlException: access denied (java.io.FilePermission sprite.gif read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
         at sun.awt.SunToolkit.getImage(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at Tetris.<init>(Tetris.java:60)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    java.security.AccessControlException: access denied (java.io.FilePermission sprite.gif read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
         at sun.awt.SunToolkit.getImage(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at Tetris.<init>(Tetris.java:60)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    waiting
    done

    How are you specifying the images to load? I think the best approach is to use getResource() which loads image files via the same mechanism that loads classes.
    ImageIcon icon1 = new ImageIcon(getClass().getResource("sprite.gif"));Will load the icon from the same directory where it got the class file, even if it's in a .jar, on a server or both.

  • ImageIcon rotate

    Is there a java native way of rotate an Image ?
    I�m developing a battleship game (a simple demo just for test some UML design features.. the game is not really important)...
    The issue is the ship image drawing. I�m reading the water and the ship hull images from a set *.gif images... but the ship may be placed in vertical or horizontal way...
    I don�t want to store two images for the same ship (because it should work both as applet or as application.. and applet forces image loading minimization).. I want to read just one gif image and then rotate 90' depending on the image orientation... (or -90' if the ship is inverted placed)
    How can I do that ? which class ? ImageIcon ? Image? other ?
    thanks for any tip...

    I�m reading some sample codes here and I�m still mess...
    then I drop some duke dollars in this question...
    The bellow code had failed:
                        BufferedImage bimg = (BufferedImage) this.createImage(d.width, d.height);
                        if(bimg==null)System.out.println("ttttttttttt");
                        Graphics2D g2 = bimg.createGraphics();
                        g2.rotate(90.0);
                        paint(g2);
    [/cpde]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Import  a class

    Hi all,
    i previuosly work with jbuilder 6 and i import a class (that locate in the project root directory and not include in any package) in the following way:
    import ClassName;
    and its compiled fine.
    when i start to work with Jbuilder2005 and also with netbeans,
    it refused to accept this kind of statment and im getting a compilation error.
    is any can suggest how can i import a class that has not include in any package.
    Thanks
    Gabi

    You can build classes without packages (in the default package). What you're seeing is a change in the definition of the import statement between 1.3 and 1.4. It's no longer permissable to have an import statement refering to a class without a package. The effect of this is that you can no longer refer to a class in the default package from a class in another package, because just giving the class name assumes a reference to the same package the reference is in.
    There's no problem when one class in the default package refers to another, you simply don't need the import statement.

  • Methods

    I am trying to create two methods to work inside one class and it keeps giving me the illegal start of expression at compile time.
    Any idea what I am doing wrong
    /tag
    mport javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GradesClass {
    ImageIcon schoolIcon = new ImageIcon ("c:\\users\\content\\pictures\\schoolbell.gif");
    public void runProgram() {  //Running program
         double grades[];
         grades= new double[100];
         boolean correct = false;//this keep track of whether the user entered a number or not
    String input = "";//used to store the user's input. Must be initialized here so it is in scope for second for loop
    while(!correct)
    String a = JOptionPane.showInputDialog (null, "How many grades do you need to enter?");
    int numberGrades=Integer.parseInt(a);
              if (numberGrades < 0)
    JOptionPane.showMessageDialog(null,"Please try again. There are one or more incorrect values.");
    correct = false;//this will trigger the loop to go again
    else
    correct = true;
    int k=1;
    int l=1;
    while (k<=numberGrades){
    boolean correct1 = false;//this keep track of whether the user entered a number or not
    //used to store the user's input. Must be initialized here so it is in scope for second for loop
    while(!correct1)
    String n= JOptionPane.showInputDialog(null, "Enter grade:");
    final double gradesl=Double.parseDouble(n);
              if (gradesl < 0 || gradesl > 105){
    JOptionPane.showMessageDialog(null,"Please try again. There is an incorrect value.");
    correct1 = false;//this will trigger the loop to go again
    else
    correct1 = true;
    grades[l]=gradesl;
    l++;
    k++;
    } //end while statement
    StringBuffer numbers = new StringBuffer();
    for(int x=1; x<l; x++) {
    numbers.append(grades[x] + " " ); }
    int b= JOptionPane.showConfirmDialog(null, "Are these grades correct? \n" + numbers.toString(),
                                                                "GradeKeeper v1.0", JOptionPane.YES_NO_OPTION);
    if (b == JOptionPane.YES_OPTION) {
    int c= JOptionPane.showConfirmDialog(null, "Are you finished with this session?",
                                                      JOptionPane.YES_NO_OPTION);
                                                      if (c==JOptionPane.YES_OPTION) {
              JOptionPane.showMessageDialog(null, "Thank you for using Gradekeeper v1.0 \n" +
                   " Have a great day!",
                   "Goodbye", JOptionPane.INFORMATION_MESSAGE, schoolIcon);
    else if (c==JOptionPane.NO_OPTION){
    public static void enterProgram ( ) {
              int a = JOptionPane.showConfirmDialog (null, "Do you have any grades to enter?",
                        "Welcome to Gradekeeper v1.0", JOptionPane.YES_NO_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,schoolIcon);
              if (a == JOptionPane.YES_OPTION) {
              JOptionPane.showMessageDialog(null, "Directions for Use: \n" +
                                                           "Do not leave any blank entries \n" +
                                                           "Use only numbers with no letters.\n"+
                                                           "Enter how many grades you are going to input on the following screen. \n");
              else if (a == JOptionPane.NO_OPTION) {
              JOptionPane.showMessageDialog(null, "Thank you for using Gradekeeper v1.0 \n" +
                   " Have a great day!",
                   "Goodbye", JOptionPane.INFORMATION_MESSAGE, schoolIcon);
    //End of enterProgram
    char[] gradeLetters = { 'A', 'B', 'C', 'D', 'E' };
    //public static char getGradeFromPercent( double percent) {
    //char grade;
    //if ( percent >= 0.8 ) grade = 'A';
    //if ( percent >= 0.7 && percent < 0.8 ) grade = 'B';
    //if (percent < 0.7) grade = ?C?;
    //return grade;
    } //End enterProgram
    public static void main (String [ ] args) {
    enterProgram();
    } //End of main
    } //End of GradesClass
    /tag

    Thank you so much for all your help. This is my finished product. If anyone would take the time I would love to get some critiques on how to improve this and also on my style. Does everything look okay and line up the way it should. Thanks again.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GradeClass2
        //Method created to enter the program and select if you want to use the program or leave.
          public static void enterProgram ()
          //Defaul icon of program
          ImageIcon schoolIcon = new ImageIcon ("c:\\users\\Brandon\\Pictures\\schoolbell.gif");
                //Requires user input to determine if they want to use program
                int userInput = JOptionPane.showConfirmDialog (null, "Do you have any grades to enter?",
                    "Welcome to GradeKeeper v1.0", JOptionPane.YES_NO_OPTION,
                    JOptionPane.INFORMATION_MESSAGE,schoolIcon);
            if (userInput == JOptionPane.YES_OPTION)
                //Directions wrote to use program
                JOptionPane.showMessageDialog (null, "Directions for Use: \n" +
                        "Do not leave any blank entries. \n" +
                        "Use only positive numbers without any letters.\n"+
                        "Enter how many grades you are going to input on the following screen. \n",
                                    "GradeKeeper v1.0", JOptionPane.INFORMATION_MESSAGE, schoolIcon);
            else if (userInput == JOptionPane.NO_OPTION)
                //Goodbye message
                        JOptionPane.showMessageDialog (null, "Thank you for using GradeKeeper v1.0. \n" +
                        "                     Have a great day!",
                        "Goodbye", JOptionPane.INFORMATION_MESSAGE, schoolIcon);
                                    System.exit(0);
          }//End of runProgram method 
          //Method created for the calculations of grades and inputs of grades from users
          public static void runProgram ()
            ImageIcon schoolIcon = new ImageIcon ("c:\\users\\Brandon\\Pictures\\schoolbell.gif");  //The icon of the program.
                //Declared and intialize values for error checking
                int errorCheck=1;
                //Declared and intialized to keep track of Array Elements used.
                int arrayElement=1;
                //Declared and initialized value to be used for fullReport
                int numberGrades=0;
                //Array created for the input of user grades
                double grades[];
            grades= new double[100];
                //While statement created for error checking the input of the user
                boolean correct = false;
            while(!correct)
                //String used for capturing the input of the user
                        String userInput = JOptionPane.showInputDialog (null, "How many grades do you need to enter?");
                numberGrades=Integer.parseInt(userInput);
                if (numberGrades < 0)
                    JOptionPane.showMessageDialog (null,"Please try again. There are one or more incorrect values.");
                    correct = false;//this will trigger the loop to go again
                else
                    correct = true;
                //Error checking on the grades entered into the program.
                        while (errorCheck<=numberGrades)
                    boolean correct1 = false;//This keeps track of whether the user entered a number or not
                    while(!correct1)
                        //String created to gather user's inputs regarding grades
                                    String userInput1= JOptionPane.showInputDialog (null, "Enter grade:");
                        final double gradesDouble=Double.parseDouble (userInput1);
                                    //If statement to determine if grades are valid
                                    if (gradesDouble < 0 || gradesDouble > 105)
                            JOptionPane.showMessageDialog (null,"Please try again. There is an incorrect value.");
                            correct1 = false;//this will trigger the loop to go again
                        else
                            correct1 = true;
                                    //Used to store the grade in a different element of the array for each time the loop goes around.
                                    grades[arrayElement]=gradesDouble;
                        errorCheck++;
                        arrayElement++;
                    }//End of last while statement
                }//End of second while statment
            }//End of first while statement
            //For loop used to create a String to check the validity of the user's input and to sum the grades already entered
                double sum=0;
                StringBuffer checkGrades = new StringBuffer ();
            for(int i=1; i<arrayElement; i++)
                checkGrades.append (grades[i] + "      " );
                        sum=sum + grades;
    //Question asked to user to check validity of grades. Report created through previous for loop
              int userInput= JOptionPane.showConfirmDialog (null, "Are these grades correct? \n" + checkGrades.toString (),
    "GradeKeeper v1.0", JOptionPane.YES_NO_OPTION);
    if (userInput == JOptionPane.YES_OPTION)
              //Computers average from sum and the number of grades entered
              double average = sum/numberGrades;
              //String that had to be created for compiler to compile...used for letterGrade
              String letterGrade="";
                        //If-else statements created to compute letter grade from average
                        if (average>=0 && average<=59){
                        letterGrade="E";
                             else if(average>=60 && average<=69){
                             letterGrade="D";
                             else if (average>=70 && average<=79){
                        letterGrade="C";
                             else if (average>=80 && average<=89){
                             letterGrade="B";
                             else if (average>=90 && average<=105){
                             letterGrade="A";
              //String created to print out a full report in JOptionPane
              String fullReport= ("FULL REPORT \n \n" + "TOTAL GRADES ENTERED: " + numberGrades + "\n \n"
              + "SUM OF GRADES: " + sum + "\n \n" + "AVERAGE: " + average + "\n \n"
                                                 + "OVERALL LETTER GRADE: " + letterGrade);
              JOptionPane.showMessageDialog(null, fullReport);
              }//End of If statement for Yes Option
                        //Checks if user is finished with GradeKeeper
                        int userInput1= JOptionPane.showConfirmDialog (null, "Are you finished with this session?", "Finished?",
    JOptionPane.YES_NO_OPTION);
    if (userInput==JOptionPane.YES_OPTION)
    JOptionPane.showMessageDialog (null, "Thank you for using Gradekeeper v1.0 \n" +
    " Have a great day!",
    "Goodbye", JOptionPane.INFORMATION_MESSAGE, schoolIcon);
                                            System.exit(0);
                        //Runs program again if user decides to stay in program
                        else if (userInput1==JOptionPane.NO_OPTION)
                             enterProgram();
                             runProgram();
    //Runs program again if user decides to stay in program
              else if (userInput==JOptionPane.NO_OPTION)
    enterProgram ();
    runProgram ();
    }//End of runProgram method
    //Main method to run program
    public static void main (String [ ] args)
    enterProgram ();
              runProgram ();
    }//End of GradeClass2

  • Porting Keynote for ultra-portable shows on the road

    I am starting this thread to discuss questions of how to leverage Keynote and iCloud to deliver presentations while on-the-road with limited access to hardware. To wit:
    As you can see from the listings below, I have access to useful hardware and software. I am writing this to seek advice on how to leverage these tools to give business (and personal) presentations while I'm on-the-road and may (or may not) be carrying hardware with me. If I'm forced to travel light, I was wondering if simply taking a thumb drive and/or using my iCloud account may be enough.
    I work for a small construction business that does projects in eight surrounding counties. I work as a "Producer", which means I'm both an office manager (writing up contracts and job estimates, arranging business with customers, contractors and suppliers over-the-phone) and a project manager (working with those same business contacts in-person on remote project sites). I am also applying for work outside of our business, and want to be able to use visual aids if/when necessary to illustrate what I do during an interview.
    I recently started taking a Lynda.com course on "Setting Up Your Mobile Office to Work from Anywhere", and it got me to thinking about how I could use iCloud and Apple's iWork apps to create business presentations that could be played in a variety of portable scenarios. My goal is to be able to travel light and still be able to make presentations to individuals or groups.
    MY CURRENT PERSONAL/BUSINESS HARDWARE & SOFTWARE
    iMac 13,1 : late-2012 slimline model, 2.9 GHz Core i5 processor, 8 GB RAM, 1 TB hard disk, USB SuperDrive
    MacOS X 10.8 Mountain Lion
    iLife 2011 (including iPhoto 9.2.3)
    iWork 2009 (including Keynote 5.3, Pages 4.3, and Numbers 2.3)
    Microsoft Office 2011: Mac
    Final Cut Studio 3, including Final Cut Pro 7
    Adobe Photoshop Elements 8
    iCloud account, free-tier service
    DSL high-speed connection to internet
    Have been shooting digital photos since November, 2001; manages iPhoto library of over 52,000 images
    OTHER HARDWARE AVAILABLE
    white MacBook 2006 vintage, 1.83 GHz Intel processor, 2 GB RAM, 160 GB hard disk, SuperDrive, MacOS 10.6.8, iLife 2011, iWork 2009, Microsoft Office 2011 (MacBook is not my machine; used by someone else in my office. This computer has battery issues; it must be plugged into AC power.)
    Epson EX7200 projector, with USB thumb-drive port (for JPEG presentations), VGA port, and HDMI port.
    Scenario #1: If I prepared a Keynote presentation on my iMac and transferred it via WiFi or thumb drive to the old MacBook, do I need to copy just a single Keynote file over and that's it? No attached files or folders with files in them?
    Scenario #2: I have successfully, in the past, used the Epson projector and a thumb drive loaded with photos and also a USB camera card reader with an SD card attached to show simple JPEG photo slideshows. If I wanted to just use the Epson's USB port to show Keynote slideshows, they would have to be stored in folders as JPEG files. How easy is this to prepare with Keynote? Are there any pointers available on designing a useful workflow for preparing such slideshows without a lot of fuss?
    Scenario #3: Forget the projector; too much bulk. If I had just a small iOS device like an iPod touch, and I wanted to plug into someone else's projector (or if I wanted to just show a slideshow of images to one person with no projector) what do I need to be prepared for, hardware-wise? What do I need to do with Keynote, both on the iMac for production and on the iOS device to make it look right?
    Scenario #4: Let's say I'm going to carry everything on a USB thumb drive as a backup. What is the best way to set it up to play on someone else's hardware? (I assume three tiers of compatibility: I do network with Mac/iOS users, so Tier #1 would be Apple compatibility with Keynote. Tier #2 would be general compatibility with Microsoft Office 2003/4 for pre-XML file formats. I guess that Tier #3 would be general-purpose PDF files, or maybe the JPEG file approach with thumb drive ports on projectors.) If I'm doing Tier #1 and I'm plugging my thumb drive into someone else's MacBook, are there any pointers to avoid font conflicts or other issues? If I'm doing Tier #1 and I'm borrowing someone else's iPad to show a slideshow, how do I get the files off of a thumb drive to show on the iPad?
    Scenario #5: ** iCloud ** Let's say I'm traveling VERY light, and I want to give a presentation that's stored on my Apple iCloud account. How can I organize files and folders so that Tier #1, #2 and #3 files are available (assuming I have an internet connection) so I can play a presentation off someone else's hardware, be it a tablet or laptop. Is there anything I should know about how to prepare this and how to reliably be able to log-in and access my iCloud files? Are my iWork 2009 apps going to function in preparing and saving presentation files with my iCloud account?
    Scenario #6: Scenario #6 is Scenario #5, but substituting another service instead of iCloud, like maybe Google Drive. Is there any way to set up an account with files so I can reliably be able to access said files for a presentation?

    This is a great reminder. I too labor over my slides, sometimes way too much labor and not enough on the presentation. This is also a reminder to check out your venue BEFORE you arrive. Talk to the tech in charge if at all possible and tell him/her the system your bringing and ask if they can accommodate your requirements. I am giving 4 classes for adult continuing education at a local high school. I've had to bring my own flat screen TV because their projector was sub-par and did nothing for my slides.
    Best practice if it is feasible and reasonable to go to the venue and check it out days before your presentation.
    For the amount of work we put into our slides, we deserve for them to be shown at the best possible resolution.
    Thanks again for the reminder.

Maybe you are looking for

  • Problem with C++ parser V2 (XDK 9.0.1.2.0)

    Hi, The problem describe in a previous message (id=416237, march 2001) with the C++ XDK 8.1.7.1 still remains with the new XDK! I can't use the function print to a FILE* on a Node. I try to print to stdout or a file => [Linstruction ` + 0x77F7CE4C ;

  • How to generate unique random numbers

    Hi All, I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows: Random diceRoller = new

  • Best way to do a 4:3 pan & scan in terms of resolution?

    Brethren, I need to deliver a broadcast quality version of my project in 4:3 pan-and-scan. The project is made up of five 20 minute long pieces, usually holding about 1 or 2 layers of video, sometimes 3 or 4. I've read a few other threads on this top

  • JMS / MBD Best Practices

    Hello All, There is currently a dispute in my camp about the limit of "responsibility" to place on a single MDB. In this case, the argument surrounds whether it is "good practice" to allow a MDB's onMessage function to: - Open a connection to a servl

  • CUCM IM and P Design - DNS SRV -

    Hey guys. I would like to design a CUCM IM and P infrastructure for my customer. High availability is mandatory for my customer and here is what I found from the documentation: Configure SIP Trunk for IM and Presence Service If high availability is c