Introducing, the JFrame Gives us a work area beside System.out.println.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Chapter 71 Inheritance Chapter 7. 2 Reminders Project 4 was due last night Project 5 released: due Oct 10:30 pm Project 2 regrades due by midnight.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
A Simple Applet.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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.
Programming Task: Task 1 Controlled Assessment Practice.
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.
Applets Java API.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
JAPPLET.
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.
TCU CoSc Introduction to Programming (with Java) Variables and Methods.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
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.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Even-Driven Programming and basic Graphical User Interface.
1 Even even more on being classy Aaron Bloomfield CS 101-E Chapter 4+
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
Programming in Java CSCI-2220 Object Oriented Programming.
© 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.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
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.
BallWorld.java Ball.java A functional walkthrough Part 3: the interaction of objects.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
Variables and Methods Chapter 3 – Lecture Slides.
Basics of GUI Programming Chapter 11 and Chapter 22.
Java Swing One of the most important features of Java is its ability to draw graphics.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Java exercise review Lesson 26: Exercise 4. Exercise #4 – a sample solution 1.Write the psudocode and the deployment diagram for what you are planning.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Introduction to Graphics
Java Graphics.
A First Look at GUI Applications
GUI AND GRAPHICS.
Inheritance Chapter 7 Chapter 7.
UNIT-5.
A+ Computer Science METHODS.
A+ Computer Science METHODS.
Lecture 4: Standard Java Graphics
Presentation transcript:

Introducing, the JFrame Gives us a work area beside System.out.println

Many ways to make use of classes Dependency new JFrame( ); Realization public class FishClass implements IFishBehavior Association - passed into a method public A ( B b ) { _b = b; }

One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow; public static void method( int a) { myWindow = new JFrame( ); … }

third way: public class myClass extends JFrame { // your class inherits all of JFrame’s // methods }

Extension, Hierarchy, and Inheritance

Extends – in the class statement, tells which larger class serves as the “parent”. Inheritance – the child class inherits methods and variables from the parent class Hierarchy - parent to child relationship

Extend keyword public class myClass extends someOtherClass { // I can use all the methods and // variables from someOtherClass in myClass. }

Other terms Parent / Child Base class / Sub class Super Class / Sub class Any class (not just an imported library class) can be a parent or base class. Write classes – then write new inherited classes for targeted capabilities.

Java common inherited classes public class myClass extends JFrame - myClass gets a whole bunch of methods for displaying windows on-screen including the ability to launch a paint( ) method. public class myClass extends Applet - applet and browser graphics public class myClass extends Object - the parent of ALL classes, usually omitted

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

Use these helper libraries import javax.swing.JFrame ; // for JFrame import java.awt.* ; // for painting and animation import java.awt.event.* ; // for “event” handling, more later import java.util.Random ; // always useful

some JFrame methods setLocation(100,200); setSize(250,250); setVisible(true); setDefaultCloseOperation ( EXIT_ON_CLOSE) paint (Graphics g)

public class WindowClass extends JFrame { public WindowClass ( ) { setLocation(100,200); setSize(250,250); setVisible(true); } // end MainClass constructor } // end class

public class WindowClass extends JFrame { public WindowClass ( int x, int y ) { setLocation( x, y ); setSize(250,250); setVisible(true); } // end MainClass constructor } // end class

public static void main (String[] args) { new WindowClass( 200, 200 ); } // end main method

Demo

If you don’t extend JFrame…. public class WindowClass { public WindowClass ( ) { JFrame myFrame = new JFrame( ); myFrame.setLocation(100,200); myFrame.setSize(250,250); myFrame.setVisible(true); } // end MainClass constructor } // end class

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 Like the String class, and Integer class, does not use the new keyword. holds a color value (nothing more) e.g Color boxColor = new Color( ); boxColor = Color.blue; or Color boxColor = Color.blue 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 );

a clarification Color boxColor = Color.blue or Color boxColor = new Color( ); boxColor = Color.blue;object t to box Color.

Color boxColor = Color.blue Color.pink Color.red Color.green Color.blue JFrame library Computer Memory Space

Color boxColor = new Color( ); boxColor = Color.blue; Color.pink Color.red Color.green Color.blue ready for Color Color.blue Computer Memory Space

the this qualifier Means “this object, the one that we’re in”. Used when a call to a method, especially in a child, needs to specify which object the method should act upon. this always refers to an object of some type.

the super qualifier refers to the parent class the command super calls the parent’s constructor super.MethodName can call any method in the parent.

graphics on “your computer” Since there are many computers (types, instances).... and since the programs that you write should run anywhere.... then the programs that you write, should retrieve and use information native to the computer that it is running on. This is called “context awareness”

The paint Method Computer runs it repeatedly (you don’t), but then you can run it by calling repaint();. The computer passes it an object of the Graphics Class, of it’s own making.

public void paint (Graphics g) { // the computer calls the paint program // automatically whenever an event requires // the screen to be redrawn }

An “event” The user does anything: moves the mouse, moves the window, hits a key, etc.

Graphics! g.setColor g.fillRect g.drawString g.drawPolygon hundreds of methods that use your computer’s graphics capability

demo A Frank Lloyd Wright style generator