Can a JSP return an image?

          Can a JSP page be written so that it returns an image? What are the
          available MIME types that can be returned? IOW, what is the possible values
          of the "page" directive attribute "content-type"? Better yet, where can I
          find it, and for that matter, docs of this type?
          Thanks!
          

Yes, a JSP can return an image. However, it is better (less error prone,
          more straight-forward) just to use a servlet. Here's one example from Erik
          L:
          From: "Erik Lindquist" <[email protected]>
          Newsgroups: weblogic.developer.interest.jsp
          Sent: Wednesday, June 28, 2000 6:20 PM
          Subject: How to dynamically display images in JSPs
          > This took a little while to figure out so I thought I'd share. After
          > doing some research I was led to the following approach on how to load
          > images from an Oracle database into a JSP:
          >
          > The "main" JSP:
          >
          > <HTML>
          > <head>
          > <title>Image Test</title>
          > </head>
          > <body>
          > <center>
          > hello
          > <P>
          > <img border=0 src="getImage.jsp?filename=2cents.GIF">
          > <P>
          > <img border=0 src="getImage.jsp?filename=dollar.gif">
          > <P>
          > world
          > </body>
          > </HTML>
          >
          >
          > And this is the image getter:
          >
          > <% try {
          > response.setContentType("image/gif");
          > String filename = (String) request.getParameter("filename");
          > java.sql.Connection conn =
          > java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
          > connect to db
          > java.sql.Statement stmt = conn.createStatement();
          > String sql = "select image from testimage where filename = '" +
          > filename + "'";
          > java.sql.ResultSet rs = stmt.executeQuery(sql);
          > if (rs.next()) {
          > byte [] image = rs.getBytes(1);
          > java.io.OutputStream os = response.getOutputStream();
          > os.write(image);
          > os.flush();
          > os.close();
          > }
          > conn.close();
          > }
          > catch (Exception x) { System.out.println(x); }
          > %>
          >
          >
          > The thing to note is that there are no <%@ page import="..." %> or <%@
          > page contentType="..." %> tags - just the single scriptlet. It
          > seems that for every "<%@" the weblogic compiler sees it puts
          > out.print("\r\n"); statements in the generated java source.(???) I
          > don't know much about how browsers work but I think that once it sees
          > flat ascii come at it it treats everything that follows as text/plain
          > which is incorrect for the binary stream that's being sent. Another
          > work around was to set out = null; but that's kind of ugly and might
          > produce server errors. The real fix is to write a bean to handle images
          > which I'll work on next (does anybody have any hints on how to do
          > that?)
          Cameron Purdy
          Tangosol, Inc.
          http://www.tangosol.com
          +1.617.623.5782
          WebLogic Consulting Available
          "Peter Bismuti" <[email protected]> wrote in message
          news:[email protected]...
          >
          > Can a JSP page be written so that it returns an image? What are the
          > available MIME types that can be returned? IOW, what is the possible
          values
          > of the "page" directive attribute "content-type"? Better yet, where can I
          > find it, and for that matter, docs of this type?
          >
          > Thanks!
          >
          >
          

