Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Graphic User Interfaces Layout Managers Event Handling.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
Event Handling Events and Listeners Timers and Animation.
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.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
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.
Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Field Trip #19 Animations with Java By Keith Lynn.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Field Trip #31 CrossWord Puzzle By Keith Lynn. JApplet A JApplet is a top-level container in Java We will use the JApplet to contain two Jpanels The first.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
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 Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Alice in Action with Java Chapter 14 Events and GUIs.
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.
Java Applet. Introductions Applet is java program that can be embedded into HTML pages Java applets runs on the java enables web browsers such as mozila.
Field Trip #28 Securing a VNC Connection with Java By Keith Lynn.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Field Trip #25 Creating a Client/Server By Keith Lynn.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
Review_6 AWT, Swing, ActionListener, and Graphics.
Computer Science 209 GUIs Model/View/Controller Layouts.
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.
Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn.
Basics of GUI Programming Chapter 11 and Chapter 22.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn.
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.
Field Trip #30 A Memory Game By Keith Lynn. View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout.
CHAPTER 14 Applets and More Copyright © 2016 Pearson Education, Ltd.
Mouse, Keyboard, Sounds, and Images JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Field Trip #29 Creating an Event Calendar with Java By Keith Lynn.
Chapter 14 Applets and More. 2 Contents I. Introduction to Applets II. A Brief Introduction to HTML III. Creating Applets with Swing IV. Using AWT for.
Java Applet What is a Java Applet? How is applet compiled?
Lecture 09 Applets.
INFSY 547: WEB-Based Technologies
Creation of an Android App By Keith Lynn
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
11.1 Applets & graphics.
Advanced GUIs and Graphics
Presentation transcript:

Field Trip #23 Hangman By Keith Lynn

JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program such as a browser JApplet is updated version of applet that allow us to use lightweight components that don't depend heavily on their environment This means that components should look the same no matter what environment they are on

Appletviewer An alternative to using a browser is to use the appletviewer program that is included in the JDK In order to use the appletviewer program, we create an HTML document where we include an applet tag The applet tag must contain the name of the class, the width and height

JButton A JButton is a graphical component We can place text on a JButton A JButton has a margin so some characters won't be displayed We can change the margin by obtain an Insets object and setting left and right to 0 and then applying it to the button

Graphics In order to display things like graphics, we will override either the paint or paintComponent method If we are directly drawing on a JApplet, then we override its paint method We can also create an instance of a JPanel and add this to the JApplet In the JPanel, we override the paintComponent method

LayoutManager We can specify how components are added to a Japplet or Jpanel by specifying a layout manager There are several built-in layout managers FlowLayout lays out components in a row GridLayout lays out components in a grid

String A String is a collection of characters We can retrieve the character at a certain location in a String with the method charAt(int) We can append characters to the String using the + symbol We can compare two Strings using the method equals or equalsIgnoreCase

Char A char is a single character There is a special relationship between chars and ints in Java If you treat a char as an int, it is converted to the ASCII value of the char The ASCII value of 'A' is 65

Events We can detect events and act on them by creating an event listener An event listener we can use with a button is the ActionListener ActionListener is an interface which contains the method actionPerformed If an ActionListener is registered with a button, then when the button is clicked, actionPerformed is called

Drawing Lines In order to draw lines and shapes, we need a Graphics object We get a reference to a Graphics object by overriding paint in a heavyweight component and paintComponent in a lightweight component A Jpanel is a lightweight component We the method drawLine(x0,y0,x1,y1) to draw a line between (x0,y0) and (x1,y1)

Sounds In order to play a sound in an applet, we use the method getAudioClip The first parameter to getAudioClip is a URL This can be a URL on the web or getCodeBase() to refer to the location of the.class file of the applet or getDocumentBase() to refer to the location of the.html file of the applet We play the audio clip with the method play

Hangman The plan for creating Hangman is to create three panels The first panel will contain buttons that represent the characters in the word The second panel will contain buttons indicating the characters in the alphabet that haven't been chosen The third panel will be used to draw the hangman

Hangman, cont'd We attach a listener to the buttons representing the alphabet Each time a letter is clicked, we search the word and display occurrences of the letter We then make the letter invisible in the alphabet If the letter didn't occur, we display another part of the hangman If the word is filled in the game is over and the user wins If the hangman is filled in and the word isn't, the user loses