Help on moving of image across screen(java application,not applet)

I've searched the entire internet and everything I've found is on java applets and I'm an alien to the differences between an applet and an application.
This is actually for a java game I'm creating using Eclipse's visual editor and I'm failing miserably.
What I'm trying to do is to find some java source code that enables me to start an image automatically moving across the screen that only stops when I click on it. I did find some applet codes but when I tried converting it to application code a load of errors popped out.
Thanks for the help if there's any! I'm getting desperate here because the game's due this friday and I'm stuck at this stage for who knows how long.

Here is one of the codes I found ,it's not mine but I'm trying to edit it into a java application instead of an applet...Sort of like: ' public class MovingLabels extends JFrame ' or some code that I can copy and paste into another java program.
* Swing version.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MovingLabels extends JApplet
implements ActionListener {
int frameNumber = -1;
Timer timer;
boolean frozen = false;
JLayeredPane layeredPane;
JLabel bgLabel, fgLabel;
int fgHeight, fgWidth;
int bgHeight, bgWidth;
static String fgFile = "wow.gif";
static String bgFile = "Spring.jpg";
//Invoked only when run as an applet.
public void init() {
Image bgImage = getImage(getCodeBase(), bgFile);
Image fgImage = getImage(getCodeBase(), fgFile);
buildUI(getContentPane(), bgImage, fgImage);
void buildUI(Container container, Image bgImage, Image fgImage) {
final ImageIcon bgIcon = new ImageIcon(bgImage);
final ImageIcon fgIcon = new ImageIcon(fgImage);
bgWidth = bgIcon.getIconWidth();
bgHeight = bgIcon.getIconHeight();
fgWidth = fgIcon.getIconWidth();
fgHeight = fgIcon.getIconHeight();
//Set up a timer that calls this object's action handler
timer = new Timer(100, this); //delay = 100 ms
timer.setInitialDelay(0);
timer.setCoalesce(true);
//Create a label to display the background image.
bgLabel = new JLabel(bgIcon);
bgLabel.setOpaque(true);
bgLabel.setBounds(0, 0, bgWidth, bgHeight);
//Create a label to display the foreground image.
fgLabel = new JLabel(fgIcon);
fgLabel.setBounds(-fgWidth, -fgHeight, fgWidth, fgHeight);
//Create the layered pane to hold the labels.
layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(
new Dimension(bgWidth, bgHeight));
layeredPane.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (frozen) {
frozen = false;
startAnimation();
} else {
frozen = true;
stopAnimation();
layeredPane.add(bgLabel, new Integer(0)); //low layer
layeredPane.add(fgLabel, new Integer(1)); //high layer
container.add(layeredPane, BorderLayout.CENTER);
//Invoked by the applet browser only.
public void start() {
startAnimation();
//Invoked by the applet browser only.
public void stop() {
stopAnimation();
public synchronized void startAnimation() {
if (frozen) {
//Do nothing. The user has requested that we
//stop changing the image.
} else {
//Start animating!
if (!timer.isRunning()) {
timer.start();
public synchronized void stopAnimation() {
//Stop the animating thread.
if (timer.isRunning()) {
timer.stop();
public void actionPerformed(ActionEvent e) {
//Advance animation frame.
frameNumber++;
//Display it.
fgLabel.setLocation(
((frameNumber*5)
% (fgWidth + bgWidth))
- fgWidth,
(bgHeight - fgHeight)/2);
//Invoked only when run as an application.
public static void main(String[] args) {
Image bgImage = Toolkit.getDefaultToolkit().getImage(
MovingLabels.bgFile);
Image fgImage = Toolkit.getDefaultToolkit().getImage(
MovingLabels.fgFile);
final MovingLabels movingLabels = new MovingLabels();
JFrame f = new JFrame("MovingLabels");
f.addWindowListener(new WindowAdapter() {
public void windowIconified(WindowEvent e) {
movingLabels.stopAnimation();
public void windowDeiconified(WindowEvent e) {
movingLabels.startAnimation();
public void windowClosing(WindowEvent e) {
System.exit(0);
movingLabels.buildUI(f.getContentPane(), bgImage, fgImage);
f.setSize(500, 125);
f.setVisible(true);
movingLabels.startAnimation();
}

Similar Messages

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • How to change heap memory size for general java applications (not applets)

    Hi. I made a java class which manipulates images and I sometimes get an out of memory error when the files are large. In these cases I can run it successfully from the command line using:
    java -Xms32m -Xmx128m myappbut as I run this class from a firefox extension, I can't use this technique.
    Could some one tell me how to set this globally? I've found a lot of info on setting it for applets in the control panel but that's it. I also tried editing my deployment.properties file by adding:
    deployment.javapi.jre.1.6.0_11-b03.args=-Xmx128mbut none of these options seem to work.
    Thanks for any help.

    Also you can use use [JAVA_TOOL_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#tooloptions], with more documentation here. JAVA_TOOLS_OPTIONS is available since 1.5. There is no direct documentation on [_JAVA_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html] but was made available since at least 1.3.
    The recent existing forum thread [Java Programming - How to change the default memory limits for java.|http://forums.sun.com/thread.jspa?threadID=5368323&messageID=10615245&start=36] has a long discussion on the issue.
    You specified you are not using applets, but if you do, I would also suggest you use the next Generation Plug-in (since 1.6.0_10) that allows you specify the max memory in the applet without having to instruct the user how to make the change. See [JAVA_ARGUMENTS|https://jdk6.dev.java.net/plugin2/#JAVA_ARGUMENTS] for applets. Java Webstart uses resources.

  • Repaint in Java application (not Applet)

    Hi,
    I have server application with GUI containing TextArea. On any connection request from client, the application creates a thread which deals with the client request. Once the client request finishes, I want to show the detail of the client which connected to the server in the TextArea. Now I have extended the main server class for the thread class, which deals with the client, and have a method in the main server class which appends string on the textarea. BUT, when thread call that function nothing appears in the TextArea. I have checked that the thread is calling the method correctly, I think I need to repaint the TextArea. How? I am looking for your help. I have tried repaint, it does not work. Appreciate any help in this regard,
    Here is the code.
    Server side.......
    public synchronized void displayMessage( String thismessage) {
         System.out.println("-----> " + thismessage);
         editPan.setEditable(true);
         editPan.append(thismessage + "\n");
    public void run() {
    while(true) {
    try {
    server = new ServerSocket( 5000, 100 );
    while(listening) {
    connection = server.accept();
    if(connection != null) {
    alertDialog cThread = new alertDialog(connection, errorNumber);
    (new Thread(cThread)).start();
    errorNumber++;
    connection = null;
    catch( IOException e ) {
    System.out.println("Exception : " + e.toString() );
    Client Attender Thread class (alertDialog) which extends server class......
    public void run() {
    try {
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String inputLine = in.readLine();
    System.out.println(" " + dateString + " " + inputLine );
    // super.editPan.append(" Test from alert.. \n");
         super.displayMessage(" " + dateString + " " + inputLine);
    JOptionPane.showMessageDialog(null, inputLine, "Alert....", JOptionPane.ERROR_MESSAGE);
    in.close();
    } catch (IOException e) {

    Be careful when calling Swing methods from outside the EventDispatch thread. If you call a swing method from a thread, you should use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater().
    See http://java.sun.com/docs/books/tutorial/uiswing/mini/threads.html for more details.

  • HELP! moved "all images" to trash by mistake. They are still there but I can't undo. How can i return photos to iphoto? Thx!

    HELP! moved "all images" to trash by mistake. They are still there but I can't undo. How can i return photos to iphoto? Thx!

    Thanks but I have no "Put Back" option when right-clicking. When I attempt to open a photo in iPhoto I receive a white exclamation point on a black background. I have restarted my PC since first encountering this problem but have not emptied trash though i appear to be out of memory. Also, iphoto library shows size as 17GB however, each photo shows 0KB. When i attempt to open a photo i receive message "Item <photo filename> is used by Mac OS X and cannot be opened." I can see the images when scrolling in iPhoto but they disappear when the screen is still. THANKS!

  • Display an Image in a Java application !

    Hi all !
    Really i want to display an image in a java application , i know how to do it in applets but this method does not work in applications so please help me to do that in an application ,thanks .

    it is the same way as in applets.
    1. Open a frame with awt
    2. Define an Image (like: Image a=null;)
    3. Load this Image with the Toolkit....(just look which method to use)
    4. draw this image to screen with g.drawImage(...)
    Note the class drawing the image must implement ImageObserver.
    regards

  • How can I put an image/s in Java Application?

    Hi to all.
    How can I put an image/s in Java Application?
    I can put some images in Java applet but when i try to put it in Java application there was an error.

    hey u can easily do it with JLabels...i found a Code Snippet for u
    public class MyPanel extends JPanel
    {private JLabel imageLabel; public MyPanel() {     Image image = Toolkit.getDefaultToolkit().getImage("myimage.gif"); // Could be jpg or png too     imageLabel = new JLabel(new ImageIcon(image));     this.add(imageLabel);  }}
    hope it helps
    Cheers,
    Manja

  • How to import the image by using java application

    1.how to import the image by using java APPLICATION and display it on the textarea that you have been created.
    2.how to store the image into the file.
    3. what class should i used?
    4. how to create an object to keep track the image in java application.
    * important : not java applet.
    plzzzzzzz.
    regards fenny

    follow the link:
    http://java.sun.com/docs/books/tutorial/2d/images/index.html

  • Why does Java Application not working with Macromedia Flash 5 or MX?

    Why does Java Application not working with Macromedia Flash 5 or MX?

    Who says they don't?
    Although I don't know much about those I'd think they should be able to talk to Java Aps using Sockets or request Servlets ...
    Spieler

  • Java application not working

    Running Win98. I somehow removed the Java application from my computer, and am unable to open any java appelets or javascript. Where can I download the JVM for Win98. Currently all I have is JVM 1.5.0_05 (which is for Win98SE), and doesn't work. I went back to the MSJVM which doesn't work either. Any help would be greatly appreciated.

    Don't know, but I uninstalled it. I'm trying to get 1.4.2_07 back.

  • Java "Application not found"

    Hi,
    I wonder of you can help me please, I'm new here and looking for an answer to a problem with my Java files.
    Perhaps I should start a new thread for the new question? Please advise me...
    'Problem' is:
    When I try to open the 'Java' icon on the 'controll panel' page, it says 'Application not found' !? :(
    I have tried re-installing Java but it still says 'Application not found'.
    (There is a plain box on the control panel, where the Java sign should be, but nothing else.)
    Also, when I try to use the BT speed tester, it tells me that 'Java is not installed/enabled on your P.C.'
    I am pretty sure I have ticked the right boxes on 'internet options', (under 'Tools',) but this doesn't work and even when I restart it says: 'restart required'.

    Thank you for your answer,
    I have, as you suggest, already tried removing all Java programmes and then uploading the latest version, that's probably why I'm in such a mess now.
    After I thought I had removed all version that were in my programme files, I attempted to upload the latest version, switching off the fire-wall first.
    But when I checked if it was working OK, it wasn't and I have been going round in a circle for hours re-loading etc.
    Plus I got the same message every time from the BT speedtester, which said 'you do not have java applets or they are not enabled' or something similar, but I did tick the 'enable' box in 'Internet Options' and ticked ''enable scripting' in the Internet Options / Security tag. But, try as I might, could not get the latest JRE files to load up and work right.
    Java script does seem to be working, although the Registry file is missing, but I had to download an earlier version to get it to work, (J2SE Runtime Environment 5.0 update 7. I think maybe one of the 'problems' is not being able to remove one Java programme which was on the computer since June, (Java(TM) 6 update 21.)
    I have tried to remove it several times but can't. ( I do have the 'administrator' rights.)
    I tried removing Java(TM) 6 update 21 again but i will not uninstall, although J2SE RE 5 update 7 has been removed now, I still can't get Java working and it's NOT showing in my programmes list at all, although Java(TM) 6 update 21 is showing in Control Panel programmes list!
    I usually get help from one of my Son's who are both in I.T. but both really busy. I have spent nearly two days now, trying to get Java working properly without much success.
    I am in a 'pickle', I don't know how to reinstate the Java Registry file for starters :( HELP!

  • AS Java applications not starting after patching from 2004s SPS10 to SPS11

    Hi folks,
    after patching our NetWeaver 2004s from SPS10 to SPS11 and the Kernel from 7.00.83.0 to 7.00.95.0, the applications on the AS Java do not start up automatically any more.
    Under the following URLs, the same error is shown:
    http://<fully qualified host name>:51000/
    http://<fully qualified host name>:51000/nwa
    http://<fully qualified host name>:51000/sap/monitoring/SystemInfo
    http://<fully qualified host name>:51000/useradmin/
    http://<fully qualified host name>:51000/wsnavigator
    http://<fully qualified host name>:51000/uddiclient
    503   Service Unavailable
    SAP J2EE Engine/7.00
    Application stopped.
    Details: You have requested an application that is currently stopped
    http://<fully qualified host name>:51000/webdynpro/welcome/Welcome.jsp
    itself works, the two links Content Administrator and Web Dynpro Console both lead to the same 503 error described above
    On http://<fully qualified host name>:51000/irj, the error message is different:
    com.sap.engine.services.deploy.container.ApplicationInManualStartUpException:
    Application sap.com/com.sap.portal.fpn.accessservice cannot be started because is in MANUAL start-up mode..
    Exception id: 09:33_09/05/07_0003_102709250
    See the details for the exception ID in the log file
    In std_server0.out we have the following entries, right after the list of all services that were started:
    ServiceManager started for 39904 ms.
    Framework started for 46720 ms.
    SAP J2EE Engine Version 7.00   PatchLevel is running!
    PatchLevel January 31, 2007 18:37 GMT
    May 9, 2007 9:40:19 AM  com.sap.portal.prt.sapj2ee.error [SAPEngine_Application_Thread[impl:3]_3] Fatal:
    The last line with com.sap.portal.prt.sapj2ee.error is listed another 131 times, and there is also the following message:
    ### Excluding compile:  com.sapportals.portal.prt.jndisupport.util.AbstractHierarchicalContext::lookup
    We can connect to the system using Visual Administrator. Under Server->Services->Deploy, most applications are not running. It is possible to start a few applications manually, others however do not start showing different exceptions.
    We have AS ABAP and AS Java installed, as well as BI, DI, EP and EPC. AS ABAP seems to be running fine.
    We have also noticed the following deviations in JSPM:
    BC_FES_IGS is Release 7.00 SP Level 7.0
    EP_BUILDT is Release 7.00 SP Level 10.0
    SAP_BUILDT is Release 7.00 SP Level 0.0
    All other components except for the Kernel are Release 7.00 SP Level 11.0 or 11.2
    What could be wrong, and what can we do to solve it?
    Best regards,
    Robert Schulte

    Thanks for your response, usha rani
    1. We already tried that, unfortunately, it does not help
    2. We checked the kernel version thoroughly after you suggested it, everything seems to be fine. We had a Unicode kernel before, and we still have one.
    3. safemode is already set to NO
    4. J2EE's default.trace is full of exceptions, but none of them is pointing me into a helpful direction.
    Perhaps the exceptions mean more to someone else:
    java.lang.Exception: Exception loading and instanciating sub-manager:
    com.sap.caf.km.repositorymanager.CAFSecurityManager
    (java.lang.ClassNotFoundException: com.sap.caf.km.repositorymanager.CAFSecurityManager)
    com.sapportals.wcm.repository.runtime.CmConfigurationProvider#
    sap.com/irj#com.sapportals.wcm.repository.runtime.CmConfigurationProvider.Component
    <SetRoomIdForDiscussionObjects> will not be available.
    Failed to load class
    <com.sap.netweaver.coll.room.impl.filter.DiscussionSetRoomIdPropertyFilterManager>
    #J2EE_GUEST#0####1e820b50fe4111db8e780013724175b4#SAPEngine_Application_Thread[impl:3]_22
    ##0#0#Error##Plain###
    java.lang.ClassNotFoundException:
    com.sap.netweaver.coll.room.impl.filter.DiscussionSetRoomIdPropertyFilterManager
    com.sap.portal.prt.runtime.broker#sap.com/irj#
    com.sap.portal.prt.runtime.broker#J2EE_GUEST#0####
    1e820b50fe4111db8e780013724175b4#SAPEngine_Application_Thread[impl:3]_22##0#0#
    Error#1#/System/Server#Java###
    [PortalServiceItem.startServices] service initialisation failed:
    tc.eu.odi.conn.uwl|OdiBridgeService
    [EXCEPTION]
    {0}#1#com.sapportals.portal.prt.core.broker.PortalServiceInstantiationException:
    Could not instantiate implementation class com.sap.tc.eu.odi.conn.uwl.OdiBridgeService
    of Portal Service tc.eu.odi.conn.uwl|OdiBridgeService because: could not load the service
    com.sap.engine.services.deploy.container.ApplicationInManualStartUpException:
    Application sap.com/com.sap.portal.fpn.accessservice cannot be started
    because is in MANUAL start-up mode.
    There are many more entries in default.trace.

  • Java Application not rocognized 3110c

    I downloaded a dictionary from the internet with jar extension.
    upon trying to run it, message appeared saying " Application not recognized"
    could you please elaborate the different types of java platforms and which one is supported o my phone Nokia 3110c, and how to identify the supported one ...
    Thanks in Advance

    http://www.forum.nokia.com/devices/3110_classic
    MIDP 2.0
    CLDC 1.1
    JSR 135 Mobile Media API
    JSR 172 Web Services API
    JSR 177 Security and Trust Services API
    JSR 184 Mobile 3D Graphics API
    JSR 185 JTWI
    JSR 205 Wireless Messaging API
    JSR 226 Scalable 2D Vector Graphics API
    JSR 75 FileConnection and PIM API
    JSR 82 Bluetooth API
    Nokia UI API

  • Moving blue bar across screen

    When I open different programs, this line comes up. Once I exit out of the program it goes away. But will stay up the whole time I have the program open. it moves back and forth like a scanner. Just started a couple days ago. Have had the ipad for 3 months.

    Go to Settings -> General -> Accessibility . Scroll down, In section Physical &amp ->motor,set the Switch Control to OFF. It will take care of it

  • HELP!  just a b & w screen with "do not disconnect" and restore doesnt work

    i dont know whats wrong with my ipod, its just got a b & w version of the normal "do not connect" screen, even when iTunes hasnt recognised it being plugged in, and if i reset it, it just has that folder picture, and the aple.com/support/ipod thing on the screen, before going back to the "do not disconnect" again in black and white. and restore doesnt work, it just says some error, and quits. Does anyone have any idea whats wrong? thanks
    (its a 5th gen ipod with video, which should be colour)
    Windows XP

    Same thing here!!

Maybe you are looking for

  • Error during testing Application Module in JDeveloper 11.1.1 Tech Preview 3

    I am successfully using Jdeveloper 10.1.3 version now i am trying to use new JDeveloper version 11.1.1 but i am initially get this error while i am trying to test my buisness components. When i test my buisness components first time i got this error

  • MERGE w/ conditional Insert clause

    Hi-- Sum Up:Is it possible to run Merge syntax with update and a conditional Insert clauses ? Question Details Have a base table Emp and staging table New_Emp with a common identifier Emp_id. The ideal would be to merge the 2 tables and update Emp us

  • Connectivity Details

    Hi All, We are using Crystal Reports 11.5.3 in windows 7(64 bit) environment. At the same time we are using Oracle 11G Client (64bit). 1) Could anyone let us know is this compatible with the windows 7 64 bit environment? 2) We are able to create the

  • How do i imported downloaded packages ?

    Hi all I'm using NetBeans 4.1, and i've downloaded a few packages from the net, but i've no idea how to get them to be imported. I've downloaded them, unzipped, and saved into a directory, and the classes i need to use are on a JAR file. i do the imp

  • OPtion 3 speed dropped to under 1Mbps

    I test my connection speed regulalry and get about 10Mbps from my Option 3 package. However, for the last 3 days I have been getting under 1Mbps at all times of the day. How can I get this fixed? Thanks Bob