Introduction to designing a Java application
In order to make a serious application, it is necessary that it has its own user interface. It actually represents the graphical part of the application. It is considered good programming practice to create applications using MVC (Model View Controler). This practically means that the code that organizes and stores data and performs various calculations (Model), displays the graphical part of the application (View), and controls and connects the two entities to function properly (Controller), is not to be confused.
This section describes how to create a visual part of an application, which is what View represents in the architecture mentioned.
This section describes how to create a visual part of an application, which is what View represents in the architecture mentioned.
Initially, classes from the java.awt package and 4 sub-packages java.awt.event, java.awt.image, java.awt.datatransfer and java.awt.peer were used to create the graphics.
A swing user package was later created and this site describes how to create applications using this package.
Finally, javafx technology for creating desktop and rich internet applications is described.
A swing user package was later created and this site describes how to create applications using this package.
Finally, javafx technology for creating desktop and rich internet applications is described.
Creating the visual part of the application in JAVA-tutorial
This tutorial contains:
- Working with basic dialogs (JOptionPane class)
- Building graphical applications using the swing user package
- Events in Java
- Drawing in the window
- Examples of building graphics in Java
- Java animations
Working with basic dialogs (JOptionPane class)
The swing package (javax.swing) contains classes to support working with graphic objects (forms, dialogs, form components, etc.).
The JOptionPane class contains methods that create basic dialogs for data entry, data display, confirmation dialogs, alerts, error messages, etc.
The JOptionPane class contains methods that create basic dialogs for data entry, data display, confirmation dialogs, alerts, error messages, etc.
Input Dialog in Java
It is used when entering data String, double, int, etc.
- Enter text information:
When starting an application, a dialog is displayed where the user can enter text data. This dialog was drawn by the showInputDialog method and this method returns a String data, that is, the text that the user enters into the text field of the dialog.
After startup:
After startup:
- Entering integer data
If we followed the logic of entering text (String) data and tried to do the same with integer data, we would get an error message:
Because the method returns a String and on the left must be a String variable. Therefore, we will introduce another variable of type String in which we will place the number in the form of text e.g. "7" and then parse and convert the number as text to an integer.
Message Dialog
Used to quickly display a message.
If the JoptionPane indicator is used instead of the JoptionPane.ERROR_MESSAGE we will get a dialog to display the error message:
Confirm Dialog
Used to ask the user to confirm the previous command. For example. if it has given the command to delete a document, it is shown a confirmation dialog, with the choice to finish the deletion started or to cancel.
Next
Graphical User Interface (GUI)>| |