Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;

Slides:



Advertisements
Similar presentations
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Advertisements

L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Ch2: Getting Started with Java - Objectives After.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Drawing pictures with Java. JFrame: the basic Java window The swing package contains classes, objects and methods that can be used to create a consistent.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Java exercise review Lesson 25: Exercise 1, 2 and 3.
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
© A+ Computer Science - Chicken yeller = new Chicken();
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
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.
CS/ENGRD 2110 SPRING 2012 Lecture 2: Objects and classes in Java 1.
Even-Driven Programming and basic Graphical User Interface.
1 Even even more on being classy Aaron Bloomfield CS 101-E Chapter 4+
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Chapter 2 Getting Started with Java. Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Classes. Preparation Scene so far has been background material and experience –Computing systems and problem solving –Variables –Types –Input and output.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Basics of GUI Programming Chapter 11 and Chapter 22.
GUI Components. The Swing package has numerous GUI components that can be added to a window. The Swing package has numerous GUI components that can be.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
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.
Computer Programming1 Computer Science 1 Computer Programming.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
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.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Java Swing. Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: – Events:
Introducing, the JFrame Gives us a work area beside System.out.println.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
CS/ENGRD 2110 Fall 2017 Lecture 2: Objects and classes in Java
Examples of Classes & Objects
Java Swing.
CSC 113 Tutorial QUIZ I.
Classes & Objects: Examples
Chapter 8 Objects and Classes Part 1
A+ Computer Science METHODS.
Introduction to Java Programming
A+ Computer Science METHODS.
Lecture 4: Standard Java Graphics
Previous Lecture: Today’s Lecture: Reading (JV):
Presentation transcript:

Using classes

One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow; // this is called DEPENDENCY public static void method( int a) { myWindow = new JFrame( ); // CREATES = … // COMPOSITION … }

JFrame Puts graphics-capable windows on screen. JOptionPane uses JFrame Colors Fonts Drawings A frame for intuitive GUI Adds a paint method

JFrame import javax.swing.JFrame; Methods: setLocation( x, y ); setSize( height, width ); setTitle(“string”); setDefaultCloseOperation( EXIT_ON_CLOSE ); add( anotherObject );

A proper program import javax.swing.*; public class WindowDemo { private JFrame myWindow; // DEPENDENCY public WindowDemo() // all the work done in constructor { JFrame myWindow = new JFrame( ); // COMPOSITION myWindow.setLocation( 400, 200 ); myWindow.setSize(200, 100); myWindow.setTitle("HELLO"); myWindow.setDefaultCloseOperation( myWindow.EXIT_ON_CLOSE ); myWindow.setVisible( true ); } public static void main(String args [ ]) // not considered part of the class { WindowDemo app = new WindowDemo(); } // end main } //end class

JButton import javax.swing.JButton; can be “added” to JFrame

String yes, it’s not just a variable, it’s a class with methods. String testStr = new String( “ ” ); testStr = JOptionPane.showInputDialog("enter a string"); System.out.println( testStr.concat("ing") ); System.out.println( testStr.toLowerCase() ); System.out.println( testStr.toUpperCase() ); System.out.println( testStr.indexOf( "s" ) ); System.out.println( testStr.replace('s', 'q')); if ( testStr.equalsIgnoreCase("exit") == true ) { System.out.println("exiting"); System.exit(0); }

Math class look it up

Random class look it up

Date class look it up Date today = new Date(); System.out.println( today );

Objects As Containers of Information

Objects don’t always DO things Sometimes they just HOLD things (information) The Color class can hold color information The Point class can hold cartesian coordinate information The Container class contains 10,000 variables that describe your computer

Color class holds a color value (nothing more) e.g Color boxColor; // DEPENDENCY boxColor = new Color( ); // COMPOSITION boxColor = Color.blue; // ASSIGNMENT then boxColor can be used to set System properties in Classes/Objects that need color (more later).

JColorChooser – returns a Color object to the caller

Returns an Object? JColorChooser fills in all of the information in a blank object of the Color class, and copies it to the Color object in the calling statement: boxColor = JColorChooser.showDialog( null, Greeting, default color );

How is boxColor given the value “Color.blue” contained in the Jframe library? private Color boxColor; boxColor = new Color( ); boxColor = Color.blue; Color.pink Color.red Color.green Color.blue COMPOSITION: creates an Object… ready for Value ASSIGNMENT: Color.blue copied from Jframe library and assigned to boxColor Computer Memory Space JFrame library DEPENDENCY: reserves the name, sets public of private domain