AWT Components.

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
More Advanced AWT Last week, you learned about Applets, Lists, and Buttons AWT provides several other “widgets” and tools: –Labels –Choice boxes –Check.
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.
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.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
1 Review of applets & Computer Graphis GUILecture 6 Review of Applets & Compute Graphics GUI Overview  Introduction to Graphics. Applets: a quick review.
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.
Graphical User Interfaces (GUI) Abstract Windows Toolkit (AWT): java.awt GUI elements: Primitive Button, Label, Checkbox, Scrollbar, etc. Container Panel,
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
Web Design & Development Lecture 18. Java Graphics.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
Chapter 12: The Abstract Window Toolkit Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 12.
Chapter 13 Java AWT – Part II (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
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.
Chapter 8: Getting Started with Graphics Programming Graphics Class Hierarchy Graphics Class Hierarchy Frames Frames The relationship between frame and.
C13a, AWT Create, display, facilitate user interaction with window objects software framework: a way of structuring generic solutions to common problems.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Objectives of This Session
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Layout Managers Arranges and lays out the GUI components on a container.
1 Windows program example import java.awt.*; import java.awt.event.*; public class wpexample extends Frame { public wpexample(String title) { super(title);
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.
CS102 – GUI AWT & Swing Components & Containers, Layout Managers, Events & Listeners MVC design pattern. David Davenport.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
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.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Csc Basic Graphical User Interface (GUI) Components.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Chapter 12: The Abstract Window Toolkit Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 12.
1 IM103 week 8 (C&K ch17, p412) Advanced graphic programming Learning objectives By the end of this chapter you should be able to:  create dialogue windows.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
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.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
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.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Chapter 4: Laying out the GUI Useful containers –Panels –Frames –Dialogs Layout mechanisms –FlowLayout –BorderLayout –GridLayout –CardLayout Menus.
GUI building with the AWT
Abstract Window ToolKit (AWT)
Swing Advanced HCI (IAT 351)
Chap 7. Building Java Graphical User Interfaces
JAVA AWT.
AWT.
AWT Components and Containers
GUI building with the AWT
Graphics Programming - Frames
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
Menu Bars and Menus.
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:

AWT Components

Using AWT Components Component Component MenuComponent TextComponent Canvas Scrollbar Button Checkbox Label List Choice TextComponent TextArea TextField Component Container Panel Window Dialog FileDialog Frame MenuComponent MenuItem Menu

Frame import java.awt.*; public class TestFrame extends Frame { public TestFrame(String title){ super(title); } public static void main(String[] args){ Frame f = new TestFrame("TestFrame"); f.setSize(400,400); f.setLocation(100,100); f.show();

How to Use Buttons? public class TestButton extends Frame { public TestButton(String title){ super(title); Button hw = new Button("Hello World!"); add(hw); } ….

How to Use Labels? public class TestLabel extends Frame { public TestLabel(String title){ super(title); Label label1 = new Label(); label1.setText("Label1"); Label label2 = new Label("Label2"); label2.setAlignment(Label.CENTER); Label label3 = new Label("Label3");   add(label1,"North"); add(label2,"Center"); add(label3,"South"); }

How to Use Checkboxes? public class TestCheckbox extends Frame { public TestCheckbox(String title){ super(title);   CheckboxGroup cbg = new CheckboxGroup(); Checkbox cb1 = new Checkbox("American Express",cbg,false); Checkbox cb2 = new Checkbox("Visa",cbg,false); Checkbox cb3 = new Checkbox("Mastercard",cbg,true); add(cb1,"North"); add(cb2,"Center"); add(cb3,"South"); } …

How to Use Choices? public class TestChoice extends Frame { public TestChoice(String title){ super(title);   Choice choice = new Choice(); choice.add("ichi"); choice.add("ni"); choice.add("san"); add(choice); }

How to Use TextField & TextArea public class TestText extends Frame { public TestText(String title){ super(title);   TextField textField = new TextField(20); TextArea textArea = new TextArea(5, 20); textArea.setEditable(false); textField.setText("TextField"); textArea.setText("TextArea Line1 \n TextArea Line2"); add(textField,"North"); add(textArea,"South"); } …

How to Use Lists? public class TestList extends Frame { public TestList(String title){ super(title); List l = new List(2, true); //prefer 2 items visible l.add("zero"); l.add("uno"); l.add("dos"); l.add("tres"); l.add("cuatro"); l.add("cinco"); l.add("seis"); l.add("siete"); l.add("ocho"); l.add("nueve"); add(l); }

How to Use Menus? public class TestMenu extends Frame { public TestMenu(String title){ super(title);   MenuBar mb = new MenuBar(); setMenuBar(mb); Menu m1 = new Menu("Menu 1"); mb.add(m1); MenuItem mi1_1 = new MenuItem("Menu Item 1_1"); m1.add(mi1_1); m1.addSeparator(); MenuItem mi1_2 = new MenuItem("Menu Item 1_2"); m1.add(mi1_2); Menu m2 = new Menu("Menu 2"); // mb.add(m2); m1.add(m2); MenuItem mi2_1 = new CheckboxMenuItem("Menu Item 2_1"); m2.add(mi2_1); } …

How to Use Canvases and Graphics Primitives? For drawing geometric shapes, texts, and images An abstract class the extended class must override paint() Line RoundRectangle Polygon Oval Rectangle Arc

drawLine(x1,y1,x2,y2) class MyCanvas extends Canvas { public void paint(Graphics g){ g.setColor(Color.blue); int x1 = 161, y1 = 186, x2 = 181, y2 = 206; g.drawLine(x1,y1,x2,y2); } (x1,y1) (x2,y2)

fillOval(x,y,w,h) drawOval(x,y,w,h) g.setColor(Color.blue); { int x = 239, y = 186, w = 48, h = 32; g.fillOval(x,y,w,h); }

fillPolygon(int[] xs, int[] ys) drawPolygon(int[] xs, int[] ys) g.setColor(Color.green); { int xs[] = {161,161,185,209,185,161}; int ys[] = {310,334,358,334,310,310}; g.fillPolygon(xs,ys,6); }

fillRect(x,y,w,h) drawRect(x,y,w,h) g.setColor(Color.pink); { int x = 239, y = 248, w = 48, h = 32; g.fillRect(x,y,w,h); }

fillRoundRect(x,y,w,h,rw,rh) drawRoundRect(x,y,w,h,rw,rh) g.setColor(Color.yellow); { int x = 161, y = 248, w = 48, h = 32, roundW = 25, roundH = 25; g.fillRoundRect(x,y,w,h,roundW,roundH); }

fillArc(x,y,w,h,sa,a) drawArc(x,y,w,h,sa,a) g.setColor(Color.orange); { int x = 239, y = 310, w = 48, h = 48, startAngle = 20, angle = 90; g.fillArc(x,y,w,h,startAngle,angle); }

drawString(s,x,y) FontMetrics

drawString, Font, & FontMetrics class MyCanvas extends Canvas { public void paint(Graphics g){ g.setFont(new Font("Dialog",0,20)); FontMetrics fm = g.getFontMetrics(); int x = 100; int y = 100; g.drawString("Hello",x,y); y = y+fm.getHeight(); g.drawString("World",x,y); }

drawImage(image,x,y,w,h,ob) Image im = Toolkit.getDefaultToolkit().getImage(name); g.drawImage(im, x, y, w, h, observer);

drawImage public class TestImage extends Frame { Image im;   public TestImage(String title){ super(title); im = Toolkit.getDefaultToolkit().getImage("jp2.jpg"); if (im==null){ System.out.println("No image"); System.exit(0); } public void paint(Graphics g){ g.drawImage(im,0,0,im.getHeight(this),im.getWidth(this),this); …

Layout of Components BorderLayout FlowLayout CardLayout GridLayout north, south, west, east & center FlowLayout left to right & top down CardLayout stack of panels GridLayout tabular form (rows & columns) GridBagLayout tabular form(variable row heights and column widths)

Use Layout Managers Default layout managers Windows (Frames & Dialogs) setLayout(new BorderLayout()); setLayout(new CardLayout(()); setLayout(new FlowLayout()); setLayout(new GridLayout(rows,columns,xgap,ygap)); Default layout managers Windows (Frames & Dialogs) BorderLayout Panels (Applets) FlowLayout

How to Use BorderLayout? import java.awt.*; public class TestBorderLayout { public static void main(String[] args){ Frame f = new Frame("TestBorderLayout"); f.setSize(200,200); f.add("North", new Button("North")); f.add("South", new Button("South")); f.add("East", new Button("East")); f.add("West", new Button("West")); f.add("Center", new Button("Center")); f.setVisible(true); }

How to Use FlowLayout? import java.awt.*; public class TestFlowLayout { public static void main(String[] args){ Frame f = new Frame("TestFlowLayout"); f.setSize(200,200); f.setLayout(new FlowLayout()); f.add(new Button("Button 1")); f.add(new Button("Button 2")); f.add(new Button("Button 3")); f.add(new Button("Button 4")); f.add(new Button("Button 5")); f.setVisible(true); }

How to Use CardLayout? import java.awt.*; public class TestCardLayout { public static void main(String[] args){ Frame f = new Frame("TestCard Layout"); f.setSize(200,200); f.setLayout(new CardLayout()); f.add("GraphicsPanel",new GraphicsPanel()); f.add("LabelPanel",new LabelPanel()); f.add("ButtonPanel",new ButtonPanel()); f.setVisible(true); }

How to Use GridLayout? import java.awt.*; public class TestGridLayout { public static void main(String[] args){ Frame f = new Frame("TestGridLayout"); f.setSize(200,200); f.setLayout(new GridLayout(2,3)); f.add(new Button("Button 1")); f.add(new Button("Button 2")); f.add(new Button("Button 3")); f.add(new Button("Button 4")); f.add(new Button("Button 5")); f.setVisible(true); }