Monday, August 12, 2013

An Introduction to Java GUI Programming


Java GUI programming involves two packages: the original abstract windows kit (AWT) and the newer Swing toolkit. Swing components have the prefix J to distinguish them from the original AWT ones (e.g. JFrame instead of Frame). To include Swing components and methods in your project, you must import the java.awt.*, java.awt.event.*, and javax.swing.* packages. Displayable frames are top-level containers such as JFrame, JWindows, JDialog, and JApplet, which interface with the operating system's window manager. Non-displaying content panes are intermediate containers such as JPanel, JOptionsPane, JScrollPane, and JSplitPane. Containers are therefore widgets or GUI controls that are used to hold and group other widgets such as text boxes, check boxes, radio buttons, et al. In .NET the main UI, called the Windows Form, holds the controls that are dragged and dropped onto the control surface. Every GUI starts with a window meant to display things. In Swing, there are three types of windows: the Applet, the Dialog, and the Frame. These interface with the windows manager. In swing, a frame object is called a JFrame. A JFrame is considered the top most container. These are also called displayable frames. Non-displaying content panes are intermediate containers such as JPanel, JScrollPane, JLayeredPane, JSplitPane and JTabbedPane which organize the layout structure when multiple controls are being used. Stated simply, the content pane is where we place out text fields are other widgets, so to add and display GUI controls, we need to specify that it is the content pane that we are adding to. The content pane is then at the top of a containment hierarchy, in which this tree-like hierarchy has a top-level container (in our case JFrame). Working down the tree, we would find other top level containers like JPanel to hold the components. Here is the code that produces a simple frame upon to build on:
Introduction_4.gif

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips