Introduction to Computer Science I

Similar documents
An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Computational Expression

G51PRG: Introduction to Programming Second semester Applets and graphics

CSC System Development with Java Introduction to Java Applets Budditha Hettige

Using the API: Introductory Graphics Java Programming 1 Lesson 8

CHAPTER 2. Java Overview

Java Applet Basics. Life cycle of an applet:


Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

PROGRAMMING LANGUAGE 2

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

IT101. Graphical User Interface

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

Graphical User Interface (GUI)

CS1004: Intro to CS in Java, Spring 2005

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Data Representation and Applets

Building Java Programs

Applets and the Graphics class

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Graphical User Interface (GUI)

Data Representation and Applets

CT 229 Arrays in Java

Data Representation and Applets

Garfield AP CS. Graphics

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Java - Applets. public class Buttons extends Applet implements ActionListener

Graphical User Interfaces (GUIs)

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components

Lecture 5: Java Graphics

Chapter 12 Advanced GUIs and Graphics

1. What is Jav a? simple

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Component Based Software Engineering

Java Applet & its life Cycle. By Iqtidar Ali

Graphic User Interfaces. - GUI concepts - Swing - AWT

Building Java Programs

Programming graphics

Building Java Programs

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

Lecture 3: Java Graphics & Events

Topic 8 graphics. -mgrimes, Graphics problem report 134

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Using Graphics. Building Java Programs Supplement 3G

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Chapter 2 Using Objects. Types. Number Literals. A type defines a set of values and the operations that can be carried out on the values Examples:

Chapter 3 - Introduction to Java Applets

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Here is a list of a few of the components located in the AWT and Swing packages:

CSC 1214: Object-Oriented Programming

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

Java. GUI building with the AWT

Part 3: Graphical User Interface (GUI) & Java Applets

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

TWO-DIMENSIONAL FIGURES

9. APPLETS AND APPLICATIONS

Week 3. parameters, return, math, graphics

Chapter 14: Applets and More

Advanced Internet Programming CSY3020

Lecture Static Methods and Variables. Static Methods

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

CSE 331 Software Design & Implementation

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to Computer Science I

CISC 1600 Lecture 3.1 Introduction to Processing

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

Building Java Programs

Topic 8 Graphics. Margaret Hamilton

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

CIS 162 Project 1 Business Card Section 04 (Kurmas)

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

Computer Science 210: Data Structures. Intro to Java Graphics

Understanding How Java Programs Work

Shared Collection of Java Course Materials: New Topics Covered. Agenda

Solutions to Chapter Exercises. GUI Objects and Event-Driven Programming

SNS COLLEGE OF ENGINEERING, Coimbatore

CS335 Graphics and Multimedia

For live Java EE training, please see training courses at

Packages: Putting Classes Together

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Graphics and Painting

Topic 9 More Graphics. Based on slides bu Marty Stepp and Stuart Reges from

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

1B1a Programming I Getting Started

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

AplusBug dude = new AplusBug(); A+ Computer Science -

Java Programming Constructs Java Programming 2 Lesson 1

This assignment should give you practice with some aspects of working with graphics and windows in Java.

CSD Univ. of Crete Fall Java Applets

Object-oriented programming in Java (2)

User interfaces and Swing

Methods (Deitel chapter 6)

COMP1007 Principles of Programming

Methods (Deitel chapter 6)

Transcription:

Introduction to Computer Science I Graphics Janyl Jumadinova 7 February, 2018

Graphics Graphics can be simple or complex, but they are just data like a text document or sound. Java is pretty good at graphics, especially for the web and small devices like phones. 2/13

Java Graphics A fantasy massively multiplayer online role- playing game, 2001 http://www.runescape.com/ Minecraft sandbox game, 2009 https://minecraft.net/ Instagram, 2011 - online mobile photo-sharing service CG Art http://www.cgartworld.com/ 3/13

Java Graphics Java can write applications or applets. 4/13

Java Graphics Java can write applications or applets. Java applet is a program that is embedded into an HTML document, and executed using a Web browser 4/13

Java Graphics Java can write applications or applets. Java applet is a program that is embedded into an HTML document, and executed using a Web browser Java application is a stand-alone program that is executed using Java interpreter 4/13

Java Graphics Java can write applications or applets. Java applet is a program that is embedded into an HTML document, and executed using a Web browser Java application is a stand-alone program that is executed using Java interpreter Java can make graphics in either one, and has two libraries to do it with: Swing (the newer kind) or AWT (Abstract Windowing Toolkit, the older kind). 4/13

Java - why two? Why is there a Swing and an AWT? 5/13

Java - why two? Why is there a Swing and an AWT? AWT was the original graphics library for Java. However, all programs looked like their host. That is, when they ran on a Mac, they looked like Mac programs, and when they ran on Windows, they looked like Windows programs. Programmers wanted to force the look and feel, so they built Swing on top of AWT. Yes, Swing includes all of AWT. AWT is still seen as better for applets, but that s fading due to AJAX, another web programming technique. 5/13

Java Graphics To start, here s a basic applet that demonstrates Java graphics using Swing import javax.swing.japplet; import java.awt.*; public class BasicGraphics extends javax.swing.japplet { public void paint(graphics g) { /* Draw the square. */ g.setcolor(color.red); g.fillrect(10, 20, 40, 40); } // end paint() } // end class BasicGraphics 6/13

Java Graphics API The first lines are import statements, to load the AWT library and swing s JApplet class. 7/13

Java Graphics API The first lines are import statements, to load the AWT library and swing s JApplet class. Our class is called BasicGraphics, and it extends JApplet to inherit JApplet properties. 7/13

Java Graphics API Inheritance Idea When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. In doing this, you can reuse the variables and methods of the existing class without having to write them yourself. 8/13

Java Graphics API Inside the applet, we have just one method: paint() It has one parameter, called the abstract Graphics object, and we call it g. You need to tell paint() what to paint on! 9/13

Java Graphics API Inside the applet, we have just one method: paint() It has one parameter, called the abstract Graphics object, and we call it g. You need to tell paint() what to paint on! 9/13

Java Graphics API paint() has two methods inside of it: setcolor and fillrect g.setcolor(color.red); is the command to color whatever graphic thing we have red. The computer still doesnt know what Graphic thing g is going to be! 10/13

Java Graphics API paint() has two methods inside of it: setcolor and fillrect g.setcolor(color.red); is the command to color whatever graphic thing we have red. The computer still doesnt know what Graphic thing g is going to be! g.fillrect(10, 20, 40, 40) tells the applet to make g into a fillrect, which is a filled rectangle. 10 is the starting x-position in the applet, 20 is the starting y-position in the applet 40 is the width and the other 40 is the height. Remember what color will fill it? Red! 10/13

Java Graphics API How do you remember all of this stuff? 11/13

Java Graphics API How do you remember all of this stuff? You don t! 11/13

Java Graphics API How do you remember all of this stuff? You don t! All of this is listed in the Java API. Want to see a simple edit? Change g.fillrect to g.filloval in the previous program. You can do whatever changes you want, just find it in the API and make sure your parameters are filled in correctly! 11/13

Java Swing Application Applets need a web page to run, but applications can run on their own. We can run our previous program by creating an application that would call it. 12/13

Java Swing Application public static void main(string[] args) { JFrame window = new JFrame("Janyl Jumadinova "); } // Add the drawing canvas and do necessary things to // make the window appear on the screen! window.getcontentpane().add(new BasicGraphics()); window.setdefaultcloseoperation(jframe.exit_on_close); window.setvisible(true); window.pack(); 13/13