[PDF] Introduction to GUIs (Graphical User Interfaces) Interactive Programs





Previous PDF Next PDF



Abstract Window Toolkit Overview

The Java 1.1 JDK ( Java Developer's Kit) occurred in December 1996. This release includes many improvements and additions to AWT and is a major step for- ward 



Untitled

JAVA provides a rich set of libraries to create Graphical User Interface (GUI) objects in an platform independent way. Abstract Window Toolkit (AWT) is a 



Introduction to Abstract Window Toolkit:(AWT)

class in java.lang package. ? AWT is used to build the graphical user interface with standard windowing elements.



AWT AWT stands for Abstract Window Toolkit. It is a platform

It is a platform dependent API for creating Graphical User Interface (GUI) for java programs. Why AWT is platform dependent? Java AWT calls native platform ( 



Difference Between AWT and Swing Key Difference - AWT vs Swing

05-Feb-2018 difference between AWT and Swing is that AWT is Java's original platform dependent windowing graphics



Introducing AWT

•The Abstract Window Toolkit (AWT) was Java's first. GUI framework. Component An abstract superclass for various AWT components. Container.



GUI Programming

Java and GUIs. • There are two primary built-?in packages that provide. GUI components in Java. – java.awt.*. – java.swing.*. • The Abstract Window Toolkit 



The AWT Applets

https://users.cs.fiu.edu/~weiss/cop4338_spr02/lectures/AWT/awt.pdf





Introduction to GUIs (Graphical User Interfaces) Interactive Programs

How does Java do GUIs? 4. Java Support for Building GUIs. • Java Foundation Classes. ? Classes for building GUIs. ? Major components. ? awt and swing.

Introduction

to GUIs (Graphical User

Interfaces)

Lecture 18

CS211 - Summer 2008

2

Interactive Programs

"Classic" view of computer programs: transform inputs to outputs, stop

Event-driven programs:

interactive, long-running

Servers interact with clients

Applications interact with

user(s)useruser program input events output events input output 3

GUI Motivation

Interacting with a programProgram-Driven

Statements execute in sequential, predetermined order Use keyboard or file I/O, but program determines when that happens

Usually single-threaded

Event-Driven

Program waits for user input to activate certain statements

Typically uses a GUI (Graphical User Interface)

Often multi-threaded

Design...Which to pick?

Program called by another program?

Program used at command line?

Program interacts often with user?

Program used in window environment?How does Java do GUIs?4

Java Support for Building GUIs

Java Foundation Classes

Classes for building GUIs

Major components

awt and swing

Pluggable look-and-feel support

Accessibility API

Java 2D API

Drag-and-drop Support

InternationalizationOur main focus: Swing

Building blocks of GUIs

Windows & components

User interactions

Built upon the AWT (Abstract

Window Toolkit)

Java event model

Java's support for cross-platform GUIs is one of its main selling points5

Java Foundation Classes

Pluggable Look-and-Feel Support

Controls look-and-feel for particular windowing environment

E.g., Java, Windows, Motif, Mac

Accessibility API

Supports assistive technologies such as screen readers and Braille

Java 2D

Drawing

Includes rectangles, lines, circles, images, ...

Drag-and-dropSupport for drag and drop between Java application and a native application

Internationalization

Support for other languages

6

GUI Statics and GUI Dynamics

Statics: what's drawn on the screen

Components

buttons, labels, lists, sliders, menus, ... Containers: components that contain other components frames, panels, dialog boxes, ...Layout managers: control placement and sizing of components

Dynamics: user interactions

Events

button-press, mouse-click, key-press, ...

Listeners: an object that responds to an event

Helper classes

Graphics, Color, Font, FontMetrics, Dimension, ... 7

Creating a Window

importjavax.swing.*; public classBasic1 { public static voidmain(String[] args) { //create the window

JFrame f = newJFrame("Basic Test!");

//quit Java after closing the window f.setSize(200, 200); //set size in pixels f.setVisible(true); //show the window 8

Creating a Window Using a Constructor

importjavax.swing.*; public classBasic2 extendsJFrame { public static voidmain(String[] args) { newBasic2(); publicBasic2() { setTitle("Basic Test2!"); //set the title //quit Java after closing the window setSize(200, 200); //set size in pixels setVisible(true); //show the window 9

A More Extensive Example

importjavax.swing.*; importjava.awt.*; importjava.awt.event.*; public classIntro extendsJFrame { private intcount= 0; privateJButton myButton= newJButton("Push Me!"); privateJLabel label= newJLabel("Count: "+ count); publicIntro() { setLayout(newFlowLayout(FlowLayout.LEFT)); //set layout manager add(myButton); //add components add(label); label.setPreferredSize(newDimension(60, 10)); myButton.addActionListener(newActionListener() { public voidactionPerformed(ActionEvent e) { count++; label.setText("Count: "+ count); pack(); setVisible(true); public static voidmain(String[] args) { try{ } catch(Exception exc) {} newIntro(); 10

GUI Statics

Determine which components you want

Choose a top-level container in which to put the

components (JFrameis often a good choice)

Choose a layout manager to determine how

components are arranged

Place the components

11

Components = What You See

Visual part of an interface

Represents something with position and size

Can be paintedon screen and can receive events

Buttons, labels, lists, sliders, menus, ...

12

Component Examples

importjavax.swing.*; importjava.awt.*; public classComponentExamples extendsJFrame { publicComponentExamples() { add(newJButton("Button")); add(newJLabel("Label")); add(newJComboBox(newString[] { "A", "B", "C"})); add(newJCheckBox("JCheckBox")); add(newJSlider(0, 100)); add(newJColorChooser()); pack(); setVisible(true); public static voidmain(String[] args) { try{ } catch(Exception exc) {} newComponentExamples(); 13

More Components

JFileChooser: allows choosing a file

JLabel: a simple text label

JTextArea: editable text

JTextField: editable text (one line)

JScrollBar: a scrollbar

JPopupMenu: a pop-up menu

JProgressBar: a progress bar

Lots more!

14

Containers

A container is a componentthat

Can hold other components

Has a layout manager

Heavyweight vs. lightweight

A heavyweightcomponent interacts directly with the host system

JWindow, JFrame, and JDialogare heavyweight

Except for these top-level containers, Swing components are mostly lightweight

There are three basic top-levelcontainers

JWindow: top-level window with no border

JFrame: top-level window with border and (optional) menu bar

JDialog: used for dialog windows

An important lightweight container

JPanel: used mostly to organize objects within other containers 15

A Component Tree

JFrame

JPanel

JPanel

JPanel

JPanelJPanel

JPanel JPanel

JComboBox (mi)JComboBox (km)

JTextField (2000)

JSlider

JTextField (3226)

JSlider

JPanelJPanel

16

Layout Managers

A layout manager controls placement and sizing of components in a container If you do not specify a layout manager, the container will use a default:

JPaneldefault = FlowLayout

JFramedefault = BorderLayout

Five common layout managers:

BorderLayout, BoxLayout, FlowLayout, GridBagLayout, GridLayout General syntax: container.setLayout(new LayoutMan());

Examples:

JPanel p1 = new JPanel(new BorderLayout());

JPanel p2 = new JPanel();

p2.setLayout(new BorderLayout()); 17

Some Example Layout Managers

FlowLayout

Components placed from left to right in order added

When a row is filled, a new row is started

Lines can be centered, left-justified or right-justified (see FlowLayoutconstructor)

GridLayout

Components are placed in grid pattern (number of rows & columns specified in constructor)

Grid is filled left-to-right, then top-to-bottom

BorderLayout

Divides window into five areas: North, South, East, West, Center

Adding components

FlowLayoutand GridLayoutuse container.add(component)quotesdbs_dbs17.pdfusesText_23
[PDF] abstract writing format example

[PDF] abstraction in oop definition

[PDF] abstraction in oop java

[PDF] abstraction in oop python

[PDF] abstraction in oops with example

[PDF] abstraction in oops with example in java

[PDF] ac 120/230 v (50/60 hz) to watts

[PDF] ac 60hz to 50hz converter

[PDF] ac capacity calculation

[PDF] ac circuits problems and solutions pdf

[PDF] ac current

[PDF] ac frequency us

[PDF] ac tonnage calculation formula

[PDF] ac unit calculator

[PDF] ac2o dmap mechanism