Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  About text output  (Read 2642 times)
0 Members and 1 Guest are viewing this topic.
Offline Sammyster

Senior Newbie

Medals: 1
Exp: 3 years

« Posted 2012-04-08 14:00:37 »

Hello JGO!

Registred at your site today, Have to say that I love your registration process, best one i've seen so far Wink

So I've just started to work on my first game project a few weeks ago.It's nothing fancy just for me to learn how game makeing works and have a bit of fun.
Choosed to try and clone a old Star Trek game I played long ago(Forgotten it's name of course Sad).
I remember it as a semi-text based game where you travel your ship to various planets on a map,constantly keeping an eye on fuel levels and supplies, and of course for any nasty klingon that might show up.
Everything has been going really well so far, sorted out some basic collision detection,ship movement and running it on a thread. But I'm not so happy about the GUI yet.
But it's a big thing I haven't gotten working yet and didnt find anything usefull on google either so I though I could ask you guys here for some expert help Smiley

So what I want to do is updating a JTextArea with all the text from my game, for example when my ship collide with planet 101 I want it to output my welcome message for that specific planet and so on.
I tried to do it simple with the "setText" method, but i only got that to work from inside the same class where my JTextArea was, and it didnt update the text at all just overwrite it with the next line.
So yeah, any help on how to update my game text would be very appreciated!

Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2012-04-09 01:24:07 »

Looks like your Google-Fu was off a little: Wink

Offline theagentd
« Reply #2 - Posted 2012-04-09 03:28:54 »

setText(getText() + theNewLine)?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-04-09 03:37:39 »

Try to not mix swing in your game. Build your own class which is able to render string and warp them. It's painful but worth it.

Offline Sammyster

Senior Newbie

Medals: 1
Exp: 3 years

« Reply #4 - Posted 2012-04-10 17:48:32 »

Thanks guys, finally got it working.
If I should'nt mix swing into my game I've done a quite big misstake now as most of my game is based on it,
but will look into an own rendering class. Will be very painfull and very time consumeing for a noob like me i'm sure!

And yes my google-fu will always be a bit off  Wink
Offline BoBear2681

JGO Coder

Medals: 19

« Reply #5 - Posted 2012-04-10 18:13:03 »

setText(getText() + theNewLine)?

Even though the OP will probably move away from Swing, just for completeness I'd recommend using JTextArea.append(text) rather than the approach above.  A little cleaner, not to mention teh more efficient!!!1

Why they added that method (and insert()) to JTextArea and not JTextComponent is beyond me.  You shouldn't have to resort to modifying the Document or replaceSelection() to do standard text operations efficiently.  Ah well.
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (27 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (210 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (779 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!