Synchronization between two classes [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have created a GUI window is being called in the main method of another class. The window has a run button. The control should return to the main method only afterthe run button has been clicked. How do i get this functionality? Should i use threads?

What you're describing is the classic behavior of a modal dialog such as a JOptionPane: program flow from the calling code pauses while the modal dialog is displayed and then returns at the calling spot when the modal dialog is no longer visible.
I suggest that you look into using a JOptionPane since this is usually the simplest way to get this behavior. Please understand that JOptionPanes can display complex GUI's since the second parameter of its showXXX(...) method is of Object type and can be a JPanel that is laden with other JPanels, components, and goodies.
For example, please look at the code from the answer to this question: How can I make a JFrame modal like a JOptionPane?
Edit
You state in comment:
can i make a JOptionPane from a JFrame? i made a JFrame with three file choosers and 3 text fields and a run button.can i make a JOptionPane from this JFrame direclty?
#Alvin: now you're learning why you should not be gearing your code towards creating JFrames -- you end up painting yourself in a corner. I suggest that you re-do that little bit of code and instead create a JPanel. Then you can put it into a JOptionPane, a JDialog, or JFrame or whatever the need dictates.

Related

Netbeans GUI programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am currently in Gr 12 and recently we received a assessment task. The task asks us to create GUI screens and then code everything behind it. Problem is that our teacher never explained to us how to code GUI screens and since exams are approaching, she won't really help us. I created the GUI screens in Netbeans using JFrame forms. From there on out, I am lost. I am using a text file to read from and I know how to code an array, display and basic class. I need help though because I don't even know where to start. If someone can help me, it would be greatly appreciated. Even if we need to talk about it more somewhere. Thank you
Create a new project in NetBeans
and then create JForm by
then select design from toolbar
now drag and drop elements from palette
click on button properties then choose ActionPerformed
this code will generates in source code write code there
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

How to make a program to sleep until my Thread ends? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Inside a JFrame class, I start one Thread. That thread checks something and return a boolean as true or false. Inside the JFrame class I want to check that boolean, and do actions according to the results of the thread.
Now my question is how can I make my JFrame to wait untill the Thread ends?
How to make a program to sleep until my Thread ends ? I dont wanna to use Thread.join(). Is it possible?
I am interacting with the user in another window.
Make the second window a modal dialog such as either a JOptionPane or a modal JDialog. Either one will freeze the calling window until the dialog window is no longer visible. Please check out this question for more on this, as well as these questions for a lot more on this.

Adding a window to another window internally [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I was wondering is it possible to add a window to another window? Like can you add that window, like an internal frame to another window. The reason why I am asking this is because I want the image window (which is produced by ImageJ) to be displayed in a desktop frame or window. Also how would you go about doing this. Thanks in advance.
You can call the getContentPane() method of a JFrame, or more generally the getComponents() method of Container (e.g., in the case of java.awt.Frame or java.awt.Dialog windows) and then set it as the content pane of a JInternalFrame.

Two window interface in java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to design the interface of a chess game, such that the chess game is within the internal frame(window) and the external frame should have a file and settings menu bar and a background image only.
The user should use new game, save game , and undo from the file(menu bar). I have written the game code but cannot figure out that type of interface. Can anybody here help me how to figure it out? I appreciate any help.
Add a JDesktopPane to the MainFrame. You can add a background to it.
Use a JInternalFrame for gameboard frame.
When use click new game from the JMenuItem, an actionPerformed should add the JInternalFrame to the JDesktopPane and make the JInternalFrame visible
If you don't understand how to create an interface at all, you should take a look at the Swing tutorials
Specifically, have a look at
How to Make Frames
How to Use Internal Frames
How to use DesktopPane
How to use Menus
How to write listeners.
If you understand the above fore-mentioned things, an you want a quick solution, look into a GUI Builder tool like Netbeans GUI Builder. If you don't understand the above concepts, I suggest you learn to hand code before working with auto-generated code, as it might overwhelm you.
One way is for the external frame/JFrame to keep a reference to the internal JFrame, and in the external frame's ActionListeners, you can then call upon the internal/game frame's public getters, setters and various methods to change the game's settings or read the current game state. Figuring out the details of how to do this is the fun part!

using breadcrumb in Swing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am working on a project where user faces 5 frames . Each frame contains the data to be filled . so when he completes the one frame and goes to next frame it has to confirm that the data is filled for that I want to use BreadCrumb(or progressbar).
so how to create a BreadCrumb(or progressbar) in java swings
I want to make similar to below image in java swings
I suggest that you
create 5 images to use as your breadcrumb images. Any basic image editing program can help you with this.
Put the 5 images in ImageIcons, and put the ImageIcons in either an array or an ArrayList<ImageIcon>.
Display the current Icon in a JLabel that is part of your GUI. You can easily set the JLabel's Icon via its setIcon(Icon icon) method.
I would strongly urge you not to use "5 frames" since that is an irksome user experience and is not what the user experiences when using a professional application.
Instead create 5 JPanels that handle each part of the process.
Swap these JPanels in and out of your GUI via a CardLayout-using JPanel, one that I assume will sit on top of the JLabel that displays your breadcrumb ImageIcons.
When you swap a JPanel view, you also swap an ImageIcon. This swapping will likely be done in the same method.
Remember that it is Java "Swing", not "swings". Good luck.

Categories