Similar Messages

  • Can I able to include image/.js file to payload-body.jsp

    Dear Experts,
    Could anyone please tell me that how can I refer a external javascript file from payload-body.jsp and where should I place the same. Also please tell the same to display an image. Please suggest me ASAP.
    Thanks,
    Rajesh

    Hi,
    so what source address of js file i have to give in jsp page.....in your case you can use below include command
    <jsp:include page="script/test.js" /> // here test.js is your .js file nameGenerally we need to place all jsp and js files under "jdevhome\jdev\myhtml\OA_HTML". In this case you can use
    <jsp:include page="test.js" /> // here test.js is your .js file nameor
    <%@include file="test.js" %>  // here test.js is your .js file nameregards,
    Anand

  • This is my Jsp code for image upload in database:

    This is my Jsp code for image upload in database:
    -----------Upload.jsp----------------
    <html>
    <head>
    </head>
    <body bgproperties="fixed" bgcolor="#CCFFFF">
    <form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
    <%! int update=0; %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.sql.Date" %>
    <%@ page import="java.io.*"%>
    <%@ page language = "java" %>
    <%
    try
    String ct="3";
    String path;
    File image=new File(request.getParameter("upload"));
    path=request.getParameter("upload");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
    PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)");
    pstmt.setString(2,path);
    pstmt.setString(3,ct);
    InputStream is=new FileInputStream(path);
    pstmt.setBinaryStream(1, is, (int)(image.length()));
    int s=pstmt.executeUpdate();
    if(s>0)
    out.println("Uploaded");
    else
    %>
    unsucessfull
    <%}
    is.close();
    pstmt.close();
    catch(Exception e)
    }%>
    </p>
    <p><br>
    <img src="UploadedPicture.jsp">image</img>
    <p></p>
    </form>
    </body>
    </html>
    My database name is itPlusElectronics and the table name is "graphics".
    I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows-------
    picture path id
    Long binary data D:\AMRIT\1-1-Picture.jpg 3
    To retrive and display i use this JSP code as--
    ------------------------UploadedPicture.jsp------------------------------
    <html>
    <head>
    </head>
    <body bgproperties="fixed" bgcolor="#CCFFFF">
    <%! int update=0; %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.io.*"%>
    <%@ page language = "java" %>
    <%@page import="javax.servlet.ServletOutputStream"%>
    <%
    try
    String path;
    path=request.getParameter("upload1");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
    PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'");
    // pst.setString(3, id);
    ResultSet rs = pst.executeQuery();
    path=rs.getString("path");
    if(rs.next()) {
    byte[] bytearray = new byte[4096];
    int size=0;
    InputStream sImage;
    sImage = rs.getBinaryStream(1);
    response.reset();
    response.setContentType("image/jpeg");
    response.addHeader("Content-Disposition","filename=path");
    while((size=sImage.read(bytearray))!= -1 )
    response.getOutputStream().write(bytearray,0,size) ;
    response.flushBuffer();
    sImage.close();
    rs.close();
    catch(Exception e)
    %>
    </body>
    </html>
    Now after browsing a jpg image file from client side and pressing submit button ;
    I am unable display the image in the Upload.jsp file.Though I use
    <img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp
    file .
    Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page..
    If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!

    dketcham wrote:
    cotton.m wrote:
    >
    2) I'm looking at how you called stuff, and you're trying to call the jsp file as an image? That jsp isn't the source of the image, just a page linking to an image. I think if you really want to do things that way you're going to need to just include that jsp within the jsp you're calling it from (or you can do it the easy way, and if you have the information to get the path of the image you want, you could simply call the image from the first jsp you posted)This is incorrect.
    There are two JSPs. The second when called will (if it worked) return the source of an image as stored in the database.even when called with <img src=xx.jsp>??
    Yes.
    If any of what I say next seems obvious or otherwise negative I apologize, just trying to explain and I don't know what you know vs what you don't.
    The link in the src is just a URL not a filetype. So just because it ends with JSP does not mean it has to return HTML. The content type is determined by the browser using the Content-Type header returned by the server in the HTTP response. In this case the header is set to be a jpeg so that's what the browser will attempt to interpret the content part of the response as.
    So in fact one is not limited to just HTML or images but whatever content type you would like to return (that the browser can understand anyway). This could be HTML or it could be an image of some type or it could be a PDF or it could be an Excel spreadsheet. All you have to do in the JSP is set the header appropriately and then send content that is actually in that format.
    This does not just apply to JSP by the way but all other web programming languages. You can do similar things to produce the same results in PHP, Perl, ASP etc.
    The only JSP/Servlet complication is whether or not doing this in a JSP is a "good" idea but I am not an expert enough at that to make a definitive statement. Mostly though JDBC in a JSP is a no-no.

  • Using Javascript to rotate images with the style.backgroundImage property & I leave the onload pg & return, the images have trouble loading.

    I'm using Javascript to rotate background images -->
    function rotateImages() {
    setInterval("startRotator()", 7000);
    var counter = 0;
    function startRotator() {
    var images = ["images/finance1.jpg","images/finance2.jpg","images/finance3.jpg","images/finance4.jpg","images/finance5.jpg","images/finance6.jpg"];
    if( counter >= images.length ) {
    counter = 0;
    var image = "url('" + images[counter] + "')";
    counter++;
    document.body.style.backgroundImage=image;
    The script is triggered by the load event when the homepage loads and the script only runs on the homepage. Everything works fine upon opening the homepage.
    If I leave the home page and return, the images will have trouble loading for about 3 to 5 cycles and I'll get white backgrounds for part of the time. The same thing happens if I enter the site from a page other than the homepage and then go to the homepage.
    I discovered, however, that if I enter the site at the homepage and then leave the homepage and return using the back button, everything runs fine. Apparently it then accesses a cached version of the homepage? Seems having two cached versions creates a conflict?
    This problem only happens with Firefox (I have ver 29.0.1). It does not happen on IE ver 11, Chrome ver 34, or Safari ver 5.1.7.
    I get the same problem with XP, Win7, and Win8 but, only on Firefox.
    Can you please fix this?

    Hey, I am trying to reproduce this here: [http://jsfiddle.net/u3TLb/]
    Mozillazine forums and the [http://webcompat.com] are more specialized in Web Compatibility, please ask there as well.

  • Jsp code for image compression

    Hai,sir this is surendra i am doing a project using jsp and mysql.
    In that each user can put his image and i am storing that image in mysql blob but that results to that database size.
    So i need jsp code for image compression or another way for storing images.

    There's no need to store images in db. You may store them in a dedicated folder.

  • ImageIcon : How can I find out if image is loaded correctly?

    How can I find out if image is loaded coretly? (see example)
    private Image img;
    img = new ImageIcon("C:\image.jpg").getImage();
    If path is wrong, there is no exception or null in img.
    Thanks....
    Message was edited by:
    ptibull77

    also from the ImageIcon docs (note the ERRORED and ABORTED):
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ImageIcon.html#loadImage(java.awt.Image)
    getImageLoadStatus
    public int getImageLoadStatus()Returns the status of the image loading operation.
    Returns:
    the loading status as defined by java.awt.MediaTracker
    See Also:
    MediaTracker.ABORTED, MediaTracker.ERRORED, MediaTracker.COMPLETE

  • I can't open RAW (cr2) images from my Canon EOS 650D

    Hey,
    I use Photoshop CS5 Extended (Version 12.1 x64). I can open the raw-Images (cr2) from my Canon EOS 1000d/Rebel XT but I can not open the RAW-Images (cr2) from my Canon EOS 650D (Rebel T4i). I have installed the latest update for CS5 through the updaate command.
    How can I open them?
    Thank you!

    Hi there,
    Support for RAW from Rebel T4i was launched in ACR 7.2 (Adobe Camera Raw). However, ACR 7.x is compatible only from CS6, not on CS5.
    Sorry, but you can work with the installation disc you've got from Canon to convert the files into TIFF/ JPG or get the 7.2 DNG converter from here:
    Win - http://www.adobe.com/support/downloads/detail.jsp?ftpID=5486
    Mac - http://www.adobe.com/support/downloads/detail.jsp?ftpID=5485
    Why don't you consider upgrading to CS6? There are some great upgrade prices in store right now.
    -ST

  • Why can't I resize jpg images in the applet?

    I used this code to display images in an html page. One applet for one image. But out of the 8 images I loaded, 6 adjusted themselves to 320x240 automatically, 1 randomly jumps around to certain parts of the image every 250millisecs, and 1 just cuts the top left hand part of 320x240. How can .jpg files give 3 different situations? I tried using the resize() method in the code but it doesn't do anything! How can I size those .jpg images to the size I want?
    /**This video stream applet loads a new image every 250ms
    import java.applet.*;
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.awt.event.*;
    public class Video extends Applet implements Runnable{
    private Image img,buffer;
    private Thread video = null;
    private URL url;
    private MediaTracker tracker;
    public synchronized void init(){
    tracker = new MediaTracker(this);
    try{url = new URL(getCodeBase(),"Camera1.jpg");}
    catch(MalformedURLException e){}
    img = getImage(url);
    tracker.addImage(img, 0);
    buffer = createImage(320,240);
    resize(320,240);
    if(video!=null)return;
    video = new Thread(this,"VideoStream");
    video.start();
    public synchronized void destroy(){
    if(video!=null)video=null;
    public void run(){
    while(!Thread.interrupted()){
    // Load new image.
    try{tracker.waitForID(0);}
    catch(InterruptedException e){}
    // Draw new Image.
    repaint();
    // Remove old image & add new one.
    tracker.removeImage(img,0);
    img.flush();
    tracker.addImage(img,0);
    // Sleep
    try{Thread.sleep(250);}
    catch(InterruptedException e){}
    public synchronized void update(Graphics g){
    Graphics bufGraph = buffer.getGraphics();
    bufGraph.drawImage(img,0,0,this);
    paint(bufGraph);
    g.drawImage(buffer,0,0,this);
    public void paint(Graphics g){
    g.drawImage(buffer,0,0,this);
    Also how can I add more than 1 .jpg in an applet since the applet tag for html is
    <applet code = Video.class width =... height = ...>
    <param name = "buffer" value = "Camera1.jpg"> ...and I can only put
    </applet> one file for "value
    Thanks a lot for ur help!

    you may try the function getScaledInstance(int,int,int) in Class Image.
    the first and second parameters are the width and height you want,the third parameter is hints-flags to indicate the type of algorithm to use for image resampling.

  • Consume a web service from JME that returns an image

    Hi,
    I have a web service that returns an image in base64binary format, but when i use the wscompile tool to generate the stub i get an error becuase seems that JME does not support base64binary -> byte[] convert. My question is: How can i return an image from web service to consume from JME?.
    Thanks in advance.
    Bruno

    I tried this and works fine, but i see this like a workaround instead of a solution. Do you know why JME doesn't support this type of data? I think that is weird because i don't see a limitation on JME for use it.
    Thanks for repsonse.

  • How can I edit a RAW image in Adobe Bridge and/or Photoshop?

    Whenever I drag and drop a photo or group of images from iPhoto. it automatically converts them to jpegs. Even when taken as RAW images. With iPhoto 09, you could do a search of the IMG_#### listed in iPhoto, and a normally-hidden folder full of the original downloaded RAW images turned up in the search. Now, in iPhoto 11, the RAW images newly downloaded DO NOT show up in any system searches (using 10.8.4. It was bad enough when they were hidden... now they are virtually gone.
    I want to use iPhoto for organization and some editing, but some photos I want to work with in the RAW format and save as TIFFs. How do I do that?

    Whenever I drag and drop a photo or group of images from iPhoto. it automatically converts them to jpegs.
    Drag and Drop and Media Browsers access the iPhoto Previews only. No conversion, just the previews.
    With 10.8 Spotlight no longer searches within packages, that's to protect the inexperienced user from trashing his or her library inadvertently - as directly accessing the file can do.
    To use Raws with an external editor:
    First off set your preferred app as an external editor in iPhoto:
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Next: In the iPhoto Preferences -> Advanced, elect to use Raw with your External editor:
    Now when you go to edit the Raw it will be sent to your external editor.
    But there's a kludge here.
    iPhoto sends a copy of the file to Photoshop. In the case of a Jpeg you simply save and it all comes back to iPhoto seamlessly. However, if you use a Save As then Photoshop is creating a new file and iPhoto knows nothing about this.
    Now here's the catch with Raws. You cannot save a Raw. The work you do must be output to a new file, in a new format (jepg, tiff, whatever). However, as the External Editor is making this new file iPhoto has no knowledge of its existence. Therefore you must save it to the desktop and then import it back to iPhoto as a new file.
    This means that you will have your Original Raw and the processed version in iPhoto but they will not be recognised as version and original. iPhoto will see them as two separate shots.

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

  • In the new iphoto app, why can't i save multiple images to camera roll at once?

    why can't i save multiple images to camera roll at once? it seems i can only save one at a time and its very frustrating..
    the options seem to be there, they are just greyed out and i cant click on them.
    at first i thought its because the images were too big, so i tried it with smaller images but same thing.
    APPLE HELP!

    I can confirm @khaniff's original post the option in iPhoto for iOS is greyed out in conflict with the referenced article that follows:
    Save to the Camera Roll
    Tap a photo, album, or event and tap .
    Tap Camera Roll.
    Confirm or change the photos you want to share by tapping an option.
    Select all the photos in an album or event: Tap All.
    Select a range of photos: Tap Choose, tap Range, tap the first and last photos in the range, and tap Next.
    To use your photo in another app, open the app and select the Camera Roll album.

  • Return an Image from a subclass to a graphics class

    Hello
    I'm wondering how to return an Image generated by one class to a class which works as a graphics class. The graphics class is run from a main class. Let me make up a schedule:
    Image-generator return Image -> graphics class paint
    I have tried just making an Image and using the getGraphics to connect a graphics object to it, but it doesn't seem to work.
    Thanks in advance

    Okay, here are the pieces of code we use. (Comments are in Swedish but they are barely relevant, and explain merely basically what is happening in the program)
    The applet is compilable, but there is a nullpointerexception in Elefanträknaren, at getGraphics(). Believe me, I have tried finding the solution to this already.
    Spelet (main method)
    import java.applet.*;
    import java.awt.*;
    public class Spelet extends Applet
         /*Elefanträknaren testerna;*/
         Ritaren ritarN;
         Graphics g;
         public void init()
              /*testerna = new Elefanträknaren();*/
              ritarN = new Ritaren(g, getSize().width, getSize().height);
              setLayout(new GridLayout(1, 1));
              add(ritarN);
         public void start()
              ritarN.startaTråd();
         public void stop()
              ritarN.stoppaTråd();
         public void update(Graphics g)
              paint(g);
    }Ritaren (graphics object)
    import java.awt.*;
    public class Ritaren extends Panel implements Runnable
         Elefanträknaren e;
         Graphics g;
         int bredd, höjd;
         //Trådobjekt
         Thread tråd;
         public Ritaren(Graphics g, int bredd, int höjd)
              this.bredd = bredd;
              this.höjd = höjd;
              e = new Elefanträknaren(bredd, höjd);
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
                   e.startaTråd();
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         public void paint(Graphics g)
              g.drawImage(e.getSpökbilden(), 0, 0, this);
         public void update(Graphics g)
              paint(g);
         public void run()
              while( tråd != null )
                   repaint();
                   try
                        Thread.sleep(33);
                   catch(Exception e){}
    }Elefanträknaren (class generating the Image)
    import java.awt.*;
    import java.util.*;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    public class Elefanträknaren extends Panel implements Runnable
         //Vektorn som innehåller alla Elefant-klasser
         private Vector elefanterna;
         //Ritobjektet för den dubbelbuffrade bilden
         private Graphics gx;
         //Bildobjektet för dubbelbuffringen
         private Image spökbilden;
         private int bredd, höjd;
         //Trådvariabeln
         private Thread tråd;
         //Rörelsen uppdateras 30 ggr/s. RÄKNARE håller koll på när en elefant ska läggas till (efter 30 st 30-delar = 1 ggr/s)
         int RÄKNARE = 30;
         int ÄNDRING = RÄKNARE;
         //DELAY betecknar delayen mellan två bilder/frames. 33 ms delay = 30 FPS
         int DELAY = 33;
         //Konstruktor
         public Elefanträknaren(int bredd, int höjd)
              elefanterna = new Vector();
              this.bredd = bredd;
              this.höjd = höjd;
         //Kör igång tråden/ge elefanterna liv
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
                   //Dubbelbuffringen initieras - detta måste ligga i startaTråd()
                   //spökbilden = new BufferedImage(bredd, höjd, BufferedImage.TYPE_INT_ARGB);
                   spökbilden = createImage(bredd, höjd);
                   gx = spökbilden.getGraphics();
         //Stoppa tråden/döda elefanterna
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         //Lägg till en elefant i vektorn
         private void läggTillElefant(Elefant e)
              elefanterna.add(e); //Lägg till en Elefant som objekt i vektorn
              Elefant temp = (Elefant)     elefanterna.get(elefanterna.size()-1);
              temp.startaTråd(); //Starta Elefantens tråd - ge Elefanten liv
         //Sätter ihop bilden som ska sickas till Ritaren
         public void uppdaterarN()
              //Rensa skärmen från den förra bilden
              gx.fillRect(0, 0, bredd, höjd);
              for( int i = 0; i < elefanterna.size(); i++ )
                   Elefant temp = (Elefant) elefanterna.get(i);
                   gx.drawImage(temp.getBild(), temp.getX(), temp.getY(), null);
         public Image getSpökbilden()
              return spökbilden;
         //Tråd-loopen
         public void run()
              while( tråd != null )
                   RÄKNARE++;
                   if( RÄKNARE >= ÄNDRING )
                        läggTillElefant(new Elefant(11, 50, 900));
                        RÄKNARE = 0;
                   uppdaterarN();
                   //repaint();
                   try
                        Thread.sleep(DELAY);
                   catch(Exception e){}
    }Elefant (a class which Elefanträknaren turns into an Image:
    import java.awt.*;
    import java.util.*;
    import javax.swing.ImageIcon;
    public class Elefant extends Panel implements Runnable
         private int x, y; //Elefantens koordinater
         private int hälsa; //Elefantens hälsa
         private int RÖRELSESTEG = 10;//Antal pixlar elefanten ska röra sig i sidled
         private int DELAY;
         //Animation
         private Vector bilderna = new Vector();
         private Vector bilderna2 = new Vector();
         private int fas; //Delen av animationen som ska visas
         private boolean framåt;
         //Tråddelen
         private Thread tråd;
         public Elefant(int x, int y, int hastighet)
              this.x = x;
              this.y = y;
              DELAY = 1000 - hastighet;
              hälsa = 100;
              framåt = true;
              fas = 0; //Nollställ fasen
              //Få fram bildernas namn
              for( int i = 0; i <= 5; i++ )
                   Image temp = new ImageIcon("Z:\\Projektet\\gamal\\Projektet\\Mappen\\mediat\\png\\jumbo" + i + ".png").getImage();
                   bilderna.add(temp);
                   Image temp2 = new ImageIcon("Z:\\Projektet\\gamal\\Projektet\\Mappen\\mediat\\png\\jumbo" + i + "r.png").getImage();
                   bilderna2.add(temp2);
         //get-variabler
         public int getX() { return x; }
         public int getY() { return y; }
         //Kör igång tråden/ge elefanten liv
         public void startaTråd()
              if( tråd == null )
                   tråd = new Thread(this); //Skapa tråden
                   tråd.start(); //Kör igång
         //Rör elefanten i sidled
         private void rörelse()
              //Animering
              if( fas < 5 ) fas++;
              else     fas = 0;
              //Flytta ner elefanten när den når en av spelets kanter
              if( x >= 800 || x <= 10 ) y += 85;
              //Kontrollera riktning
              if( x >= 800 ) framåt = false;
              else if( x <= 10 ) framåt = true;
              //Positionering
              if( framåt ) x += RÖRELSESTEG;
              else x -= RÖRELSESTEG;
         //Hämtar den aktuella bilden, och returnerar den
         public Image getBild()
              Image temp;
              if( framåt ) temp = (Image) bilderna.get(fas);
              else temp = (Image) bilderna2.get(fas);
              return temp;
         /* Tråd-hantering */
         //Stoppa tråden/döda elefanten
         public void stoppaTråd()
              if( tråd != null )
                   tråd.interrupt();
                   tråd = null;
         //Körs när elefanten är vid liv
         public void run()
              while( tråd != null )
                   rörelse();
                   try
                        Thread.sleep(DELAY);
                   catch(Exception e){}
    }

  • How can I restore a single image from an aperture time machine backup, do I have to restore the entire library? that does not make sense

    I hope there has been found a more efficiant solution for this,  how can I restore a single image from an aperture time machine backup, I really hope I don't have to restore the entire library? that does not make sense
    any suggestions?

    Did you try browsing your backups in the Finder ?  That is, do not go and "Enter Time Machine".  Instead, navigate to your Time Machine backup via Finder and then manually go to the time period (by folder name) you are looking for ... when you find your Aperture library you can then "Show Package Contents" and find the Master you are looking for.

  • How can I keep a photo image from fading away on my tv using apple tv.

    How can I keep a photo image from fading away on my tv using apple tv?

    Thanks for you reply.  When I paint, I bring up the photo as you suggested.  I begin painting.  After about 10 minutes or so, the photo goes blank.  And, I have to start the process over again to get that same photo.  It interrupts the painting process.  I think it goes blank due to a sleep function.  I have gone into the Apple TV settings and turned off the sleep function.  But, this does not seem to work.  What can I do to keep the image on the TV screen permanently?

Maybe you are looking for

  • Scroll down/up functionality in a jMenu?

    What i mean is a jMenu similar to that of internet explorer's Favorites menu. When you have a ton of favorites you get a little arrow pointing down or up depending on where you are in the menu. Is it possible to implement something similar in java wi

  • Can't paste a paragraph into Dreamweaver code

    Hi there, Big thank you to whoever can help with this one... I am trying to paste a paragraph of text I have copied from a website, "Lorem Ipsum" in fact, but when I paste it within paragraph tags - or code view general - Dw returns the data as one l

  • Removing library from Apple TV

    I just did a fresh install on my system, and Apple TV recognizes my iTunes library as a new one, distinct from the original that no longer exists. Since the old system is gone, I can't use iTunes to remove the Apple TV from the old library. As a resu

  • Vendor Master and Bank Key Master-Confirmation required

    Hi Gurus, Is there any possibility in SAP, wherein we create Vendor master and Bank Key, but we can use that vendor or bank key only after confirmation/approval given by concerned person? Please revert asap. Thank You

  • Help with After Effects' expressions

    Hi, I'm actually working on simulations of movements and I'd like to make an expression to set position and rotation in function of time . my functions are : position : X(t)= 15(cm/s)* t (s) rotation :  F(t)= -5(rad/s) *t (s) Thanks in advance