?
Solved

Applet using my .class file

Posted on 2003-02-23
13
Medium Priority
?
171 Views
Last Modified: 2013-11-23
Okay I created a class which is a standalone program which downloads and parses a file for certain items.

Downloader d = new Downloader();
d.download();
d.getdata();
d.gettime()

Are some of the functions it has. I made a separate standalone program to test it and that works fine. I tried creating an applet which uses an instance of the standalone class file but its reporting notinited. I assume this is because I can't call a standalone app? If anyone has a workaround to being able to use my own class inside an applet. OR downloading a URL from within an Applet (to either a local file or a vector of strings). Either answer solves this problem.. OR how I can use the .class successfully thru a javascript (.js) page (haven't had ANY luck with this). Thanks
0
Comment
Question by:mayhem4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8007185
 You shouldn't have problems instantiatign a standalone class from applet. What exactly is the problem? Do you have the standalone class in the same folder with applet or in the same jar file?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8007597
The file that the application parses would have to be in the applet's codebase and should be accessed without instantiating File.
0
 

Author Comment

by:mayhem4
ID: 8010775
Quote:The file that the application parses would have to be in the applet's codebase and should be accessed without instantiating File.

Can you elaborate a little? They are both in the same folder ... I haven't made them a jar file, and would prefer not to.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 86

Expert Comment

by:CEHJ
ID: 8010914
>>They are both in the same folder

OK. How are you going to get the file into the application for parsing?
0
 

Author Comment

by:mayhem4
ID: 8010938
Could the problem be I never used classloader in my applet :\ Looking into that now :(
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8010992
No reason to use a classloader particularly.
0
 

Author Comment

by:mayhem4
ID: 8014637
If you could throw up a sample .class and an applet which uses the functions and creates a type of that classtype, I could most likely figure the rest out. I'd accept any answer that teaches me how to create a variable of my classtype. :)
0
 
LVL 35

Accepted Solution

by:
girionis earned 1100 total points
ID: 8015264
 Try this:

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class AddsApplet extends Applet
{
     SampleClass sc = new SampleClass();
     
     public void init()
     {
          System.out.println(sc.getAd());
     }
     
    public void start()
    {
    }

    public void stop()
    {
    }

    public void destroy()
    {
    }
}

  and your class:

public class SampleClass
{
     public String getAd()
     {
          return "an ad";
     }
}

  Have both the applet class and the SampleClass on the same folder of your web application. When you load the applet in the browser you should see the string "an ad" on the console window.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8015813
And what about the

>>d.getdata();


stuff?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8015842
 It's just some sample code to show how to create an instance from within an applet.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8015862
No, my remark is really addressed to mayhem4, as that area of the program is potentially problematic in an applet.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8015990
 I think he would help us more if he could tell us the exact error message. Applet not initialized is a generic error that can be caused by dseveral factors.

  Mayhem4 what does the java console say when it fails to initalize the applet?
0
 

Author Comment

by:mayhem4
ID: 8046597
Well I've given up on the script but heres the points and a good grade for tryin. :P
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question