good day sirs. I've been struggling with this dialog because it keeps on saying I should have a table skin for my table but I'm not even using a table. However I have a skin ".atlas" file which contains packed images for my graphical user interface such as windows buttons.
Is there any way I could resolve this problem?aside from ".json" is there anyway?
My modal dialog worked using another stage. When I wanted to show it, I changed the InputProcessor to my dialogs internal stage so other GUI objects couldn't respond to user input outside the dialog.
I found LIBGDX's dialogs overkill for my purposes. Perhaps you need a skin for your dialog? If not I'd just go with my approach. You could always use a texture atlas instead. It can function much like a skin as strings are used to reference regions of an image.
Related
I'm about to write a program using Java and i want it to have the next behavior:
Start with a small screen, just one button (i'm going for the JMenuBar) for the user to select a image file (a country or state map)
Once selected the image file, i'll need to resize the frame to the size of the selected image, and put the image as background.
when the user clicks somewhere inside the frame (click on a state or city) the program will have to create a visual object there, a circle, square or any form in that coordinates.
will need also a listener in those objects to know when they are clicked.
Summary: User has to select an image and trace a graph on it.
I am not asking for the code to do this. I would like to have some ideas about which components use to achieve this since i have been reading and there are plenty of ways to set the background image and stuff. But, considering the requirements, can you recommend me which components to use? I am a bit short of time since i've been given only about a week to code this, otherwise i would try all the alternatives by myself.
Some answer like:
"use a label to set the background and then resize the frame by this way: (some stuff) and then you can create a class extending from JLabel to create the circles with the listeners...." that would be enough help
I hope I was clear, any idea is welcome
Many thanks!
If you're going to stick with Swing I would use a JFileChooser to select the image. Once you got the image you can easily resize the JFrame by using the frame.setSize(image.getWidth(), image.getHeight());
To listen for mouse clicks inside your JFrame you need to use a MouseListener, make sure to add it to the frame, I always forget doing that.
Not sure whether you've succeeded drawing images/shapes at all. If not, you need to use a JPanel, check this topic if you need extra help.
If you are going to use a "JFrame " then you should definitely use Swing JFrames JPanels, and JLabels (as well as any other JComponents you need.) to accomplish this. Use only one JFrame. Use JPanel as the content pane/background for your JFrame and add everything else to it. But I would also suggest learning and using JavaFX because its the newest and I think it would be the easiest to use to do something like this. But if you only have a week and you know some swing use what you know. If you need more information post some code. Or ask a more direct question.
I have a 2.5D isometric game that I would like to add a interactive HUD to. I tried using JButtons with Icons but could not draw both the button and my game at once. I'm looking for a cost-efficient (computer resources-wise) technique in which I can draw my own images/buttons to the screen on top of my game.
Most likely will require you to create your own.
First you will need a method of capturing the click event (You may be able to use Swing's existing one depending on your engine). You could for example register a single click event on the screen itself and then implement a method of "capturing" that event through to the component which was clicked on.
Next you will want to create button class which handles its state (MouseOver,Pressed,Unpressed), size and position.
Finally style or how you want your buttons to look. one possible method would be a 9-Patch, which is essentially 9 tiny images that are repeated in such a way to form a stretchable button.
9 Patch Resource - It's for android but the concept still applies
You can also take a look to see how other engines do it such as LibGDX.
Hope This Helps
I am already familiar with JButtons, JLabels and such, but I want to start making a game a very "colorful" menu. Is there a way to do this using Canvas (like adding a mouse listener and make some buttons in PhotoShop and detect if the mouse hovers over and clicks the button), or is there a better way?
Since you're already familiar with JButtons, you may find it easier (and more practical) simply to extend the existing JButton and modify its appearance, so that it looks like an image rather than the traditional grey button.
Amongst other things, it means you get all the standard button behaviour for free, including special cases, and in exchange all you have to do is override a couple of methods.
Have a read through the accepted answer for the following question, which explains pretty much exactly how to do that:
Creating a custom button in Java
I want to know how to show the loading of an application. Normally (let's say Netbeans IDE,)
the application will show how far it has loaded and how far to load. Also, loading classes as well can be seen in welcome page. How is this is done and how we can show our classes loading and loaded status (in a progress bar) in our applications? Also let's say that we have used Hibernate, and there is a login on first page, it takes time to start but only for the starting (I think it is because that the Hibernate factory is getting started and load its classes). The answer is hoped in Java.
I want to know how to show the loading of an application.
See the java.awt.SplashScreen class. But..
..show how far it has loaded and how far to load.
..with a customized image. Call SplashScreen.createGraphics() to get a Graphics object (from the image defined as a splash in the manifest) which can be drawn on. Draw the progress bar at an appropriate location on the Graphics object. For the progress bar, either use a JProgressBar as already mentioned, or to keep it lean (using pure AWT), draw one big Rectangle to represent the bar, and fill a smaller Rectangle to represent the progress.
See also How to Create a Splash Screen in the Java Tutorial. (Where you can see that image above.)
That sounds for using JProgressBar, combined with Splash Screen or JDialog.
Be sure that JProgressBar must be updated on the Event Dispatch Thread, more about that in Concurrency in Swing,
Then you have two choices as to how to update a JProgressBar correctly - by wrapping code into:
SwingWorker
Runnable/Thread
There is some support built into swing for this. See the tutorial on How to Use Progress Bars to get started.
Here is a very basic code:
JProgressBar progressBar;
progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(33); // put here the percentage you want to display...
progressBar.setStringPainted(true);
In my application I've a main shell window and lots of dialogs (classes extends Dialog). I use setSize(width,height) when initializing them, but I know that users constantly resize them for their taste.
What is a smarty way to get notified when the size changes so I can store/load them?
(And why don't do toolkit provide such a thing out of the box, like XUL?)
Most if not all GUI toolkits have a resize event that triggers whenever the user (or something else) resizes a given widget. Some readong for an example Moving and resizing - SWT
Take a look at java.util.prefs.Preferences. The width and height settings can be saved via putInt() and retrieved via getInt().
It would be a pretty minor task to subclass Dialog or JDialog and create a SizeRememberingDialog, or (probably better) to create a SizeRememberer(Dialog) class to set the size when constructed, listen for resize events, and save the new size whenever a resize occurs.