Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea question - accessing and code structure

 
James Ferrara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First: I'm new to this. I've searched around a bit but think a human might be able to answer my question better than the search engines so far.

So I understand that you create a class representing your GUI, add a bunch of controls to it, then start running it. My question is twofold: one relates to structure, one relates to how to access a text box.

So here's the code:


Here are the questions:
1. Let's say I want to open a file and input all the contents into the JTextArea "txtBox". How do I access that control to add text to it?
2. Where should I do that? To clarify: what method should I add or utilize to do that. I don't think it should be in the constructor JCheck() if I insert multiple files - should I create another function to do this? And where should I call it from? The run() function?

I know these are fairly entry level questions but I'd like to set myself straight before I start writing poorly formed Java code and any references you can point me to would be awesome too.

Thanks for your time!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it really your intention to waste everyone's time by encouraging duplicate responses?

http://www.java-forums.org/awt-swing/31852-accessing-jtextarea-after-creation-intro-level-question.html
 
James Ferrara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am maximizing the responses by double posting, yes.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I am maximizing the responses by double posting, yes.

double posting is fine, provided you include a link to the other post so everyone can see what's already been suggested/tried.

without the link, people like me (who read multiple forums) will just add you to a personal ignore list, so your
attempt at 'maximizing the responses' has the reverse effect.
 
James Ferrara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies. In the future I will do so.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:is it really your intention to waste everyone's time by encouraging duplicate responses?

http://www.java-forums.org/awt-swing/31852-accessing-jtextarea-after-creation-intro-level-question.html

Michael, thanks for the heads-up.
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
James Ferrara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Thanks Michael.

James,
Please read http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites


Speaking of redundancy, you should read my apology above.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you followed/understood the suggestions given at java-forums?

did they work, or do you still have a problem?

if still a problem, let us know what you've tried and what happened vs what you expected to happen

> before I start writing poorly formed Java code

one thing not mentioned yet is extending a component (JFrame), just for the sake of extending it.
google 'Composition vs Inheritance' for detailed explanations
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic