Win a copy of Serverless Applications with Node.js this week in the NodeJS 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Best way to display hidden game console  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0


Hi I'm trying to create a game console for developer tools. I want to be able to toggle its visibility with a key press, from what I've read, tell me if I'm wrong, I should use key binding and i should make the console a JDialog not Jframe.

So I created the JFrame game window, and create a JPanel game canvas inside of it, then the JDialog console inside that, with the visibility set false.

Inside the gamecanvas, I also create an instance of the class ShowConsole which extends AbstractAction, and is passed the console object, which the constructor assigns to a local variable to work with, and the action performed being to setVisibilty of console to true.

Then I use getInputMap to map the home key to an action name, then use getActionMap to map the action name to the ShowConsole action object.

Now somebody has said that I'm going to need to place another key binding inside the console in order to rehide it when it has focus, but I can't even get it to display in the first place, unless I have it created with visibility true.

This tells me it's being created and the problem must be with the key binding or action, though no errors are displaying, can somebody explain what I'm missing or if there is a better way...

__________________________________________________


__________________________________________

 

__________________________________________

 
 
Marshal
Posts: 63823
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you calling setVisible()?

And welcome to the Ranch
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where are you calling setVisible()?

And welcome to the Ranch



I'm calling it in the ShowConsole action, which I create an instance of in gamecanvas, and use in getActionMap to bind to home key.
 
Campbell Ritchie
Marshal
Posts: 63823
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call setVieible(true); last, after everything has been added.
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Call setVieible(true); last, after everything has been added.



How so, could you explain? I have it inside the ShowConsole action I create in gamecanvas along with the console, and pass the console to it so it can access console.setVisible():

Maybe are you saying I should wait until after the key binding to create the instance of the action?
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where are you calling setVisible()?

And welcome to the Ranch [/q

It's also called in console's constructor when it's created, to set the initial value to false to hide it until i want it visible.

 
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a lot of classes that I don't recognize there. Canvas? If that's the AWT Canvas class then you should be using JPanel as a generic panel thing. Or is it a JavaFX class? And Console? Is that your JDialog descendant?

As for what's going on or not going on, I'd recommend doing some debugging so that you can see whether pressing the Home key actually causes any of your code to be executed.
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:There's a lot of classes that I don't recognize there. Canvas? If that's the AWT Canvas class then you should be using JPanel as a generic panel thing. Or is it a JavaFX class? And Console? Is that your JDialog descendant?

As for what's going on or not going on, I'd recommend doing some debugging so that you can see whether pressing the Home key actually causes any of your code to be executed.



I created the Canvas class which extends Jpanel:



And yes console extends JDialog:



And I think the problem is with the key binding but I can't figure out why.
 
Paul Clapham
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code seems to suggest that when you press the Home key, line 14 of the ShowConsole class gets control. Does that happen or not?
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Your code seems to suggest that when you press the Home key, line 14 of the ShowConsole class gets control. Does that happen or not?


Exactly, that's what's supposed to happen, but it's not and that's where I'm stuck.
 
Paul Clapham
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Like Campbell already said, "Call setVisible(true); last, after everything has been added."
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Like Campbell already said, "Call setVisible(true); last, after everything has been added."



That setVisible is for the JFrame gamewindow, not the JDialog console, but I did move it to after adding gamecanvas, so it's last in gamewindow, and still nothing.
 
Paul Clapham
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So now it's time to put that code aside, and write an SSCCE (<-- follow that link) which gets key-binding working. Once you know how to do that, you can then retrofit the working code into the code you posted.
 
Michael Coster
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Okay. So now it's time to put that code aside, and write an SSCCE (<-- follow that link) which gets key-binding working. Once you know how to do that, you can then retrofit the working code into the code you posted.



Lol that's what I was trying to do, I already cut out a ton, but I could simplify it some more, I had also tried using the key binding to simply create a new JDialog, but I thought it might be relevant to include that i was trying to use it to control an attribute of a separate container not the current the current one.

Is there any way to edit my post if I want to simplify it more, or update with changes, or should I just create a new topic?
And I was reading about SSCCE's and what exactly do they mean by demote all classes to default?
 
Paul Clapham
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Coster wrote:Lol that's what I was trying to do, I already cut out a ton, but I could simplify it some more...



You sure could. An SSCCE would look more like a single JPanel with a key binding which does something trivial like changing the background colour.
 
Paul Clapham
Sheriff
Posts: 24291
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Coster wrote:Is there any way to edit my post if I want to simplify it more, or update with changes, or should I just create a new topic?



My suggestion would be to just carry on with this thread.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!