I have been playing around with trying to get a menu screen for my game. I have only been able to figure out how to paint a new Screen on top of an existing one; meaning that the actual game is still running behind the title screen. I don't need actual code but just a description of how I would go about this.
One way to display a menu would by by using a JDialog outside of your main application window. Take a look at the How to Make Dialogs tutorial for more information.
Another possibility would be to use JInternalFrame for your game and menu so they can be wrapped in a larger application frame. These are explained nicely in How to Use Internal Frames
Related
I want to simulate basic input for a swing application. The whole thing runs headless and doesn't even have a JFrame. I just render all components from the JPanel using the draw() method on a Image (If you want to know why: The Image gets rendered on minecraft maps where users then should be able to interact). I want to execute click or scroll actions on the panel like it would come from regular user.
I know that I can simulate a Button click using doClick() but this doesn't work for components like checkboxes. I also tried using dispatchEvent() but that didn't fire the animations or on some components even threw a HeadlessException.
I'm currently developing the menu of my application and I would like to know what's the proper way of coding a "stage based menu". What I mean by stage based menu is that, user clicks a button, the entire interface changes to the next "stage". Here are the pictures I designed in Photoshop in order to explain my idea:
First picture would be the first stage and the second picture the second.
Each round looking thing is a JButton
So far I got the main menu (fist picture) made on eclipse using WindowBuilder, made it as a JPanel and then I instantiate it on the window class.
My idea was to have an event listener listen for clicks on each button and then once the even is triggered, have the JPanel variable on the frame change to the next "stage". So I was wondering if this is actually the proper way of doing this or are there any better ways?
You could use a Card Layout to make it easy to swap panels.
Check out the section from the Swing tutorial on How to Use Card Layout for more information and examples.
I had started working on a java based tool that my friend has developed. Now we are working on it together. He has used custom made jpanels and used them in jtabed pane like fashion. Its something like this,(check the link for the screen shot,since i am new user,i cannot post images here)
https://www.dropbox.com/s/5wnrmxiraywlg7p/tab2.png
The problem is that,we want to implement a browser like display of tabs,when the number of tabs opened is more that the panels widths,it gets hided.so the idea is to develop a left and right brows tab buttons tats similar to web broswer .how this could b achieved?
More info about the current layout and design:
The canvas panels are created and tab panels are created and finally called in the main display panel. The stagetab panel holds the tab panels(which mimics appearances of the tabbed pane). Also there already functions to display various canvas panel(different tabs) based on user pressing the tab panels.so all those are working well. have been looking on various solutions for this problem.one sch is developing an custom view port like method similar to jscroll pane which could be used here.
What would be the better way to do this?
A good possibility would be to use SCROLL_TAB_LAYOUT as tabLayoutPolicy. This will show two arrows at the corner of the JTabbedPane. Of course you could redesign the component to show it as you want.
You can find an image of a table using it here.
I am trying to build a user alert mechanism by bringing up the window to the front and then flashing the icon on the screen for the user. I have two questions with regards to this approach:
How can you find the current window you are at in Java and then de-minimize it and bring to front?
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
Thanks a lot for any replies.
How can you find the current window you are at in Java and then de-minimize it and bring to front
Window[] allWindows = Window.getWindows();
returns arrays of all Top-Level Containers from current JVM e.g. J/Frame, J/Dialog(JOptionPane), J/Window,
you can to test for (example) if (allWindows[i] instanceof JFrame) {
then WindowState returned WindowEvent
by bringing up the window to the front and then flashing the icon on the screen for the user
use undecodated JDialog (works toFront, toBack) with
create only once time
setDefaultCloseOperations(HIDE_ON_CLOSE)
use Swing Timer for hide JDialog
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
have look at Java Translucent Window, put there Icon to the JLabel (or to the JButton)
use Swing Timer for flashing by hiding Icon or swithing bewtween two or more Icons (three or four is good)
I think the simplest way to get the window ancestor is :
SwingUtilities.getWindowAncestor(yourComponent);
I already designed many JPanel's for my application in Netbeans now i want to ..
Add background images to all jpanel's in which i had some jcomponents already.
And i want it to do it for jdialog too.
I need to design a JMenu with images and menu name.
But already i saw many examples for background images in that they are adding there components through coding im doing it in Netbeans.Is it possible to set it for the main JFrame then i can leave the jpanel's.
If you use netbeans background image can be added using a simple method. I don't know whether it is a good practice, but it is really easy. See this video.