Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.

Slides:



Advertisements
Similar presentations
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
Advertisements

CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Outline Graphics Applets Drawing Shapes Components and Containers Images.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Chapter Day 6. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 DUE Problem set 2 posted 
Chapter 3 Using Classes and Objects 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Graphical User Interfaces
A Simple Applet.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Creating GUIs in Java Using.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Review of Graphics in Java,
Object Oriented programming Instructor: Dr. Essam H. Houssein.
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.
Applets Yong Choi School of Business CSU, Bakersfield.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Lab 7: Tree & Forest. Drawing a Forest Created by Emily Hill & Jerry Alan Fails.
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.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Lab 7: BoxCar Class. Drawing a BoxCar Step 1:Create classes for Circle & Rectangle (done!) Step 2:Create a BoxCarPart class that can draw this part at.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Review_6 AWT, Swing, ActionListener, and Graphics.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Basics of GUI Programming Chapter 11 and Chapter 22.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Swing One of the most important features of Java is its ability to draw graphics.
3-1 Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as a type to declare an object reference.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Processing Timer Events
Lecture 27 Creating Custom GUIs
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
GUI AND GRAPHICS.
Steps to Creating a GUI Interface
Outline Character Strings Variables and Assignment
Lecture 4: Standard Java Graphics
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications

Agenda Create more shape classes –Ellipse –Rectangle Change applet to stand alone GUI application Created by Emily Hill & Jerry Alan Fails

Graphical Applications Except for the applets seen in Chapter 2, the example programs we've explored thus far have been text-based They are called command-line applications, which interact with the user using simple text prompts Let's examine some Java applications that have graphical components These components will serve as a foundation to programs that have true graphical user interfaces (GUIs) Copyright © 2012 Pearson Education, Inc.

GUI Components A GUI component is an object that represents a screen element such as a button or a text field GUI-related classes are defined primarily in the java.awt and the javax.swing packages The Abstract Windowing Toolkit (AWT) was the original Java GUI package The Swing package provides additional and more versatile components Both packages are needed to create a Java GUI- based program Copyright © 2012 Pearson Education, Inc.

GUI Containers A GUI container is a component that is used to hold and organize other components A frame –Container displayed as a separate window with a title bar –Can be repositioned and resized on the screen as needed A panel –Container that cannot be displayed on its own but is used to organize other components –Must be added to another container (like a frame or another panel) to be displayed Copyright © 2012 Pearson Education, Inc.

GUI Containers A GUI container can be classified as either heavyweight or lightweight A heavyweight container is one that is managed by the underlying operating system (e.g. a frame) A lightweight container is managed by the Java program itself (e.g. a panel) Copyright © 2012 Pearson Education, Inc.

Convert Picture from Applet to Stand-Alone GUI Download and import the Picture.Extended starter code from the Course Materials of Canvas. –Rename the project to PictureExtended_netID –You can copy pieces from your previous CircleApplet or Picture project to PictureApp_netid Create a copy of the Picture class –Call one PictureApp, the other PictureApplet Change Picture class –Change so it extends JPanel not JApplet –Change init method to be a default constructor –Change paint method name to paintComponent –Add a main method (see General Template on next slide) Created by Emily Hill & Jerry Alan Fails

General Template for Stand-Alone GUI public static void main(String[] args) { JFrame frame = new JFrame(”Picture Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new PictureApp(); panel.setPreferredSize(new Dimension(500,500)); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } Created by Emily Hill & Jerry Alan Fails

Create Rectangle and Ellipse Classes Create a Rectangle and an Ellipse class with: –Create fields for x & y positions, width, height, fillColor, and outlineColor –Create default constructor & constructor with parameters –Add getter & setter methods –Add a paintComponent method –Add get area & get perimeter methods Area of ellipse: Perimeter (circumference) of ellipse: Add rectangle and ellipse objects to your picture (to test your new classes) Created by Emily Hill & Jerry Alan Fails

Circle getArea public double getArea() { return Math.PI * radius * radius; } Don’t forget to test your getArea & getPerimeter methods in a main inside each shape class Created by Emily Hill & Jerry Alan Fails

Recap Created more classes –Ellipse & Rectangle –Just specified: fields, constructors, methods Change applet to stand alone GUI application –Note didn’t have to change Circle, Square, Ellipse, Rectangle, just a few changes to Picture Also briefly mentioned type promotion –Math.pow(double, double) can receive integer values because no information is lost e.g. Math.pow(3, 4) Created by Emily Hill & Jerry Alan Fails

Homework Finish lab exercise –Next lab: we will use these classes to create other classes Read Chapter 4 CodingBat Created by Emily Hill & Jerry Alan Fails