CS1103 Discussion Assignment Unit 8 - The advantages of using Java GUI

Questions

Please discuss the advantages of using Java GUI.

1. Definition

The graphical user interface (GUI) is a form that allows users to use picture-like tools, such as buttons and text fields, instead of the command line, to interact with electronics (Wikipedia, 2022). Java has three GUI toolkits: the Abstract Windows Toolkit (AWT), Swing, and JavaFX.

  • AWT was introduced in Java 1.0. The feature is that it is a bit old, and “there were different bugs in the AWT user interface library on the different platforms, which is known as write once, debug everywhere” (Horstmann, 2019, p. 759).

  • Swing is built based on AWT. It has more capable components than AWT (Horstmann, 2019)

  • “JavaFX is designed to replace Swing as the GUI library for Java SE and is included with the standard JDK and JRE since Java 7” (Farrell, 2018, p. 759). But since Java 11, JavaFX has been removed from the standard JDK and JRE.

2. Advantages

The widespread use of Java GUIs, I think, is mainly due to the following three advantages:

  • First, the GUI is easy to operate (Roomi, 2021) because it has many picture-like components, such as buttons, text fields, labels, etc. Users only need to click or drag these visual components to complete the operations, which is very intuitive and easy to do.

  • Second, the GUI is easy to understand (Roomi, 2021). Specifically, although the GUI is event-driven, users only need to pay attention to the component’s function and do not need to understand how the component is implemented and driven by events. For example, if a person creates a submit Jbutton, he/she must do the following three steps: (a) Write a class that implements the ActionListener interface. (b) Override the actionPerformed(ActionEvent) method in this class. (c) Create an object with the above class as a listener and register it with the Jbutton object. However, when users use it, they don’t need to know these specific code details. Instead, they only need to know that this is a submit button and then click it. This greatly simplifies the difficulty for users to understand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JButtonDemo extends JFrame implements ActionListener {

JButton button = new JButton("Submit");

public JAJButtonDemoction() {
// Register the JButtonDemo class as a listener for events generated by the button
button.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
// Implement what you want to do after clicking the button
}
}
The process of registering a listener for a Jbutton
  • Third, using a GUI can improve efficiency. There are two specific reasons. One is that, as mentioned in the previous two points, these visual components are easy to use and understand, so they are helpful to improve efficiency. Another reason is that we can associate keyboard accelerators with these components. For instance, we can use the setAccelerator() method to associate a JMenuItem with a shortcut key of “ctrl Z”. This also benefits operations and increases efficiency.
1
2
JMenuItem undoCommand = new JMenuItem( "Undo" );
undoCommand.setAccelerator( KeyStroke.getKeyStroke("ctrl Z") );
Associate a keyboard accelerator with a JmenuItem

Word count: 477

References

1.Wikipedia. (2022). Graphical user interface.
https://en.wikipedia.org/wiki/Graphical_user_interface

2.Horstmann, C. S. (2019). Core Java Volume I–Fundamentals (11th ed.). Pearson.

3.Farrell, J. (2018). Java Programming (9th ed.). Cengege.

4.Roomi, M. (2021, February 11 ). 5 advantages and disadvantages of GUI: Drawbacks & benefits of GUI. HitechWhizz.
https://www.hitechwhizz.com/2021/02/5-advantages-and-disadvantages-drawbacks-benefits-of-gui.html

​


This is the ending, thanks for reading.