Java GUI questions?

So, currently I am trying to make my first simple Java game, and I started to deal with the GUI. I already planned exactly how I want the user interface to look, but I did not spend much time working with the GUI in Java, so I got a little lost. I do not understand if the GUI should be a separate object from the logic or built in the same class. For example: I have a map class that contains color and value, but is it better to code a separate class only to display and use a graphic image to represent the map, where its executors use the logic of my actual map class class? Or I just code both the GUI and the logic in one class, because then I need to extend the JComponent and that does not match my original map class.

Also, I'm really confused about how a professional looking GUI will look like coding wise? Like the League of Legends game, the client was encoded in Java, and Frame was not even a native Windows frame. Are buttons and frames and which not all user images are encoded as buttons or are components extending JComponent etc.? I know a lot about java programming logic since I am in AP Computer Science, but the class is really basic for the GUI for what I would like to accomplish, and I can't find anywhere on Google to learn professional methods and techniques.

I am currently using the Netbeans IDE

+4
source share
3 answers

You will learn a lot of experience.

Many of the most advanced interfaces are no longer even like Java. At least the top level extends JComponent , but buttons do not have to. The main application can use custom drawing methods for custom views or other libraries to display 3D images. After you have experience using many different components and libraries, you will begin to see how they can all come together to form a cohesive application.

To solve issues related to the object model, there are definitely separate classes from your objects to display them. One object can ultimately be used by different parts of your application, transmitted over networks, displayed on screens, sent as text or any number of different things. If you try to put all this code in your object model, it will be a complete mess.

Try creating common sense methods for your objects. Think about what methods, questions, properties will be used by all the different parts of your application when interacting with these objects. Whatever is disposable and useful in only one place, do not put it in your main classes of objects.

Also, remember that you can always move functionality. Using a good IDE, such as Eclipse, makes it easy to pull or push methods, properties, and other parts of a class into a superclass or subclass. If you write some functions related to an object, put it in a module that uses it. When you need the same functionality in another module, move it to your object model so that it can be shared. This is easy to do with the right tools.

+4
source

If you are using the AWT or Swing GUI, I would recommend using an IDE like Netbeans , which has a built-in GUI for AWT and Swing. Regardless of whether you want to use it, this can help you learn one way to structure your GUI.

As commentators noted, there are also very good lessons, although I personally think that books are much easier to read than online lessons.

Also, code completion is really useful for reading Java documents and learning about the possible methods each class has.

0
source

First of all, you should have a clear understanding of Java. I would recommend you use Swing and the NetBeans . You will find a good GUI tutorial on the NetBeans website and youtube . Hope that will help you a lot.

0
source

Source: https://habr.com/ru/post/1398745/


All Articles