When we develop a GUI form we need some way to organize the components on
the form. The easiest way to do this is just add them to the form
one after the other. In swing this is called a
FlowLayout. They definitely aren't going to give the
developer much, if any, control over the overall appearance of the GUI.
But they do provide something.
In this webpage we will also develop GUIs using both an applet and an application. Developing GUIs with applications is slightly more difficult than it is for applets. This is because the basic concept of an applet has it configured to run within a web browser which has all kinds of built-in GUI capabilities.
Neither of these programs will have the capacity to respond to any user inputs other than when they click on the close button of the GUI. The capabilities to respond to other important user inputs is something we will develop in the next webpage. Presently, I want to demonstrate a GUI layout to help you work towards developing your own more elaborate layouts.
Our first program is an applet called InTheFlow.java.
public class InTheFlow extends JApplet
|This program does the following
The following contains the HTML file.
<applet code="InTheFlow.class" width=300 height=100>
|When this applet is run you should see the following on your screen.|
|So you can see the labels and text fields don't really
line up together all that well. You should try to adjust the size to
see if you can get a better correspondence.
In addition, to see some of the inherent difficulties in this sort of layout, you should stretch the window somewhat to see something like the following.
|You can see how the layout shifts.
So, FlowLayouts are the easiest to implement, and possibly practicable in some situations. But, we will only make use of them intermittently and mostly when I don't want to distract your understanding of the code with other issues.
An Application Based GUI. Now I want to run what should seem like almost the same program, but as an application. We will discuss the code after presenting the code and running it. You should call the file InTheFlowApp.java.
public class InTheFlowApp extends JFrame
} // end class InTheFlowApp
} // end class ExitWindow
|If you run the program, the end result will look very little different from what was obtained using the applet.|
|The discussion of the code follows. Make sure to
focus on the differences between the applet and the application.
Notice how when you compile the InTheFlowApp program, you get a class called InTheFlowApp.class but you also get a class called ExitWindow.class.