Two window interface in java? [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 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!

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:
}

Create clickable graphics 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 create a simple cad-like java application.
In it there will be a Jframe in which I want to have my shapes. Those shapes will be circles and lines. Also some text will be placed. There will be up to some thousands circles, so speed is an issue. Also the shapes will have to be redrawn all the time (for example for zoom-in etc). Those shapes apart from the "standard" properties of their class I want them to have extra properties declared with new variables such as "cityname" or "speedinthisline". The shapes will have to interact on user actions (click, move ever etc).
I though for the circles I could use circular jbuttons. I found some examples on how to make such buttons, or round shaped frames. Also I found some examples on how to make clickable graphics. In vb.net OvalShape an Lineshape exist that are ready made clickable shape objects.
For ease of usage I would like to have seperate class for each shape type, in which all the extra variables could be declared.
What is the best way to focus my efforts? Go for extending components like buttons, or go for doing something out of Graphics classes?
Are there any ready made classes like the ones that exist in vb.net? Any recomendations?
The question depends a lot on how you want to structure the program
For simplicity sake, I would go with creating a custom component, probably extending from something like JPanel and override it's paintComponent method.
This gives you a basic "paintable" component, that can easily be configured with a MouseListener...
This means you're not having to spend most of your time worrying about how to translate the mouse events.
My personal preference would be to maintain a single MouseListener, which is registered with all the elements you have on the screen and provides overall management.
The problem with this approach is zooming. It's difficult to zoom a single parent container and provide translation of the mouse events.
Lukey for your, JLayer can provide this functionality for you. This, again, saves you from having to make mouse event translations as well as trying to calculate the viewable size of the container all the time.
I'm no expert on Swing, but drawing thousands of constantly morphing circular JButtons is definitely probably not going to be fast or smooth. Look into doing something with more basic Graphics packages. Here's an example of how to make a custom clickable, drawn object.

Move image with mouse cursor in Java applet [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've been trying to teach myself Java recently and as part of the process I'm working on a Calorie Calculator applet.
Just to make things more fun I was thinking to use the picture of a smartphone as the background image.
What I want to know is: say I also had a picture of a stylus pen; any way I could make that move with the mouse once I've clicked on it? Preferably this image would replace the mouse cursor (though not mandatory). It should stick to the mouse cursor until the applet is closed, regardless of any other events occurring (clicking other images, buttons, text areas etc.)
I appreciate your assistance!
..any way I could make that move with the mouse once I've clicked on it?
The main component needs a MouseListener. See How to Write a Mouse Listener for details.
Preferably this image would replace the mouse cursor (though not mandatory).
Look to the Cursor API for that.
This sounds like a classic XY problem.
What you might actually be looking for is Drag and Drop and Data Transfer.

Synchronization between two classes [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 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.

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