By Dr. Jiang B. Liu 3. Graphic User Interface using AWT.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
Graphical User Interfaces
Java Software Development Paradigm Lecture # 12. Basics of GUI.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
For Computational Finance Java Applets and the AWT Jeff Stephenson (slides adapted from Manu Kumar)
James Tam An Introduction To Graphical User Interfaces The event-driven model Building simple graphical interfaces in Java.
Abstract Windowing Toolkit Design Goal: –allow the programmer to build o GUI that looks good on all platforms –provide a well-designed object-oriented.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
LayoutManager, J 1 Layout Manager. LayoutManager, J 2 Layout Manager To each UI container there is a layout manager (an object). When you add a component.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Java Computing 6. RMI By Dr. Jiang B. Liu
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
9/21/99www.cs.vt.edu/wwtut/1 Introduction To Abstract Windowing Toolkit (AWT) Part 3 – AWT Marc Abrams Virginia Tech CS Dept courses.cs.vt.edu/wwwtut/
Fall 1998CSE 4701 Graphics in Java CSE470 Fall 1998 Thanks to Aaron Malenfant for providing the original slides. The slides have been slightly modified.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java Software Solutions Lewis and Loftus Chapter 10 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Graphical User Interfaces --
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java Programming 1 Java Programming II Events, AWT, and Swing.
C13a, AWT Create, display, facilitate user interaction with window objects software framework: a way of structuring generic solutions to common problems.
Cs884(Prasad)java12AWT1 Abstract Windowing Toolkit Support for Graphical User Interface (Event-driven programming)
Objectives of This Session
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
CS100A, Fall Lecture, 4 Nov. 1 CS100A, Fall 1997 Lecture 4 November: OTHELLO Goals: Introduce you to assignment 8. Let you have fun with the game.
1 Lesson: Applets with User Input and Output with GUI ICS4M.
Layout Managers Arranges and lays out the GUI components on a container.
CS100A, Lecture 16, 27 October CS100A Lecture October 1998 Assignment 7: A Checker-playing program: learning about GUIs and working with a.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Csc Basic Graphical User Interface (GUI) Components.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
Graphical User Interfaces (GUI). PART ONE About GUI’s.
Chapter 12: The Abstract Window Toolkit Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 12.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Session 10. Java Simplified / Session 10 / 2 of 36  An Applet is a Java program that can be executed with the help of a Java enabled browser.  Every.
import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
Java Programming (By Rama Bhadra Rao M) You can Trace me in Day 5
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
CSC 205 Programming II Lecture 5 AWT - I.
GUI building with the AWT
Java Swing.
AWT Components.
AWT.
GUI building with the AWT
Steps to Creating a GUI Interface
Programming Graphical User Interface (GUI)
GUI building with the AWT
AWT Components Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e.
Presentation transcript:

By Dr. Jiang B. Liu 3. Graphic User Interface using AWT

Using the AWT Components The following figures show the inheritance hierarchies for all the AWT component classes.

