Upload
harry-ostaiza
View
91
Download
1
Embed Size (px)
Citation preview
TECHNICAL UNIVERSITY OF MANABI
FACULTY OF COMPUTER
ENGLISH PROJECT
TOPIC:
PARTIAL 2ND PROJECT ENGLISH
NAME:
HARRY OSTAIZA
3”C”
TEACHER:
DANY JARRE
PERIOD:
SEPTEMBER 2012-FEBRUAARY 2013
INTRODUCTION TO SWING
Swing is one of the major improvements that have experienced the JDK in version 1.2
with respect to version 1.1, and represents the new generation of AWT. It is also one of
the API of Basics Classes Java (JFC), which is the result of a collaborative effort
between Sun large, Netscape, IBM and other companies. Swing what gives power its
importance is offered to develop graphical user interfaces (GUI) for applets
And applications. The quantity and quality of checks Swing GUI offering is unrivaled
in any other toolkit controls GUI .the source Swing GUI that presents can find on
Internet Basics Classes Netscape (IFC). Swing components beyond the IFC, to the
extent that there is no significant similarity between the components of IFC Swing.
Swing also offers the possibility of quickly and easily changes the look and feel (L & F)
of a single component or component group. This possibility, known with aspect and feel
Pluggable (PL & F), is a hallmark of Swing.
Abstract Windows Toolkit (AWT) is the original toolkit
Java. Its main advantages are that comes with each version of Java technology,
including Java applications in old browsers, and is very stable.
AWT is a very simple set of tools with few components with layout managers, and
events. This is because Sun Microsystems decided to use the lowest common
denominator (LCD) for AWT approach.
The content of AWT:
Object
CheckboxGroup
Component
Button
Canvas
CheckBox
Choice
Container
Panel
Applet
ScrollPane
Window
Dialog
Frame
Label
List
TextComponent
TextArea
TextField
MenuComponent
MenuItem
CheckboxMenuItem
Menu
PopupMenu
LayoutManager
FlowLayout
GridLayout
LayoutManager2
BorderLayout
CardLayout
GridBagLayout
EventObject
AWTEvent
ActionEvent
AdjustmentEvent
ComponentEvent
ContainerEvent
FocusEvent
InputEvent
KeyEvent
MouseEvent
MouseWheelEvent
PaintEvent
WindowEvent
HierarchyEvent
InputMethodEvent
InvocationEvent
ItemEvent
TextEvent
SWING
Java Swing, also known as part of the Java Foundation Classes (JFC), was an attempt to
solve most of the shortcomings of AWT. In Swing, Sun created a beautifully designed,
flexible and powerful set of tools
.Unfortunately, this means that Swing takes time to learn, and is sometimes too complex
for common situations.Swing is built on AWT parts. All parts are also part of Swing
AWT. Swing uses the AWT event model and support classes, such as colors, images
and graphics. Swing components, layout managers, and events are summarized below.
Object
Component
Container
JComponent
AbstractButton
JButton
JMenuItem
JCheckBonMenuItem
JMenu
JRadioButonMenuItem
JToggleButton
JCheckBox
JRadioButton
Box
Filler
JColorChooser
JComboBox
JDesktopIcon
JFileChooser
JInternalFrame
JLabel
JLayeredPane
JDesktopPane
JList
JMenuBar
JOptionPane
JPanel
JPopupMenu
JProgressBar
JRootPane
JScrollBar
JScrollPane
JSeparator
JSlider
JSplitPane
JTabbedPane
JTable
JTableHeader
JTextComponent
JEditorPane
FrameEditorPane
JTextPane
JTextArea
JtextField
JPasswordField
JToolBar
JToolTip
JTree
JViewport
ScrollableTabViewpot
Panel
Applet
JApplet
Window
Dialog
JDialog
Frame
JFrame
JWindow
*Layoutmanager
CenterLayout
LayoutManager2
BoxLayout
OverlayLayout
SpringLayout
EventObject
AWTEvent
AncestorEvent
ComponentEvent
InputEvent
KeyEvent
MenuKeyEvent
MouseEvent
MenuDragMouseEvent
InternalFrameEvent
BUILD A WINDOW
Import javax.swing.*;
public class Trigo extends JFrame{}
The first line simply import the package where the class is defined JFrame. A JFrame is
the class that represents the type "Window". In other words a "JFrame" is a Windows
operating system. As our class inherits (extends) the class JFrame, Wheat will therefore
also a JFrame is a window.
To check this add to our class a "main" method, now being as follows:
import javax.swing.*;
public class Trigo extends JFrame{
public static void main(String[] arg){
Trigo miAplicacion = new Trigo();
miAplicacion.setBounds(10,10,200,200);
miAplicacion.pack();
miAplicacion.setVisible(true);
}
}
All messages sent to the object "myapp" are methods inherited from "JFrame". The first
method "setBounds" sets the initial position of the window on the screen and its
dimensions. The second, "pack", at this time it was not really necessary because the
window is empty, but we wanted to include it to avoid having to modify the main later.
This method optimizes the arrangement of the elements within the window. And the last
message is simply to order the sale is made visible. After compiling and running the
code you see something like the screen shown in Figure 1.
THE BORDERLAYOUT MANAGER
The steps to set the BorderLayout manager are different from those used for the
FlowLayout manager.
1. Create buttons (Button class objects) and the layout manager (BorderLayout
class object)
Button btnOeste = new Button();
BorderLayout borderLayout1 = new BorderLayout();
2. Set its properties in init
btnOeste.setFont(new Font("Dialog", 1, 16));
btn1.setLabel("Oeste");
Add the controls to the applet (or panel) using add, in the second argument indicating
the position you occupy each panel control by static BorderLayout class.
this.add (btnOeste, BorderLayout.WEST);
FLOWLAYOUT MANAGER
Controls are objects of the Button class, and the layout manager is an object of the class
FlowLayout. Once initialized data members in member function init set their properties
and add the applet using the add function, once established by the layout manager
setLayout. The steps are as follows
1. Create buttons (Button class objects) and design manager (class object FlowLayout)
Button btn1 = new Button ();
FlowLayout1 = new FlowLayout FlowLayout ();
2. Set its properties in init
btn1.setFont (new Font ("Dialog", 1, 16));
btn1.setLabel ("1");
flowLayout1.setHgap (20);
3. Set the applet's layout manager (or Blank) by setLayout
this.setLayout (flowLayout1);
4. Add the controls to the applet (or panel) by add
this.add (btn1, null);
What has been said for a voucher for any panel applet as an applet is simply a
specialized panel.
GRIDLAYOUT
The steps to set the GridLayout manager are identical to those we have used for
determining lel FlowLayout manager. This manager controls available in a matrix form
as shown in Fig. We have eight buttons arranged in two rows and four columns.
JPANEL
a JPanel object is a so-called "containers". This is because they serve to contain other
objects. In this way, they act as "boxes" where are you getting them to handle things and
so as a group. For example, if you group a series of buttons inside a JPanel and want to
disable them all at once, you can disable the JPanel that contains all the contents and so
is disabled. Or if you want to move them all at once, etc..
The containers are very useful as they help to simplify things and structure them.
Dialogs (JOptionPane) are "tools" very useful when entering data and display
information; say useful because these do not need to create objects of type
BufferedReader and "pull" more code to use correct data entered as I explained briefly
in elanterior post. Among the JOptionPane entontraremos: showConfirmDialog,
showInputDialog, showMessageDialog and showOptionDialog. The most used are the
first three.
SHOWMESSAGEDIALOG
This dialog box is ideal for displaying information of any kind, this replaces the
System.out.print () The syntax is:
1 JOptionPane.showMessageDialog (null, "Hello world!");
- As noted in the previous line, which goes inside the "..." is the message we want to
show, for these messages can also be used to display messages concatenation and
variables at once.
- What you see when you run the application is:
SHOWINPUTDIALOG
This dialog box is ideal for data entry, you have to keep in mind that all that is received
is taken as a string, but this is no problem to work with other data types, in which case
you need to convert the string receives the type of data you need (int, float, double,
etc.). The syntax is the following:
String x = JOptionPane.showInputDialog ("Enter a number:");
JOptionPane.showMessageDialog (null, "The number entered is:" + x);
- In line 1 create a variable of type String which call "ax" in this variable I store the data
that is entered with showInputDialog, like the showMessageDialog what goes into the
"..." is the message that showed the user.
- On line 2 show the data I got right through the variable x.
- When running the application will see the following:
SHOWCONFIRMDIALOG
This dialog box is of type integer, so you have to create a variable of type int to handle
this options dialog offers the above are yes, no, and cancel, the syntax is:
int x = JOptionPane.showConfirmDialog (null, "You are in java?");
if (x == JOptionPane.YES_OPTION)
JOptionPane.showMessageDialog (null, "You have chosen SI.");
else if (x == JOptionPane.NO_OPTION)
JOptionPane.showMessageDialog (null, "You have chosen NOT.");
- On line 1 shows that create an integer variable, the null that comes before the message
is necessary, as this is taken when the user presses the Esc key or press Cancel, the
message to display is used as in the previous dialog boxes.
- On lines 2 and 4 are used to make conditional respective shares according to the
option that the user has given.
- In lines 3 and 5 are shown for the respective message option that the user has given.
If we select if we will see the following dialog box:
If instead you select will not see the following dialog box: