even better solution is to apply some function to the password and compare the result with
a number that is stored somewhere. In this way, even if someone obtains the Java code,
they would not be able to read the password. In order for this approach to work, it must be
the case that the encoding function cannot be easily reversed. In other words, one cannot
easily determine what is the input to the function from the output of the function.
The chapter describes three component layouts: flow, grid, and border. The flow layout
is used when we want to place components sequentially in a window. When the top line
becomes full, the components are placed on the second line and so on. The grid layout can
be used to place components in a grid. The border layout allows us to place components
in the south, east, west, north, or the center of the window. All three layouts can also be
applied to either windows or panels. Multiple panels can be added to a window and each
panel can have its own layout scheme. Note that this overview of layouts is not exhaustive.
Rather, it gives the reader the basics to arrange GUI components in a window.
The chapter also covers basic GUI components, such as buttons, labels, text fields,
text areas, scroll areas, combo boxes, radio buttons, and password fields. For every GUI
component, a short example of how the component works is presented. Again, the overview
is by no means complete. It covers only the most basic GUI components and it is a good
starting point for creating GUI applications. The chapter also covers dialog boxes. They are
similar to windows, but they cannot be minimized or maximized. A dialog box can also be
modal, which means that it must be closed before the user can interact with the rest of the
windows of the application.
JButton b = new JButton("Press me");
Creates a new button with text “Press
Change the label of a button.
Registers the action listener with the button. When
the button is pressed, the actionPerformed method of the a object will be executed.
String s = b.getText(); ⇒
Gets the label of a button.
p.setLayout(new FlowLayout(FlowLayout.LEFT,2,10)); ⇒
Changes the layout of
the panel p to flow layout. The method can also be applied on objects of type JFrame .
The virtual lines where the components are displayed will be left justified. There will
be a 2-pixel horizontal gap and a 10-pixel vertical gap.
p.setLayout(new BorderLayout()); ⇒
Changes the layout of the panel p to border
layout. The method can also be applied on objects of type JFrame .
Adds the button b to the west side of the panel