The "Hello Bradley" Applet (with AWT component: button and TextComponent) … public class HelloGUIApplet extends Applet { Button b1, b2; TextField textField; TextArea textArea; public void init() { textField=new TextField("Hello, Bradley!", 20); add(textField); textArea = new TextArea(5, 20); add(textArea); b1 = new Button(); b1.setLabel("Send"); b2 = new Button("Exit"); add(b1); add(b2); }

The "Hello Bradley" Applet (with AWT component: button and TextComponent)... public boolean action(Event e, Object arg) { Object target = e.target; if (target == b1) { //They clicked "send button" String text = textField.getText(); textArea.appendText(text + "\n"); return true; } if (target == b2) { //They clicked "exit button" System.exit(0); return true; } return false; }

The "Hello Bradley" Application (with AWT component: button and TextComponent) … public class HelloGUI extends Frame {//vs. Applet Button b1, b2; TextField textField; TextArea textArea; public HelloGUI() { //vs. init() super("Hello GUI Application"); setLayout(new FlowLayout()); textField = new TextField("Hello, Bradley!", 20); add(textField); textArea = new TextArea(5, 20); add(textArea); b1 = new Button(); b1.setLabel("Send"); add(b1); b2 = new Button("Exit"); add(b2); }

The "Hello Bradley" Application (with AWT component: button and TextComponent) public boolean action(Event e, Object arg) { Object target = e.target; if (target == b1) { //They clicked "send button" String text = textField.getText(); textArea.appendText(text + "\n"); return true; } if (target == b2) { //They clicked "exit button" System.exit(0); return true; } return false; } public static void main(String args[]) { HelloGUI hFrame = new HelloGUI(); hFrame.pack(); hFrame.resize(200, 200); hFrame.show(); }

The "Hello Bradley" Application (with BorderLayout manager) public class HelloGUILayout1 extends Frame { Button b1, b2; TextField textField; TextArea textArea; Label infoField; public HelloGUILayout1() { super("Hello GUI Application"); setLayout(new BorderLayout()); textField = new TextField("Hello, Bradley!", 20); add("North", textField); textArea = new TextArea(5, 20); add("Center", textArea); b1 = new Button(); b1.setLabel("Send"); add("East", b1); b2 = new Button("Exit"); add("West", b2); infoField = new Label("BorderLayout Demo"); add("South", infoField); }

The "Hello Bradley" Application (with GridLayout manager) public class HelloGUILayout2 extends Frame { Button b1, b2; TextField textField; TextArea textArea; Label infoField; public HelloGUILayout2() { super("Hello GUI Application"); setLayout(new GridLayout(3,2)); textField = new TextField("Hello, Bradley!", 20); add(textField); b1 = new Button(); b1.setLabel("Send"); add(b1); textArea = new TextArea(5, 20); add(textArea); b2 = new Button("Exit"); add(b2); infoField = new Label("GridLayout Demo"); add(infoField); }

The "Hello Bradley" Application (with GridBagLayout manager)... GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; textField = new TextField("Hello, Bradley!", 20); gbl.setConstraints(textField, gbc); add(textField); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 2; gbc.gridheight = 1; textArea = new TextArea(5, 20); gbl.setConstraints(textArea, gbc); add(textArea); … }

The "Pizza" Application public class Pizza extends Frame { // AWT Checkbox components CheckboxGroup sizeCBG; Checkbox smallCheckbox; Checkbox mediumCheckbox; Checkbox largeCheckbox;... public Pizza() { … // create the Pizza size checkbox area sizeCBG = new CheckboxGroup(); smallCheckbox = new Checkbox("Small", sizeCBG, true); smallCheckbox.reshape(10, 30, 120, 40); add(smallCheckbox); mediumCheckbox = new Checkbox("Medium",sizeCBG,false); mediumCheckbox.reshape(140, 30, 120, 40); add(mediumCheckbox); largeCheckbox = new Checkbox("Large", sizeCBG, false); largeCheckbox.reshape(270, 30, 120, 40); add(largeCheckbox);

The "Pizza" Application public class Pizza extends Frame { // AWT List and choice Components List toppingList; Choice typeChoice;... public Pizza() { // create the Pizza toppings list toppingList = new List(6,true); toppingList.addItem("Mushroom");... toppingList.addItem("Toufu"); toppingList.reshape(10,70,160,70); add(toppingList); // create the Pizza type choice typeChoice = new Choice(); typeChoice.addItem("Thin Crust");... typeChoice.addItem("Stuff"); typeChoice.reshape(200,70,160,20); add(typeChoice);

The "Pizza" Application public class Pizza extends Frame {... public Pizza() { // Order info text fields Label l = new Label("Name", Label.RIGHT); l.reshape(10, 160, 80, 30);add(l); nameField = new TextField(); nameField.reshape(100, 160, 260, 30); add(nameField); l = new Label("Address", Label.RIGHT); l.reshape(10, 200, 80, 30);add(l); addressField = new TextField(); addressField.reshape(100, 200, 260, 30); add(addressField); l = new Label("Phone #", Label.RIGHT); l.reshape(10, 240, 80, 30); add(l); phoneField = new TextField(); phoneField.reshape(100, 240, 260, 30); add(phoneField);...

The "Pizza" Application public boolean action(Event evt,Object obj){ if(evt.target == sendButton){ // get customer order String order= new String(); order = nameField.getText(); order += "|";... // determine the order if(smallCheckbox.getState()) { order += "Small"; order += "|";... // get toppings String toppings[] = new String[6]; toppings = toppingList.getSelectedItems(); for (int i = 0; i < toppings.length; i++) { order += toppings[i]; order += " "; }... // send the order to the server statusArea.setText("Sending Order: \n" + order); }