Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2004

Tip: Looking for answers? Try searching our database.

Applet + Swing basic (very basic!)

Thread view: 
Chris - 16 Dec 2004 02:42 GMT
Hi,

I'm a total newbie to Java (forced into it via a master's class, actually,
but enjoying it!).  I've scoured my Java books and the web for what I'm sure
is very simple stuff but am coming up blank.

Basic premise: build an applet that has a JTextArea in which to display some
simple lines of text as the applet runs.  Using JBuilder Foundation I'm able
to build the GUI in the init() method and am hacking my way through learning
what all the auto-generated code means.  As a Delphi guy, it's slowly making
sense.

My applet has multiple custom classes, each in their own .java file, that
need to be able to write to the JTextArea.  But I can't for the life of me
figure out how to reference that component or write to it in classes other
than the main class that extends applet.

In Delphi I'd simply add the main class that contains the JTextArea to the
'uses' clause of other classes, but I don't know the equivalent
functionality in java.  Can anyone tell me the basic concept, or where in
the Sun or JBuilder docs to find it?  I'm stumped.

Thanks,

Chris
Andrew Thompson - 16 Dec 2004 03:11 GMT
> I'm a total newbie ...

[1]

>..to Java (forced into it via a master's class, actually,
> but enjoying it!).  I've scoured my Java books and the web for what I'm sure
> is very simple stuff but am coming up blank.
>
> Basic premise: build an applet

Why an applet?  [1] That is not a good place to start
if you are new to Java
<http://www.physci.org/codes/javafaq.jsp#appfirst>

>..that has a JTextArea ..

Why a JTextArea specifically?  Has it got something that
an Applet or HTML TextArea does not?

What does your applet (supposed to) do?

>..in which to display some
> simple lines of text as the applet runs.  Using JBuilder Foundation

Oh-oh.  There's trouble.
<http://www.xdweb.net/~dibblego/java/faq/answers.html#Q34>

You need to learn how to code Java before you let an advanced
IDE like JBuilder mess it up with it's ..what do they call it..
XYLayout, or AbsoluteLayout?

>...I'm able
> to build the GUI in the init() method and am hacking my way through learning
> what all the auto-generated code means.  

Toss it and add your text area (with scrollpane if necessary)
to the CENTER of a BorderLayout.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

klynn47@comcast.net - 16 Dec 2004 04:01 GMT
Do you have a reference to the different classes as instance variables
in your applet?
Lee Weiner - 16 Dec 2004 05:34 GMT
>Basic premise: build an applet that has a JTextArea in which to display some
>simple lines of text as the applet runs.  Using JBuilder Foundation I'm able
[quoted text clipped - 6 lines]
>figure out how to reference that component or write to it in classes other
>than the main class that extends applet.

I assume you're creating instances of your "custom classes" inside the applet
class.  If so, pass a reference to the JTextArea in the constructors of those
classes.

Lee Weiner
lee AT leeweiner DOT org


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.