OOP&M - theory lectures1 OOP&M – the third day “… I cannot help with this terrible headache …” - Bjorn the morning after -

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
The Web Warrior Guide to Web Design Technologies
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
OOP&M - theory lectures1 OOP&M – the second day “… In the beginning God created the heavens and the earth …” - the Hollybook -
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
OOP&M - laboratory lectures1 “… and the little computer knew then that computers would always grow wiser and more powerful …” - Isaac Asimov - JPN – GUI.
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
OOP&M - laboratory lectures1 OOP&M – LAB2 LABzwei: the Input.
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.
Applets. What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
OOP&M - laboratory lectures1 JPN – GUI and Applets “… I am sure ‘it wont fail as much as the one before …” - Bill Gates about W98 -
Io package as Java’s basic I/O system continue’d.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Applets Java API.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
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, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Welcome to CIS 083 ! Events CIS 068.
JAVA APPLETS By: Ms. Humaira Siddiqui. Java and the Internet Java is considered to be a language well suited to be used in the internet. In contrast with.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Java applet basics, loading & displaying images After this section, you should be able to : –Use the applet tag and applet parameters –Describe what a.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
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.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
University of Sunderland CDM105 Session 6 Dreamweaver and Multimedia Fireworks MX 2004 Creating Menus and Button images.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
CS61B L02 Using Objects (1)Garcia / Yelick Fall 2003 © UCB Kathy Yelick Handout for today: These lecture notes Computer Science 61B Lecture 2 – Using Objects.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
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.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets Yong Choi School of Business CSU, Bakersfield.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating a Java Application and Applet
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
I/O Basics.
Chapter 13: Advanced GUIs and Graphics
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Java applets 1/3/2019.
I/O and Applet from Chapter 12
Advanced GUIs and Graphics
APPLET PROGRAMMING.
Presentation transcript:

OOP&M - theory lectures1 OOP&M – the third day “… I cannot help with this terrible headache …” - Bjorn the morning after -

OOP&M - theory lectures2 OOP&M – input / output to programs Java program keyboard monitor files network InputStream System.out FileOutputStream Java program ? ? FileInputStream System.in

OOP&M - theory lectures3 OOP&M – input … an overview Java program InputStream bytes of data ewsc24rfds53Hej20Hur20m76ar20du20?rsf Input source We must build a bridge between the Java Program and the input source!!

