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...
Related
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.
I am new to stackoverflow and am sorry, if this question was already asked, but when I searched for one containing my problem, I could not find one.
Here is my question:
In Java I am creating a game (just for fun and am learning to code). You start my game with a launcher to log in. However, if you do not have an account, you can register. What I like more is to use one frame. I have a panel containing the launcher elements and one containing the register elements. I am trying to learn how to code, if another one is working on my project, he does not necessarily need to look all over the code to do some work. In other words, I am using packages to sort classes. Example: Classes for the launcher are in package Launcher. Classes for register are in package register.
In my code, I have a class called Display extending JFrame. Display is instanciated in the class with the main method. Display has 2 Methods for removing a panel and adding a panel, requiring you to pass a JPanel, if you use any of both methods. After Display is instantiated, it instantiates a jpanel inside the constructor. This has all the components to Display. The event listeners are in another class. So I am passing the buttons and Display to that class, because here is the eventlistener code for the button register. In my register class I have defined and instantiated all necessary components. I passed the display through all of the classes until it reached the register class which extends jpanel. I even passed the Launcher class. Now i can use the methods in display to remove the launcher panel and add my register panel.
My Question:
is this good code or overkill?
I never instantiated Display after the main method again. I always declared it and set it to the passed display. I did this, because instantiated a new Display would mean unnecessary use of memory and passing objects in java is actually a passing by references, meaning it is not passing the object but a pointer to the object. So this would mean less memory usage.
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'm new to Java, so need a little bit help:
Programming in Java I use NetBeans. So, in making forms, I use already existing swing controls just placing them on the form. But, for example, I want to improve control as a point add some new action listeners, so good solution would be override it.
I can create new class and write:
public class ExtendedControl extends Control
{
}
But, is it possible to add ExtendedControl to form automatically (like original controls)?
You will need to write your own JavaBean Components. This can be easily done with Netbeans.
Once you are done you can add your JavaBean to the Beans Folder, or wherever you wish, in the Palette Manager.
Here is the manual and here is an example that shows you how to proceed.
These are the few steps, necessary in order to add to the Palette.
I'm looking for a specific functionality. I want to load a class that extends JPanel for instance and show that JPanel on a separate GUI class.
I'm looking for the ability to switch several of these classes out at will. I have an idea for an educational game software and the classes would be the different games.
I do realize that I can instantiate an instance of each class in my GUI class, but I ran into the issue of them not displaying properly when I try to switch between them. repaint() only works on the last class I added to my content pane. Not sure why as the multiple classes I instantiate are present, it just seems to ignore the preceding classes.
How to swap components?
You can either use CardLayout to switch all the component or add/remove them calling
container.revalidate();
container.repaint();