1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.

Slides:



Advertisements
Similar presentations
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
Advertisements

Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
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.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Applets Java API.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.
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,
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
GUI programming Graphical user interface-based programming.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
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,
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Java's Graphical User Interface Toolkit
Ade Azurat, Advanced Programming, 2004 Review: Slide 1 Review Why Java ? Application and Applet User Interface Exception Object-Oriented Programming.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
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.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Java Applet What is a Java Applet? How is applet compiled?
Java Applets.
Lecture 09 Applets.
30 Java Applets.
Graphical user interface-based programming
Applets.
UNIT-5.
Java Applets.
Constructors, GUI’s(Using Swing) and ActionListner
Applet in Java.
Applet 2019/4/23.
GUI building with the AWT
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
Presentation transcript:

1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC

2 Running Java  Standalone applications  Like traditional programs  BUT platform independent javac MyClass.java java MyClass ing/Programming/BasicJava1/compile.html ing/Programming/BasicJava1/compile.html

3 Running Java on the Internet  Applications could be packed as jar- archives and executed by JNLP  Run on a server

4 Running Java on the Internet  Two other alternatives Servlets  Running on the server side Applets  Running in the web browser  And Java Applets is the main theme for this course !!

5 Inheritance for Applets  An Object extended to  A Container extended to  A Panel that is extended to  An Applet which I can extend to  to MyApplet

6 Application  Applet How to make an applet out of an application ? THE APPLICATION: import java.awt.BorderLayout; import java.awt.event.*; import javax.swing.*; public class MyApplication extends JFrame implements ActionListener {

7 The Application private JButton northButton; private JLabel southLabel; /** * The constructor that creates the GUI */ public MyApplication(){ //set the title and the size super("Lektion24"); setSize(300, 150);

8 The Application //create some Swing components northButton = new JButton("PUSH ME for a greeting"); southLabel = new JLabel("Here goes the greeting!", JLabel.CENTER); //connect the button with a listener northButton.addActionListener(this);

9 The Application //lay out the components add(northButton, BorderLayout.NORTH); add(southLabel, BorderLayout.SOUTH); //make the window visible and closable setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); }//constructor

10 The Application /** * The implementation of the method from the * interface ActionListener. The code that’s * going to be executed when the user clicks * on the button */ public void actionPerformed(ActionEvent e) { southLabel.setText("Hello Colombo!"); }//actionPerformed public static void main(String[] args) { new MyApplication(); }

11 Workshop Pause

12 The Applet run by AppletViewer

13 The Applet Code part 1  Even simpler than the application import java.awt.BorderLayout; import java.awt.event.*; import javax.swing.*; import java.applet.*; public class MyApplet extends JApplet implements ActionListener {

14 The Applet Code part 2 private JButton northButton; private JLabel southLabel; /** * A method that initiates the applet and * creates the GUI */ public void init(){ //set the size of the window setSize(300, 150);

15 The Applet Code part 3 northButton = new JButton("PUSH ME for a greeting"); southLabel = new JLabel("Here goes the greeting!", JLabel.CENTER); //connect the button with a listener northButton.addActionListener(this); add(northButton, BorderLayout.NORTH); add(southLabel, BorderLayout.SOUTH); }//constructor

16 The Applet Code part 4 /** * The implementation of the method from * ActionListener. The code that is * going to be executed when the user * clicks on the button */ public void actionPerformed(ActionEvent e) { southLabel.setText("Hello Colombo!"); }//actionPerformed }//MyApplet

17 The (oversimplified) HTML file <applet code="MyApplet.class" width="300" height="200"> Problems with the applet

18 Workshop Pause

19 Another Simple Applet  A simple but  illustrative  Applet  Run with the AppletViewer

20 The Simple Applet Code 1 import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; public class SimpleApplet extends Applet{ private String text;

21 The Simple Applet Code 2 public void init() { text = "I'm a simple applet"; setBackground(Color.cyan); } public void start() { System.out.println("starting..."); }

22 The Simple Applet Code 3 public void stop() { System.out.println("stopping..."); } public void destroy() { System.out.println("preparing to unload..."); }

23 The Simple Applet Code 4 public void paint(Graphics g){ g.setColor(Color.blue); g.drawRect(0, 0, getSize().width -1, getSize().height -1); g.setColor(Color.red); g.drawString(text, 15, 25); }//paint }//SimpleApplet

24 The Simple Applet Code 5  Further info about this applet can be found on: aining/Programming/BasicJava1/applet. html#struct aining/Programming/BasicJava1/applet. html#struct  In Swing applets you replace paint() with the newer paintComponent()

25 The Appletviewer  How to run applets outside a web browser

26 The Appletviewer  The final result in a web browser  A web browser works with a cache  Appletviewer during the development of the applet That all for now, thank you!