Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn.

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

1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphic User Interfaces Layout Managers Event Handling.
Corresponds with Chapter 12
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
Event Handling Events and Listeners Timers and Animation.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
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.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Text Boxes and WordArt Guided Lesson.
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
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.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java SE 8 for Programmers, Third Edition
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Field Trip #19 Animations with Java By Keith Lynn.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
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.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
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.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
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.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
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.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
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.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
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.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Field Trip #29 Creating an Event Calendar with Java By Keith Lynn.
Section 10.1 Define scripting
“Form Ever Follows Function” Louis Henri Sullivan
CHAPTER 7 & 8 REVIEW QUESTIONS
Creation of an Android App By Keith Lynn
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn

JPanel A JPanel is a lightweight container that can be placed inside of other containers It can have its own layout For this app, we will make the layout of a JPanel a grid

JApplet A JApplet is a top-level container in Java We will use the JApplet to contain two Jpanels The first JPanel will contain letters The second JPanel will contain words In order to load a JApplet, we create an HTML document The HTML document must contain an applet tag The applet tag must contain the applet's name, width, and height

LayoutManager A LayoutManager defines how components will be placed onto a screen There are built-in layout managers in Java FlowLayout will put components in a row GridLayout will put components in a grid In this app, we will create a Jpanel to hold letters in buttons and put the buttons in a grid

String A String is a collection of individual characters We can obtain the character at a certain position in a String with the method charAt(int) The first character in a String is at position 0 We can determine the length of the String with the length() method We can concatenate characters to String with the += operator We can compare the content of two Strings with the equals or equalsIgnoreCase methods

Character A character is a single character There is a special relationship between chars and ints in Java If you treat a char like an int, it is converted to its ASCII equivalent

Events Events can be detected and acted on by creating listeners In this app, we will have three different kind of event listeners We will attach an ActionListener to a single button that will start the puzzle For each button in the grid, we will attach both a MouseListener and MouseMotionListener The MouseListener will be use to determine when we let up on the mouse The MouseMotionListener will be use to determine when we drag the mouse

Color In this app, when a word has been found, we will change the background color of the button to red We will change the text color to white

Fonts Fonts allows us to change the appearance of text We will display a list of words the user will find When a user correctly finds one, the font of the word will be changed to strikethrough

Arrays Arrays are a collection of elements of the same type In this app, we will consider what is actually a 2 dimensional array Java doesn't directly support 2 dimensional arrays so we will create an array of arrays The array will hold all of the buttons The buttons contain letters

Subclasses In this app, we will also make use of the ability to create subclasses If a class is not declared final, then we can create a new class called a subclass We can add additional functionality to the subclass

The game The idea behind the game to choose randomly words from a list We create a grid of 400 letters and randomly choose locations to place those words in the grid After we have placed those words, we fill the other buttons in with random letters The words hidden are displayed in a list

The game, cont'd The player will search through the grid trying to locate the words When a player thinks they have found the word, they will hold down the mouse on the first letter and drag the mouse to the last letter When the player begins dragging the mouse, a MouseMotionEvent is fired We record the buttons that the user drags the mouse over

The game, cont'd When the user lets up on the mouse, a MouseEvent is fired We then collect the letters from the buttons the user selected We create a String from the letters and check to see if it is in the list If it is, then we change the font of the word to strikethrough If the user wants to start over, we provide a button to reset the grid