Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Loading Source Code into a JFrame in an Applet

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brendan Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic