C13b, AWT cont.. Panel Container that acts like a Component Can be added into other components (like Frames, other Panels) private Panel makeScrollBars()

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

Graphical User Interfaces (Part IV)
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
CSE 341, S. Tanimoto Java-PolyDraw- 1 A Java Case Study: An Applet for Drawing Polygons Motivation -- See a number of AWT features integrated. Get ideas.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Graphical User Interface Bonus slides Interaction Between Components & Drawing.
Swing: the art of the GUI COMP204, Bernhard Pfahringer.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Carnegie Mellon University, MISM1 Java GUI programming and Java Threads GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann Thread.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Lecture 19 Graphics User Interfaces (GUIs)
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
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 © Walter Milner 2005: Slide 1 Java Swing Walter Milner.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
Applets, AWTS CompSci 230 Software Construction.
Using Inheritance to Customize Frames Use inheritance for complex frames to make programs easier to understand Design a subclass of JFrame Store the components.
Veri Transferi Kes ve Yapıştır 1. import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; /** * This program demonstrates how to add.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
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 GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
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.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
Cs884(Prasad)java12AWT1 Abstract Windowing Toolkit Support for Graphical User Interface (Event-driven programming)
Programming and Problem Solving With Java Copyright 1999, James M. Slack Graphics in Java Applications The Graphics Class The Canvas Class The MouseListener.
Objectives of This Session
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Event Handling.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Chapter 10 Event Handling.
Computer Science 209 GUIs Model/View/Controller Layouts.
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.
Java Swing One of the most important features of Java is its ability to draw graphics.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Advanced Java Class Events. change in state initiated by system or user java.util.EventObject java.awt.event java.swing.event.
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.
Menus and Toolbars CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Java Swing. Note - this presentation.. often needs to refer to source code which is too big to put on a slide So the source code is in a separate Word.
A Quick Java Swing Tutorial
CSC 205 Programming II Lecture 5 AWT - I.
GUI building with the AWT
Advanced GUIs II CS Lecture
GUIs Model/View/Controller Layouts
AWT Components.
Abstract Window ToolKit (AWT)
Swing Advanced HCI (IAT 351)
AWT Components and Containers
GUI building with the AWT
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Programming Graphical User Interface (GUI)
Menu Bars and Menus.
Advanced GUIs II CS Lecture
Presentation transcript:

C13b, AWT cont.

Panel Container that acts like a Component Can be added into other components (like Frames, other Panels) private Panel makeScrollBars() { Panel p = new Panel(); p.setLayout(new BorderLayout()); p.add(“West”,redBar); p.add(“Center”,greenBar); p.add(“East”,blueBar); return p; }

ScrollPane Can hold exactly one other component (  no LayoutManager) Automatic scrollbars if Component larger than ScrollPane class BigCanvas extends Frame { public static void main(String[] args) { BigCanvas w = new BigCanvas(); w.show(); } private Polygon poly = new Polygon(); private Canvas cv = new Canvas(); …

public BigCanvas() { setSize(300,300); setTitle(“Scroll Pane Test”); cv.setSize(1000,1000); cv.addMouseListener(new MouseKeeper()); ScrollPane sp = new ScrollPane(); sp.add(cv); add(“Center”,sp); } public void paint(Graphics g) { Graphics gr = cv.getGraphics(); gr.drawPolygon(poly); } private class MouseKeeper extends MouseAdapter { public void mousePressed(MouseEvent e) { poly.addPoint(e.getX(),e.getY()); repaint(); }}}

Case study: Color display private class BrightenButton extends Button implements ActionListener { private int index; public BrightenButton(int i) { super( i == 0 ? “brighter” : “darker”); index = i; addActionListener(this); } public void actionPerformed(ActionEvent e) { setFromColor(index == 0 ? current.brighter(): current.darker()); }

Dialogs Special purpose window displayed shortly To notify, or ask simple questions Always attached to a Frame Modal: demands user response, prevents further actions; show() won’t return until dismissed,  setVisible(false) Nonmodal: actions often placed into separate Thread Dialog dig = new Dialog(this,false);

class Dialog extends Frame { static public void main(String[] args) { DialogTest w = new DialogTest(); w.show();} private TextArea d = new TextArea(); private Checkbox cb = new Checkbox(“Modal Dialog?”); public DialogTest() { setTitle(“Dialog Test Program”); setSize(300,220); add(“West”,cb); add(“East”, new MakeButton()); add(“South”,d); } private class MakeButton extends ButtonAdapter { public MakeButton() { super(“Make Dialog”); } public void pressed() { makeDialog(cb.getState());} }

private void makeDialog(boolean modalFlag) { final Dialog dlg = new Dialog(this,modalFlag); dlg.setSize(100,100); dlg.add(“North”,new CountButton(1)); dlg.add(“West”,new CountButton(2)); dlg.add(“East”,new CountButton(3)); dlg.add(“South”, new ButtonAdapter(“Hide”) { public void pressed() {dlg.setVisible(false);}}); dlg.show(); } private class CountButton extends ButtonAdapter { public CountButton(int val) {super(“” + val);} public void pressed() {d.append(“Button “ + getLabel() + “ pressed\n”); }}}

MenuBar Not subclass of component, but graphical! Attached to Frame by setMenuBar(): MenuBar bar = new MenuBar(); setMenuBar(bar); Add menus: Menu HelpMenu = new Menu(“Help”); bar.add(helpMenu); Add menu items: MenuItem quitItem = new MenuItem(“Quit”); quitItem.addActionListener(new QuitListener()); helpMenu.add(quitItem);

class QuitItem implements ActionListener { private void m1(MenuItem mItem) { mItem.addActionListener(this); } private void m2(Menu menu) { MenuItem mItem = new MenuItem(“Quit”); m1(mItem); menu.add(mItem); } private void m3(MenuBar mBar) { Menu menu = new Menu(“Quit”); mBar.add(menu); m2(menu); } private void m4(Frame application) { MenuBar mBar = new MenuBar(); application.setMenuBar(mBar); m3(mBar); }

public QuitItem(Frame application) {m4(application);} public QuitItem(MenuBar mBar) {m3(mBar);} public QuitItem(Menu menu) {m2(menu);} public QuitItem(MenuItem mItem) {m1(mItem);} public void actionPerformed(ActionEvent e) {System.exit(0);} Use like in: class ColorTest extends Frame { … public ColorTest() { … new QuitItem(this); … }}