I'm working on a GUI in Window Builder and I want to import some of the objects I have declared on my main. The GUI is in the same package as my main and 5 classes, 1 parent and 4 child classes. Is this possible to do? As of right now, I'm trying to call my characters for the game I created into the GUI to be displayed when a certain button is pushed.
So far, I tried importing each class into my GUI. That didn't work went into my main and added my GUI by declaring it as a new object followed up by adding EventQueue.invokeLater and making that visible, but that didn't really work. Any thoughts on how to do something like this?
On Window builder Palette, click choose component and search for your class for example
package.class. This is the image Refer to this.
Related
It's my first question here.
As the title already says, this question is about Java Windowbuilder and about a project I am currently working on.
So:
I got a class creating an Window using Window Builder with multiple RadioButtons each with a unique name.
I need a second class, which I "inherit" (already needed to inherit JFrame) by simulating it with interfaces.
In this second class I need to be able to change e.g. the RadioButtons in the first class.
Maybe I just do not see the solution...
What I'm thinking of doing is creating a class for my little subview, so I can use it over and over again. Specifically, in my project, I need a colored rectangular and a label, and between those subviews those are the ones gonna change. Thus, I want a class that represent that two components as one component.
I'm trying to use swing. Before, I used acm package which gave me convenient way of doing it, but I can't solve that problem with swing. So, the problem starts here, I couldn't figure out how to create a custom GUI class for a subview.
I want to put them in a for loop later, so I want to handle the case in once rather than writing for 20 times manually.
Any help would be appreciated,
Create your custom class so that it extends a JPanel. From there, you can add your common subcomponents, which sets each one up by passing parameters through the constructor, and then implement any common behaviours with methods on that class.
You could try Window Builder plugin for eclipse for drag and drop editor. You could try to figure what's going wrong by organizing you objects.
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)
I've created a new Java project without main class in NetBeans and then I've added a jApplet Form (let's call it MainWindow.java) to my project package. After that, I've added few other jApplet Forms that represent different "pages" of my applet application to my package using the GUI builder of NetBeans.
When I run my applet, I can see the MainWindow form with some buttons, label, etc. on the AppletViewer just fine.
Now, I want to make an event when one of my buttons on my MainWindow is pressed, to show another jApplet Form that I've created earlier and show that form instead of the MainWindow form. I'm trying to create a simple navigation system in my jApplet, and I don't know how to make it efficiently!
Can anyone help me with the code that I should write in the MouseClicked event of my button to make it show another form?
Basically, you can't (or shouldn't) design applets like this. There is no effective means to switch from one applet to another.
Instead, you should create one master applet and using something like CardLayout, design separate forms using one thing like JPanel
You'd then able to switch the forms using the CardLayout manager as needed
Create a project in NetBeans and create a new JFrame.
Use the GUI Builder to drag some components like a button or label onto the frame and look and the source. You'll see by default that the member variables are private in the frame class.
Now go to Tools -> Options -> Misc -> GUI Builder and change something like the variables modifier to protected instead of private.
Now how do you apply those changes to the already generated code? I've tried several things like format code, fix code, etc. I've even tried cutting all the components off of the frame and then repasting them hoping to fix the issue, but it still uses the old settings.
When I create a new JFrame in the project and perform step 2 again, the changes have taken effect. Any new code generated on a new frame or file works as expected, but not the original.
This is very strange behavior, and I have to imagine there's an easy straight forward way to regenerate this code. Am I missing something?
I'm using NetBeans 7.1 and Java 7u2. Thanks in advance!
As you have already alluded to, the GUI Builder options are defaults only, for the creation of the form.
You can change most things about already-generated GUI elements.
To change the GUI components 'access' from private to protected, right-click the component in the GUI designer and select "Customize Code". At the bottom of the "Code Customizer" dialog you can change just about any aspect of the declaration of the GUI element. That dialog also lets you customise things like the constructor used for the element.
I would recommend you leave the access default at private, and only change the elements that you really need to be protected or even public.
And don't listen to the doom-sayers. We have over 600 GUI-designed forms in our application, we use the GUI designer every day, with multiple developers, and we very rarely have any issues at all.
By the way, we are using version 6.9.1 of NetBeans with Java6, so YMMV.