I am new to this GUI stuff on NetBeans, so could someone please explain how to link multiple GUIs into one? This I should mention is in a java format.
If you want to open another gui from a specific gui, you should give an event to a button.
For example, if you want to open anothergui from maingui, you can create an event for a button which says anothergui is new anothergui, then you can set visibility true for anothergui.
Related
I hope everyone is doing well.
I've built a hangman game with a swing gui and everything works well enough, HOWEVER I am trying to make a popup show up by constructing a new JFrame object when the user wins or loses with a "you lose" message or what have you. No problem, but I want a specific window to close when activating the button listener on the popup, or when the 'x' is clicked. Assume my program has 3 windows up, and I only want to close 2 of them with one click.
I tried stuff in the area of
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
But that specific one closes all the windows. If you want to see more specific sample code, I would happy to provide it, but it didn't seem necessary for this question.
Either way, I can't figure out how to do this. Is this possible using Swing?
Thank you so much in advance. You guys are always so helpful.
I have a JFrame with three text fields, two combo boxes and two Jbuttons. The coding is written in Java. One button is to start the execution of the automation script and another button is to abort the execution.
But after clicking on Start Execution button, I am unable to click on the second button and unable to edit other fields like text fields, combo boxes in the JFrame also.
As this is my project related I cannot post my code here. I apologise for that. I hope you can understand the logic or concept behind my problem. I have done a lot of search in internet but still no progress.
Please help me with this. I am using action listener behind the two Jbuttons.
The Event Dispaching Thread (EDT) should only and only do graphic related work. Any other work should be done in another thread (see SwingWorker).
Every event generated by swing, will run in the EDT, this includes actionPerformed()
That is happen because of the code implement you in the first button is continuously running , use java thread to do that stuff in the first button code. then that will be works fine.
I am developing a simple swing application and I would like to have something which can help user with it.
As example a little popup window will appear over "Start" button when user runs app first time and say "Hey, click here to start playing with me!"
Do you know the way to create something like quick doc in Intellij Idea?
Could you please put me on the right way to sources, examples, source codes or anything else which could be useful?
Below is example of how it can look like
PS. I have updated the picture.
As I said in the comment use javax.swing.PopupFactory to show popup for any component (which is probably not pointed by the mouse)
Popup p = PopupFactory.getSharedInstance().getPopup(component, new JLabel("It's a hint!"), 5, 5);
p.show();
component is the widget for which the popup must be shown.
You can also use the javax.swing.Timer to hide this popup automatically.
Tooltips are used in Swing to give the hover-over text that you are looking for. It is very easy to use a tooltip, all you have to do is set the tooltip text on your button
btnStart.setToolTipText("Hey, click here to start playing with me!");
Here is a pretty useful guide that explains the topic in more depth http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html
I have a question.
I just started with Java and may have some small basic things. Now I wonder how a kind of pages (sections) in a program makes.
I do not mean some kind of tabbed panel, or if you click on a button that a text is visible.
I mean that for example all over the screen a separate part of the program looks. As the main menu of a game.
There is nothing else than the main menu visible at that time. If you for example a button from that menu click. The game is loading.
(I'm using the building of a standard game as an example)
If you for example the main menu click on another button (eg "Settings")
Then wort settings "page" is visible, and there is nothing else that the program is really doing.
I do not know how this type of navigation is called. But almost every program does have something.
How can I do this too? What should I do for example, as a new file, import the classes of a particular page, or something?
You seem to be searching for CardLayout. As shown here.
I think you should look for "state machines", which is a way for structuring your code, and implement your menu changing swing components (like JPanel, for example) in a JFrame. If I understand what you want, I think this can be an option.
There is no short answer, but based on your question, you need to read alot. I would suggest the swing tutorial It explains use of Panels, Frames, Layout managers and other containers.
You can also use the Matisse builder in netbeans (relevant plugin in eclipse)
Hi all:
I have a Java Swing App. There is a button allow user to create open up a new window of the application. I use System.Exit(0) when user decides to close the application, however when I press "Close" button, both Application windows closed.
public static void main(String[] args)
{
ghMain = new GreenHouseMain();
}
Above is how I initialize the first application, then use the same code to create new GreenHouseMain Object to open second application window.
So my question is how do I close only one application window which the close button I pressed from?
Thanks all
call dispose() instead of System.exit() on the Window object that you want to close. When there are no more visible windows, the Event Dispatch thread will exit.
I assume that both windows are JFrames. If so, it is better to have the second window be a JDialog, modal or non-modal depending on your requirements. If you need both windows open and want to be able to let the user select which to close, then perhaps both need to be dialogs, though I'm not 100% sure based on the information you've presented. If these suggestions don't solve your problem, then please provide us with more details on your exact requirements.
read the javadocs for setDefaultCloseOperation. System.exit() is doing exactly what it's supposed to, so get rid of it.