Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Applet using my .class file

Posted on 2003-02-23
13
Medium Priority
?
172 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

564 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