OOP&M - theory lectures4 OOP&M – from LAB2 – internet When we are try to read information from the Web The Net as other communication media for our programs can be read using Streams There is a difference between what we saw until now and what will happen with the Net: files are in HTML code The constructors are: Strings; URL u; InputStream ins; InputStreamReader isr; BufferedReader link; u = new URL(" ins = u.openStream(); isr = new InputStreamReader(ins); link = new BufferedReader(isr); s = link.readLine(); As you see here, the structure is similar to the one that we saw for the files. The difference is at the constructor for the InputStream object, which is special!! But the method for reading the information is the same: *.readline()

OOP&M - theory lectures5 import java.net.*; import java.io.*; class MyFirstBrowser { public static void main(String[] arg) throws Exception { URL uNet; InputStream insNet; InputStreamReader isrNet; BufferedReader linkNet; String s; uNet = new URL(" insNet = uNet.openStream(); isrNet = new InputStreamReader(insNet); linkNet = new BufferedReader(isrNet); s = linkNet.readLine(); System.out.println(s); s = linkNet.readLine(); System.out.println(s); System.out.println("connection closed"); } OOP&M – from LAB2 – internet EXERCISE C.1 – Just reading a file

OOP&M - theory lectures6 Features: Interpret HTML TAGs underline a text if it is a link ( ) jump line with show the name of the images ( ) try to show tables (...) think how to ask to the user for the next jump to do... Interpret scripting languages JavaScript Visual Basic Script Perl Calls external applications Office Java Virtual Machine OOP&M – from LAB2 – internet The Browser

OOP&M - theory lectures7 OOP&M – the third day “… and the little computer knew then that computers would always grow wiser and more powerful …” - Isaac Asimov -

OOP&M - theory lectures8 OOP&M – the e-volution load reg; nop; add x; jmp $009; time

OOP&M - theory lectures9 OOP&M – the e-volution – a definition The evolution of the electronics has leaded us to a moment in which the interaction between computers and humans is made by the use of a 2 dimensional interface Because the control of the electronic equipment is quite complex, engineers have developed programs that use a reduced set of interaction possibilities in order to allow creators an easy way of work The GRAPHICAL USER INTERFACE (GUI from now) defines the use of interfaces which include some of that interaction methods Buttons, menus, scrollable windows and graphical drawings are used to communicate with the users

OOP&M - theory lectures10 OOP&M – the GUI – an approach The are different ways of attacking the problem of designing a user interface One is directly related to the Internet As you know, HTML has got only some very basic features for the communication to users … it is one-directional: it goes from the server to the screen of the user, but, by itself, cannot capture any user actions As we have seen in the description of a browser, HTML interpreters can call to other programs that execute external code, as JAVA, improving the communication An approach to the GUI design is to program applets

OOP&M - theory lectures11 OOP&M – the GUI – an approach with applets An applet is a Java program embedded in a web page. It is not only a way of providing a way of getting information form the user, because it is capable of compute something as well Applets use the GUI facilities that are provided with Java. These are NOT a part of the language proper; they belong to a package of predefined classes known as the abstract window toolkit (AWT) Applets are defined in another package, called the applet package and, for that reason they don’t have a main() declaration, it is a part of the class Applets can have a declaration called init() instead, which will contain special variable declarations and other “stuff” that should declared only once

OOP&M - theory lectures12 OOP&M – the GUI – some methods from AWT We already know one method contained into the AWT package In LABone we were experimenting with drawString in order to show some text on the screen In the AWT there are methods that can be used to define Graphics objects On of those objects models the drawing behavior of a portion of a computer screen; that is, it will respond to messages requesting that rectangles be drawn, background colors be set, current font information be returned, etc.

OOP&M - theory lectures13 OOP&M – the GUI – some methods from AWT import java.applet.*; import java.awt.*; public class textapplet extends Applet { public void paint(Graphics g) { g.drawString("Time |To Do |Needings", 30, 30); g.drawString(" ", 30, 45); g.drawString("10:00 |wake up |faith ", 30, 60); g.drawString("10:05 |shower |soap ", 30, 75); g.drawString("10:25 |breakfast |milk, juice, eggs, jam... ", 30, 90); g.drawString("11:00 |university |pants, T-shirt, books? ", 30, 105); } Do you remember our first applet? We had the problem of the alignment of the last column of the table AWT provides us some tools for solving this!!

OOP&M - theory lectures14 OOP&M – the GUI – some methods from AWT AWT provides a Color and a Font class that enable the programmer to define and use new colors and fonts Colors are described using three integers that specify the amount of RGB in a scale of each Fonts are specified by naming a font family (expressed as a String : “TimesRoman” or “Helvetica”, e.g.), a font style ( Font.PLAIN, Font.BOLD or Font.ITALIC ) and a number specifying point size (12 is typical) To change one of this features we need to first create an object and send a message to the Graphics object before drawing the text

OOP&M - theory lectures15 OOP&M – the GUI – some methods from AWT Change the Color Color c; c = new Color(180,10,120); g.setColor(c); g.drawString("Time …", 30, 30); Change the Font Font f; f = new Font(“Helvetica”, Font.BOLD, 14); g.setFont(f); g.drawString("Time …", 30, 30);

OOP&M - theory lectures16 OOP&M – the GUI – some methods from AWT Besides drawing strings and setting font and color, Graphics provides the following simple geometric object drawing methods: fillOval : draws an oval on the screen filled up with color fillRect : draws a rectangle filled up with color drawOval : draws an oval drawRect : draws a rectangle drawLine : draws a line An example would be: import java.awt.*; import java.applet.*; public class DrawOval extends Applet { public void paint(Graphics g) { Color c = new Color(20,120,160); g.setColor(c); g.fillOval(20,20,60,30); }

OOP&M - theory lectures17 OOP&M – the GUI – the problem appears Imagine a button: PRESS ME Can you decompose it into different graphical components? DO YOU THINK YOU CAN? ARE YOU SURE?  you have 5 minutes

OOP&M - theory lectures18 OOP&M – the GUI – the problem appears Decomposition of the button: PRESS ME

OOP&M - theory lectures19 OOP&M – the GUI – the problem appears The common Interaction tools that we use for the interaction with computers are VERY COMPLICATED to be implemented each time that we need them Buttons, menu-bars, scroll controls, text boxes, radio buttons … are predefined and ready to use in the AWT package so that we do not need to create them ourselves [Later we will see other possibilities, like the Swing package that offers many other ways of handling with this object]

OOP&M - theory lectures20 OOP&M – the GUI – Applets are alive Before we start to draw buttons on the screen, we need to learn a little bit more about the life cycle of applets When an applet is first loaded into the browser, the browser invokes its init() method Each time that we make a change on the screen or that we move the window … the Applet class invokes again all the methods contained into the applet But the init() method is called only once. Its intended role is to do the init ial setup for the applet

OOP&M - theory lectures21 OOP&M – the GUI – a place to press Java AWT provides a predefined class for modeling buttons, called Button the constructor for Button accepts the text in it (a String reference) as its argument new Button ( string ) An example of this would be: Buttonb; b = new Button(“touch Bjorn”);

OOP&M - theory lectures22 OOP&M – the GUI – a place to press Now we have created the object button, but we must also accomplish the following: Buttons should appear in the applet The applet should be able to respond to clicks in the buttons Java AWT provides a predefined method that handles both problems: add() The complete code would be: Buttonb; b = new Button(“touch Bjorn”); add(b);