CIS3931 - Intro to JAVA Lecture Notes Set 14 21-July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.

Slides:



Advertisements
Similar presentations
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Advertisements

METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
slides created by Marty Stepp
Road Map Introduction to object oriented programming. Classes
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.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
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.
Chapter 81 Exception Handling Chapter 8. 2 Reminders Project 5 due Oct 10:30 pm Project 3 regrades due by midnight tonight Discussion groups now.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Test. A software house decides to develop a DVD renting program. The product manager identifies the following requirements: Every DVD will have a title,
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Week 14 - Monday.  What did we talk about last time?  Image manipulation  Inheritance.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
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,
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
CIT 590 Intro to Programming First lecture on Java.
CS 320 Assignment 1 Rewriting the MISC Osystem class to support loading machine language programs at addresses other than 0 1.
Problem of the Day  Why are manhole covers round?
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Programming in Java CSCI-2220 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.
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.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
CSI 3125, Preliminaries, page 1 Compiling the Program.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
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.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Interfaces and Inner Classes
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
CITA 342 Section 1 Object Oriented Programming (OOP)
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
OOP Basics Classes & Methods (c) IDMS/SQL News
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chapter 4 - Finishing the Crab Game
Stack Data Structure, Reverse Polish Notation, Homework 7
Conditions and Ifs BIS1523 – Lecture 8.
Packages and Interfaces
Tonga Institute of Higher Education
Constructors, GUI’s(Using Swing) and ActionListner
Java Tutorial – Application Building
More on Creating Classes
Object Oriented Programming
Review for Midterm 3.
Presentation transcript:

CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets

Spot Forms …

Reminder… Update on the FINAL The final will be entirely multiple choice The lowest grade you can receive on the final and still pass the class is a 65 ! The final will be approximately 30 questions (about repeated questions from the previous midterms and 5-8 new questions) There will be 4 or 5 extra credit questions, for a total of 20 available extra credit points

Thursday’s class… Turning a JAVA program into a web- viewable applet A few more notes on program 6 Notes on the “protected”, “private”, “public”, “static”, and “final” modifiers.

Applets The Applet class is part of the AWT. A newer class called JApplet is included in Swing, but is not as commonly used as the Applet class. HOWEVER : The JApplet class makes turning an existing GUI program into an applet VERY easy …

JApplet Instead of extending JFrame, you want to extend JApplet in your program. JFrame and JApplet are very similar … so, almost everything will work without modification There are a few exceptions …

Example : Changing textaction.java into an Applet textaction.java was discussed in the last class. The first step is to take the textaction.java program and rename it to something like textactionapplet.java Then --- Modify it so your public class extends JApplet instead of JFrame

textactionapplet.java If you try to compile the program at this point, you will get a few errors… textactionapplet.java textactionapplet.java:20: cannot find symbol symbol : constructor JApplet(java.lang.String) location: class javax.swing.JApplet super ("TextAction Example"); ^ textaction.java:81: cannot find symbol symbol : method addWindowListener( ) location: class textaction addWindowListener(new WindowAdapter( ) ^ 2 errors

textactionapplet.java The errors are as follows : –The JApplet class does’t have a super method associated with it … so, you have to remove that. –There is no window listener available with applets …

textactionapplet.java Since you aren’t extending your entire program from the JFrame class, you will have to create one somewhere else. You will be modifying the “main” section of your program to create and customize the main JFrame.

textactionapplet.java public static void main (String[] args) { //Create a JFrame here instead.... JFrame frame = new JFrame("Making an applet"); //Add the textactionapplet information to this frame frame.getContentPane().add(new textactionapplet()); //Set the JFrame size frame.setSize(300,300); //Set the JFrame to be visible frame.setVisible(true); }

textactionapplet.java Now, the program should compile without any errors. Next, you will have to move the class files to your webserver. Make sure to set the appropriate file permissions on them. Finally, you will need to create a webpage to display the applet.

Webpage for the textactionapplet

The Applet Webpage See The applet should function just as the application did. The.class file can still be run as an application from a command line using the normal “java” run command. This program is now both and applet and an application.

Public, Private, and Protected The information needed to fully understand the use of these modifiers is a little beyond the scope of this class; however, it is important to at least understand at the basic level what each of these actually do. These modifiers have a bearing on access privileges in programs that have multiple classes associated with them.

Public, Private, and Protected When used in a class declaration : Keywords used to specify the access levels for member variables and functions (methods). When used on a method : Used to specify the access levels for the method and its variables. When used on a variable : Used to specify the access level for the single variable.

Public, Private, and Protected Public : visible to all classes Private : Visible only to the class to which it belongs Protected : Visisble to the class to which they belong and to all subclasses of that class.

Deciding when to use the modifiers Think about whether or not an external object (or program) actually needs direct access to the information. Really only applies in complex object oriented programming with multiple classes and methods.

Example public class bank_balance { public String owner; public int balance; public bank_balance( String name, int dollars ) { owner = name; //Check to be sure the balance is positive if (dollars >= 0) balance = dollars; //If the balance is not positive, make it 0 else dollars = 0; }

Example In this example, both the string and integer are public. Any object in the system can change the balance (even to a negative value). This could cause the program to fail even though there are checks in the bank_balance class to prevent negative values.

Example : modified The better way to make this program would be to prove two methods, getBalance and setBalance. Also – the balance should be either private or protected. Other objects can still access the data, but the can’t input invalid data.

Example : modified public class bank_balance { public String owner; private int balance; public bank_balance( String name, int dollars ) { owner = name; if (dollars >= 0) balance = dollars; else dollars =0; } public int getBalance() { return balance; } public void setBalance(int dollars) { if (dollars >= 0) balance = dollars; else dollars = 0; }

The reload button Your reload button should attempt to reload the page that is currently being displayed It will be hard to tell if this is actually working because pages sometimes load very quickly We will be checking your code to be sure you performed the reload correctly

The reload button The reload button first needs to determine the current page location Your textfield should be showing the current page location (it should be updated each time you click on a link!!) You will then simply call a setPage (or the function that loads your URLS) on the location

The home button The home button is loads a static page For assignment 6, home should load Just call a setPage on the address (or use your function that loads the URL Remember to update the text in the textfield as well! (When you click home, your textfield should say

Questions ? Any other topics to cover before the end of class? Only one more lecture class left, Assignment 7 will be assigned Next Thursday will be the review for the final The final is the Tuesday of the last week of class The last Thursday of class is intended to be used for help with Assignment 7 as well as to finalize grades and go over the grades on the final exam.