GUIs Part 4 CS221 – 4/17/09. Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software –

Slides:



Advertisements
Similar presentations
Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Advertisements

Designing Classes Chapter 8. Classes Collection of objects Objects are not actions Class names – Nouns Method names – Verbs What Makes a Good Class Represent.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
1 Lecture 2 Java Packages  What are Java packages?  Why do wee need packages?  How to create a Java package?  Some examples.
Java Library Java provides a huge library or collection of useful programs A gold mine of well-tested code that can save you countless hours of development.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
Java Packages and Libraries M Taimoor Khan
Applets and Frames CS 21a: Introduction to Computing I First Semester,
The Java Programming Language
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Static. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A static method does not operate on an object double dY.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
CS Lecture 00 Swing overview and introduction Lynda Thomas
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Chapter 5 Introduction to Defining Classes
More Object Concepts— Farrell, Chapter 4 Dr. Burns.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Packages. The main feature of OOP is its ability to support the reuse of code: –Extending the classes –Extending interfaces The features in basic form.
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
Libraries and APIs Don’t reinvent the wheel. What’s an API? API – Application Programmers Interface –We want to use code someone else has written –API’s.
April 20, 1998CS102-02Lecture 4-1 A Method to the Madness CS Lecture 4-1 Java's Work Horses.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Console Input and Output JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
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.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Lecture 5:Interfaces and Abstract Classes
Chapter 3 Syntax, Errors, and Debugging
Inheritance-Basics.
Software Development Java Classes and Methods
More About Objects and Methods
Classes, Libraries & Packages
Java Basics Packages.
MSIS 655 Advanced Business Applications Programming
Applying OO Concepts Using Java
Constructors, GUI’s(Using Swing) and ActionListner
Using java libraries CGS3416 spring 2019.
Chapter 6 Objects and Classes
Interfaces,Packages and Threads
Presentation transcript:

GUIs Part 4 CS221 – 4/17/09

Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software – ID=83c3a1ec-ed72-4a db0192b&displaylang=en ID=83c3a1ec-ed72-4a db0192b&displaylang=en Assignment #3 – Implement any one of your sorting algorithms using C# instead of Java To get credit for both assignments: – Send me your working C# project in – If it compiles and works you’ll get full credit

What we’ll cover today Quick Review – Java Class Library – Packages More SWING Programming

Java Class Library Java includes over 3000 classes for your use! Almost entirely written in Java These classes help with a variety of common tasks – Managing lists of objects – String parsing – GUI programming You access through the use of classes grouped by packages

Packages Classes are grouped together with packages Why packages? – Provides hierarchical organization to classes – Solves the problem of class name collision All java packages start with java or javax – 3 rd party developers (like you) can create other package names

Example Packages Java.lang – fundamental classes to the language, e.g. string, process, thread, etc Java.io – data streams, serialization and file system Java.net – support for building networking applications Java.awt – basic GUI support Javax.swing – built on awt adds more GUI features Java.sql – access to SQL databases

Many More

Using Packages Import statement tells the compiler you want to use a class – E.g.: import java.awt.* – * symbol indicates you want to import all sub- packages within the java.awt package. java.lang is special. Every java program automatically imports this package.

Using Packages You can reference a class without the import – E.g. new java.awt.Color(0,0,0); Not recommended, using import is better for: – Readability – Makes it easy to understand what classes your program depends upon Under what condition would you want to reference a class without an import statement?

Class Methods Constructor – Used to manufacture new instances of a class Instance – Associated with a specific instance of an object – Object must be instantiated (created) for an instance method to be called Static – Applied to a class as a whole, rather than to an instance – Can be called without instantiating the class

Examples Constructor – Declaration: public Math() – Usage: Math math = new Math(); Instance – Declaration: public int abs(int x) – Usage: Math math = new Math(); math.abs(-5); Static – Declaration: public static int abs(int x) – Usage: Math.abs(-5);

Constants Constants are variables whose values cannot change Many classes define constants These are declared as: – Static, value is associated with the class – Final, value cannot change For example the Color class defines – static final Color BLACK

Constants Use class defined constants to improve readability – setFillColor(Color.RED) – area = Math.PI * radius * radius How to declare your own constants – Use all caps PI, BLACK, RED, etc. – Use underscores if necessary NUMBER_OF_MONTHS – Assign value at declaration public static final float PI = (float) 22/7;

Variable and Method Access

Back to SWING Let’s turn this: Into this:

Let’s see how to do this

Problems How to draw freely on the screen? – Extend JComponent – paintComponent(Graphics g) How to randomly place a circle in our component – Math.random() – getWidth, getHeight

Let’s make it better

Problems How to capture mouse events? – Implements MouseListener – addMouseListener – mousePressed(MouseEvent e)

Think About How would we: – Keep drawing circles as long as the mouse is clicked? – Allow the user to select a circle and drag it somewhere else? What can we use to figure it out?