• Post Reply Bookmark Topic Watch Topic
  • New Topic

paint and text areas on same screen

 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a simple platform game and everything works fine with paint and double buffering. I now need a text area and a couple of buttons to appear on screen that allow the user to enter text (actually a little language that defines the platform layout). I haven't used any text input methods before and I'm not even sure if Java allows you to have a playable game one moment and then, on clicking a button, popup a text area and a couple of buttons. When the user is done I'd like to make the text area and most of the buttons disappear so the user can continue playing. I've tried JtextAreas and JButtons but they either don't appear or appear but refuse to disappear or they only appear if the mouse happens to move over that part of the screen.

Is this possible? and can anyone describe what I need to do in such a way I might be able to understand it?

Mike
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your best bet would be to use a dialog to capture the user input. More about it here http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

I think this question would be more suitable on the UI forum. Moving..
 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response!

The idea of a popup window would work great but I've looked through that link and it only seems to offer tiny dialogues though one of the options would input a line of text if it's param was null but I couldn't see how I could input a text area.
I'm really after something like 80 columns by 20 rows (preferably scrollable) with a couple of buttons.
Did I miss something in there?

Mike

EDIT:

I managed to work it out! I used a mouse listener to activate the popup. Then used the JTextArea for the input area and then added a scrollable "thing" to that.

This means I'll soon be able to let others try out my little language for platform games. I don't have many illusions here but perhaps someone might try to write a screen or two.
Thanks for your help.
Mike
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done!
If you noticed, the JOptionPane.showXXXDialog accepts an Object message. Like you have done you can pass anything as a 'message' including a panel with nested layouts and complex component hierarchy if required.

Since you have been gracious enough to share your solution, you just earned a cow! Moo!
 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing as I've earned a cow I'll give you the current code which is slightly different in that it now shows custom options. You need to implement MouseListener to use this. The variable Program just contains the users program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!