Hi i have a quick question. If i have a java application are their any third party applications that can help me run it on an html website without porting it to a JApplet.

Recommended Answers

All 10 Replies

It would be fairly easy to rewrite the application to run as an applet. Put the GUI and code into a panel that could be either added to a JFrame for the application or to a JApplet for the applet.
Any file I/O would have to be changed. But that would always be true.

The problem is the imageas do not show up. Does an applet abide to specific methods. And what do you mean by GUI i know its graphics user interface but are u specifically referring to Layout MAnager, Jpanel, etc. I did that adn again as i said evrything shows up except for the images i set for the program.

You need to handle image files as resources not as disk files. Use the getResources methods and put the images on the classpath. Normally that would be in a jar file.
The GUI would be what you see on the screen.

so basically its a compatibility issue with japplets

what do you mean by resources and not disk files. I have all the images stored in a folder under the my eclipse package folder. and i call the images with "x = new ImageIcon("...");"

See the getResource methods in the API doc to see how they work.
They return a value that can be used to read the contents of an image file.
There are lots of code samples on the forum if you do a search.

ould you throw a quick line of code using the getResource method please.

So far I tried this:

URL myurl = this.getClass().getResource("res/cell.png");
        Toolkit tk = this.getToolkit();
        tileset_res[0] = tk.getImage(myurl);

and its not working...

i used to use:

tileset_res[0] = new ImageIcon("res/cell.png").getImage();

And I found something else out. Under jdk 7 theres a methods called: Load Scanner.

Heres the class i used for it:

import java.io.*;
import java.util.*;

public class Save {
    public void loadSave(File loadPath){
        try{
            Scanner loadScanner = new Scanner(loadPath);

            while(loadScanner.hasNext()){
                Screen.killsToWin = loadScanner.nextInt();

                for(int y = 0; y < Screen.room.block.length; y++){
                    for(int x = 0; x < Screen.room.block[0].length; x++){
                        Screen.room.block[y][x].groundID = loadScanner.nextInt();
                    }                   
                }

                for(int y = 0; y < Screen.room.block.length; y++){
                    for(int x = 0; x < Screen.room.block[0].length; x++){
                        Screen.room.block[y][x].airID = loadScanner.nextInt();
                    }                   
                }
            }

            loadScanner.close();
        }catch(Exception e) {}
    }
}

And I have it read files like this i create and have it place pictures according the numbers.:

10

0  0  0  0  0  0  0  0  0  0  0  0
1  1  1  0  1  1  1  1  1  1  1  0
0  0  1  0  1  0  0  0  0  0  1  0
0  0  1  0  1  1  1  1  0  0  1  0
0  0  1  0  0  0  0  1  0  0  1  0
0  0  1  0  0  0  0  1  0  0  1  0
0  0  1  1  1  1  1  1  0  0  1  1
0  0  0  0  0  0  0  0  0  0  0  0

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Obviously it works when the program is a normal java application but its not working when its a JApplet as its unable to read it for some reason.

Applets are restricted in the I/O they can do. They often can not read from a PC's disk.
Try putting the file you want to read in the jar file and using the getResources methods to read the file. Did you try searching on the forum for sample code that uses getResource?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.