This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes Loading Source Code into a JFrame in an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Loading Source Code into a JFrame in an Applet" Watch "Loading Source Code into a JFrame in an Applet" New topic
Author

Loading Source Code into a JFrame in an Applet

Brendan Thompson
Greenhorn

Joined: Apr 27, 2012
Posts: 21
Beginner question here:
Create an applet that loads its own source code in a JFrame.

Sounds weird to me. Is there some sort of method that does this? All I can think of is copying the source code into a txt file and then reading from that.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Why copy? You can read a .java file just as easily as a .txt.

I would hazard a guess that what the assignment's really looking for is your ability to locate and access a file based on the running class's name and package structure. Always assuming that the .class and .java are located in the same folder, under the package root (if there's a package statement).

Also note that you don't
Create an applet that loads its own source code in a JFrame.

You display the contents of a text file (yes, a .java file is a text file) in an appropriate JTextComponent which is shown in a JFrame.

I don't see why an Applet should come into the mix, unless part of the test is to launch a JFrame from an Applet.


luck, db
There are no new questions, but there may be new answers.
Brendan Thompson
Greenhorn

Joined: Apr 27, 2012
Posts: 21
Thanks for the advice on readi.g .java files. And the use of an applet is just to get familiar with creating and implementing them.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Loading Source Code into a JFrame in an Applet
 
Similar Threads
Applet InvocationTargetException
JFrame vs JApplet
My *stupid* questions...
set the background panel to an jpeg and display text in front of it
Can't accept parameters from an applet