09 java programming with gui part1

14
JAVA PROGRAMMING WITH GUI PART I Object Oriented Programming

Upload: danita-ureta-balasta

Post on 30-Sep-2015

22 views

Category:

Documents


0 download

DESCRIPTION

Object Oriented Programming

TRANSCRIPT

  • JAVA PROGRAMMING WITH GUI PART I Object Oriented Programming

    Advanced Object-Oriented Concepts (Part 1)

  • What is GUIStands for Graphical User InterfaceProgram interface that takes advantage of the computers graphics capabilities to make the program easier to use Designed in 1970 by Xerox Corporations Palo Alto Research Center

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • What is GUIBasic Components:PointerPointing deviceIconsDesktopWindowsMenu

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Basic GUI ObjectsIn Java, GUI-based programs are implemented by using the classes from the standard javax.swing (Swing classes) and java.awt (AWT classes) packages. All GUI classes are based on the fundamental classes in the Application Windowing Toolkit or AWT.JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Basic GUI ObjectsA GUI program is composed of three types of software:Graphical components that make up the Graphical User InterfaceListener methods that receive the events and respond to themApplication methods that perform the desired operations on the information

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Abstract Window ToolkitJavas platform-independent windowing, graphics, and user-interface widget toolkit Part of the Java Foundation Classes (JFC) the standard API (Application Program Interface) for providing graphical user interfaces for Java programs Contains the fundamental classes used for constructing GUIsJAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • SwingGraphical user interface toolkit in Java, which is one part of the Java Foundation Classes (JFC) Includes graphical user interface (GUI) widgets such as text boxes, buttons, split-panes, and tables runs the same on all platforms Supports pluggable look and feel not by using the native platform's facilities, but by roughly emulating them Classes are often described as lightweight because they do not require allocation of native resources in the operating systems window toolkit JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Swing ComponentsUI elements such as dialog boxes and buttons; you can usually recognize their names because they begin with J Each Swing component is a descendant of a JComponent, which in turn inherits from the java.awt.Container class You insert the import statementimport javax.swing.*;at the beginning of your Java program files so you can take advantage of the Swing UI components and their methods

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JFrame Classcontains the most basic functionalities that support features found in any frame window, such as minimizing the window, moving the window, and resizing the window To design such a frame window, we define a subclass of the JFrame class and add methods and data members that implement the needed functionalities. JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JFrame Classjava.lang.Objectjava.awt.Componentjava.awt.Containerjava.awt.Windowjava.awt.Framejavax.swing.JFrameJAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JFrame ClassisResizable()indicate whether the JFrame is resizable Sets a JFrame to be visible voidsetVisible(boolean)using the boolean argument true and invisible using the boolean argument falsevoid setBounds(int, int, int, int)Overrides the default behavior of the JFrame to be positioned in the upper-left corner of the computer screens desktop. The first two arguments are the horizontal and vertical positions of the JFrames upper-left corner on the desktop. The final two arguments set the width and height.

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JFrame ClassWhen a JFrame serves as a Swing applications main user interface, you usually want the program to exit when the user clicks Close. To change this behavior, you can call a JFramessetDefaultCloseOperation() method and use one of the following four values as an argument:JFrame.EXIT_ON_CLOSE() - exits the program when the JFrame is closed.WindowConstants.DISPOSE_ON_CLOSE() - closes the frame, disposes of the JFrame object, and keeps running the application.WindowConstants.DO_NOTHING_ON_CLOSE() - keeps the JFrame and continues running. In other words, it functionally disables the Close buttonWindowConstants.HIDE_ON_CLOSE () - closes the JFrame and continues running; this is the default operation that you frequently want to override.

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JPanel ClassThe simplest Swing container plain, borderless surface that can hold lightweight UI components, such as JButton, JCheckBoxes, or even other JPanelsjava.lang.Objectjava.awt.Componentjava.awt.Containerjavax.swing.JComponentjavax.swing.JPanel

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

  • Using the JPanel ClassTo add a component to a JPanel, the containers add() method is called, using the component as the argument. In using a JPanel to hold components, the setContentPane() method is also used to allow the JPanel to be set as a content pane so it can hold components.

    JAVA PROGRAMMING WITH GUI PART I*

    Advanced Object-Oriented Concepts (Part 1)

    *