Java abstract class & abstract methods,Abstract class in java
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
The document discusses method overloading and overriding in Java. It defines method overloading as having multiple methods with the same name but different parameters, while overriding involves subclasses providing specific implementations of methods in the parent class. It provides examples of overloading methods by changing parameters and data types, and explains why overriding is not possible by only changing the return type due to ambiguity. The use of the super keyword to refer to parent class members is also explained.
This document provides information about applets including:
- Applets are small programs that can be embedded in web pages and run within web browsers. They allow for dynamic and interactive content.
- There are two types of applets: local applets stored on the local system and remote applets stored on remote servers.
- The lifecycle of a Java applet involves init(), start(), stop(), destroy(), and paint() methods being called in a specific order when the applet loads and runs in the browser.
This document provides an overview of Java applets, including:
- Applets are small Java programs that can be transported over the network and embedded in HTML pages.
- The main types of Java programs are standalone programs and web-based programs like applets.
- Applets differ from applications in that they have a predefined lifecycle and are embedded in web pages rather than running independently.
- The Applet class is the superclass for all applets and defines methods corresponding to the applet lifecycle stages like init(), start(), paint(), stop(), and destroy().
- Common methods for applets include drawString() for output, setBackground()/getBackground() for colors, and showStatus() to display in
This document provides an overview of Java servlets technology, including:
1. What Java servlets are and their main purposes and advantages such as portability, power, and integration with server APIs.
2. Key aspects of servlet architecture like the servlet lifecycle, the HttpServletRequest and HttpServletResponse objects, and how different HTTP methods map to servlet methods.
3. Examples of simple servlets that process parameters, maintain a session counter, and examples of deploying servlets in Eclipse IDE.
The document discusses key concepts in Java including classes, objects, methods, and command line arguments. A class defines common properties and behaviors for objects through fields and methods. Objects are instantiated from classes and can access fields and methods using dot notation. Command line arguments allow passing data into a Java application and are accessed through the args parameter in the main method.
This document discusses Java collections framework and various collection classes like ArrayList, LinkedList, HashSet, HashMap etc. It provides definitions and examples of commonly used collection interfaces like List, Set and Map. It explains key features of different collection classes like order, duplicates allowed, synchronization etc. Iterators and generic types are also covered with examples to iterate and create typed collection classes.
This document provides an overview of Java Swing components. It defines Swing as a GUI toolkit built on top of AWT that provides platform-independent and lightweight components. It describes common Swing components like JButton, JTextField, JTextArea and their usage. It also compares AWT and Swing, explaining how Swing components are more powerful and support pluggable look and feel while AWT is platform-dependent. Examples are given to demonstrate creating and using Swing components like JButton, JTextField, JTextArea etc.
This is the presentation file about inheritance in java. You can learn details about inheritance and method overriding in inheritance in java. I think it's can help your. Thank you.
Fragments allow modularizing an app's UI into reusable components. A fragment represents a portion of UI within an activity and has its own lifecycle. Multiple fragments can be used within a single activity to create a multi-pane UI or reuse fragments across activities. Key advantages are modularity, ability to reuse fragments, and maintaining a back stack of fragment states. The document discusses implementing fragments in different screen types, writing fragment and activity classes, and including fragments in layouts. It also covers fragment types like ListFragment and DialogFragment and ensuring compatibility by adding the support library.
This document provides an overview of GUI programming in Java, including basic concepts, AWT vs Swing frameworks, common control components, layout managers, and event handling. It discusses the key differences between AWT and Swing, describes common control components in both frameworks, explains different types of layout managers like flow, border, and grid layouts, and lists additional references for further reading.
PHP is a server-side scripting language used to create dynamic web pages. It allows embedding PHP code within HTML pages and interacting with databases. Key elements of PHP include variables, control structures, functions, and sessions. Sessions store user data on the server instead of the client to avoid cookies and allow tracking users across multiple pages.
This document provides an overview of the Java Collections Framework. It discusses core collection interfaces like List, Set, and Map and their common implementations like ArrayList, HashSet, and HashMap. It also covers sorting collections with Comparable and Comparator, searching collections with binary search, and using utility methods in the Collections class. Examples are provided to illustrate usage of various collection classes and methods.
This keyword is a reference variable that refer the current object in java.
This keyword can be used for call current class constructor.
http://www.tutorial4us.com/java/java-this-keyword
The document discusses multithreading concepts like concurrency and threading, how to create and control threads including setting priorities and states, and how to safely share resources between threads using synchronization, locks, and wait/notify methods to avoid issues like deadlocks. It also covers deprecated thread methods and increased threading support in JDK 1.5.
The document discusses the Java Collections Framework, which includes interfaces like Collection, List, Set, and Map. It describes common implementations like ArrayList, LinkedList, HashSet, TreeSet, HashMap, and LinkedHashMap. It covers the core functionality provided by the interfaces and benefits of using the framework.
The document discusses JavaScript error and exception handling using try, catch, and finally blocks. It provides examples of using try and catch to handle exceptions, catch to retrieve error details, and finally to execute code regardless of exceptions. It also shows how to use window.onerror to handle uncaught exceptions and access error details.
This document introduces JavaScript, explaining that it allows for interactivity on web pages by manipulating the browser and reacting to user actions. It is embedded in HTML and executes on the client side for fast interactions without a connection. JavaScript statements can include code combined with HTML tags. The document also discusses using JavaScript with HTML forms to process and display user input on the page.
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Access modifiers in Java control the accessibility and inheritance of classes, methods, and fields. There are three main access modifiers: private, protected, and public. Private members can only be accessed within their own class, protected within the package and subclasses, and public anywhere. Access modifiers also impact inheritance, with private members not being inherited by subclasses while protected and public can be.
Java is a programming language that compiles code to bytecode that runs on a Java Virtual Machine (JVM). The JVM is an abstraction layer that executes bytecode similarly across operating systems. It includes components like the bytecode verifier, class loader, execution engine, garbage collector, and security manager. The JVM allows Java to be platform independent and "write once, run anywhere".
This document provides an overview of the Java Virtual Machine (JVM) and how it executes Java code. It describes that the JVM converts Java bytecode into machine language and executes it, allowing Java programs to run on different platforms. It also outlines the key components of the JVM, including the class loader, execution engine, stack, method area, and garbage collected heap.
The life cycle of an applet involves different states including born, running, idle, and dead as it loads, executes code, becomes inactive, and is removed from memory. An applet transitions between these states, calling methods like init(), start(), stop(), paint(), and destroy() that perform initialization, launching execution, pausing, drawing to the screen, and cleanup. The init() method is called once while start() and stop() can be called multiple times as the applet loads, resumes running, and becomes inactive.
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
This document provides an overview of threads in Java, including:
- Threads allow for multitasking by executing multiple processes simultaneously. They are lightweight processes that exist within a process and share system resources.
- Threads can be created by extending the Thread class or implementing the Runnable interface. The run() method defines the code executed by the thread.
- Threads transition between states like new, runnable, running, blocked, and dead during their lifecycle. Methods like start(), sleep(), join(), etc. impact the thread states.
- Synchronization is used to control access to shared resources when multiple threads access methods and data outside their run() methods. This prevents issues like inconsistent data.
Java applets are small Java programs that can be embedded within HTML pages. When a user views a page containing an applet, the applet code is transferred to their system and executed by the Java Virtual Machine within their browser. Applets allow for interactive features on web pages like capturing mouse input and including buttons or checkboxes. They can also play media formats not natively supported by browsers. Applets are embedded using the applet or object tags, which can specify the applet's location and download any necessary Java plugins.
Java applets allow Java programs to run in a web browser. Applets are downloaded and run similarly to web pages. When a web page containing an applet tag is loaded, the browser downloads the applet class file from the web server and executes it within the browser's context on the client host. Applets are subject to security restrictions that prevent them from accessing local files or making network connections except back to the host from which they were downloaded.
This is the presentation file about inheritance in java. You can learn details about inheritance and method overriding in inheritance in java. I think it's can help your. Thank you.
Fragments allow modularizing an app's UI into reusable components. A fragment represents a portion of UI within an activity and has its own lifecycle. Multiple fragments can be used within a single activity to create a multi-pane UI or reuse fragments across activities. Key advantages are modularity, ability to reuse fragments, and maintaining a back stack of fragment states. The document discusses implementing fragments in different screen types, writing fragment and activity classes, and including fragments in layouts. It also covers fragment types like ListFragment and DialogFragment and ensuring compatibility by adding the support library.
This document provides an overview of GUI programming in Java, including basic concepts, AWT vs Swing frameworks, common control components, layout managers, and event handling. It discusses the key differences between AWT and Swing, describes common control components in both frameworks, explains different types of layout managers like flow, border, and grid layouts, and lists additional references for further reading.
PHP is a server-side scripting language used to create dynamic web pages. It allows embedding PHP code within HTML pages and interacting with databases. Key elements of PHP include variables, control structures, functions, and sessions. Sessions store user data on the server instead of the client to avoid cookies and allow tracking users across multiple pages.
This document provides an overview of the Java Collections Framework. It discusses core collection interfaces like List, Set, and Map and their common implementations like ArrayList, HashSet, and HashMap. It also covers sorting collections with Comparable and Comparator, searching collections with binary search, and using utility methods in the Collections class. Examples are provided to illustrate usage of various collection classes and methods.
This keyword is a reference variable that refer the current object in java.
This keyword can be used for call current class constructor.
http://www.tutorial4us.com/java/java-this-keyword
The document discusses multithreading concepts like concurrency and threading, how to create and control threads including setting priorities and states, and how to safely share resources between threads using synchronization, locks, and wait/notify methods to avoid issues like deadlocks. It also covers deprecated thread methods and increased threading support in JDK 1.5.
The document discusses the Java Collections Framework, which includes interfaces like Collection, List, Set, and Map. It describes common implementations like ArrayList, LinkedList, HashSet, TreeSet, HashMap, and LinkedHashMap. It covers the core functionality provided by the interfaces and benefits of using the framework.
The document discusses JavaScript error and exception handling using try, catch, and finally blocks. It provides examples of using try and catch to handle exceptions, catch to retrieve error details, and finally to execute code regardless of exceptions. It also shows how to use window.onerror to handle uncaught exceptions and access error details.
This document introduces JavaScript, explaining that it allows for interactivity on web pages by manipulating the browser and reacting to user actions. It is embedded in HTML and executes on the client side for fast interactions without a connection. JavaScript statements can include code combined with HTML tags. The document also discusses using JavaScript with HTML forms to process and display user input on the page.
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Access modifiers in Java control the accessibility and inheritance of classes, methods, and fields. There are three main access modifiers: private, protected, and public. Private members can only be accessed within their own class, protected within the package and subclasses, and public anywhere. Access modifiers also impact inheritance, with private members not being inherited by subclasses while protected and public can be.
Java is a programming language that compiles code to bytecode that runs on a Java Virtual Machine (JVM). The JVM is an abstraction layer that executes bytecode similarly across operating systems. It includes components like the bytecode verifier, class loader, execution engine, garbage collector, and security manager. The JVM allows Java to be platform independent and "write once, run anywhere".
This document provides an overview of the Java Virtual Machine (JVM) and how it executes Java code. It describes that the JVM converts Java bytecode into machine language and executes it, allowing Java programs to run on different platforms. It also outlines the key components of the JVM, including the class loader, execution engine, stack, method area, and garbage collected heap.
The life cycle of an applet involves different states including born, running, idle, and dead as it loads, executes code, becomes inactive, and is removed from memory. An applet transitions between these states, calling methods like init(), start(), stop(), paint(), and destroy() that perform initialization, launching execution, pausing, drawing to the screen, and cleanup. The init() method is called once while start() and stop() can be called multiple times as the applet loads, resumes running, and becomes inactive.
The document provides an overview of how to build a graphical user interface (GUI) in Java. It discusses the key classes used to create GUI components like JFrame, JPanel, and JButton. It explains how to set layout managers, add components, set frame size and visibility. It also includes sample code to create a simple calculator GUI with a border layout and grid layout. The document is an introduction to developing GUIs in Java using the Swing toolkit.
This document provides an overview of threads in Java, including:
- Threads allow for multitasking by executing multiple processes simultaneously. They are lightweight processes that exist within a process and share system resources.
- Threads can be created by extending the Thread class or implementing the Runnable interface. The run() method defines the code executed by the thread.
- Threads transition between states like new, runnable, running, blocked, and dead during their lifecycle. Methods like start(), sleep(), join(), etc. impact the thread states.
- Synchronization is used to control access to shared resources when multiple threads access methods and data outside their run() methods. This prevents issues like inconsistent data.
Java applets are small Java programs that can be embedded within HTML pages. When a user views a page containing an applet, the applet code is transferred to their system and executed by the Java Virtual Machine within their browser. Applets allow for interactive features on web pages like capturing mouse input and including buttons or checkboxes. They can also play media formats not natively supported by browsers. Applets are embedded using the applet or object tags, which can specify the applet's location and download any necessary Java plugins.
Java applets allow Java programs to run in a web browser. Applets are downloaded and run similarly to web pages. When a web page containing an applet tag is loaded, the browser downloads the applet class file from the web server and executes it within the browser's context on the client host. Applets are subject to security restrictions that prevent them from accessing local files or making network connections except back to the host from which they were downloaded.
This document discusses Java applets, including their life cycle, differences from Swing, and advantages/disadvantages. Applets run in a web browser and have an initialization state, running state, idle/stopped state, and dead state. They do not use a main method but instead override init(), start(), paint(), stop(), and destroy() methods. Compared to Swing, applets are heavier weight, use AWT layouts, and require a browser to run. Advantages include cross-platform capability and moving work to the client, while disadvantages are needing the Java plugin and some browsers not supporting applets.
- Applets are small Java applications that run within web browsers. They are embedded in HTML pages and can interact with the user.
- Applets follow an event-driven model where the AWT notifies the applet of user interactions. The applet then takes action and returns control to the AWT.
- The applet lifecycle includes init(), start(), stop(), and destroy() methods that are called at different points as the applet loads and runs within the browser.
El documento describe las applets de Java, incluyendo su estructura de ciclo de vida con los métodos init(), start(), stop(), destroy(), y paint(). También discute las ventajas de las applets como ser multiplataforma y cargarse rápidamente, así como las desventajas como requerir el plugin de Java y tener acceso limitado al sistema. Finalmente, muestra un ejemplo básico de una applet que dibuja una línea roja.
This document provides information about applet programming in Java. It discusses that applets are small Java programs used primarily for internet computing. Applets can perform tasks like displaying graphics, playing sounds, and accepting user input. Key differences between applets and standalone applications include applets not having a main method, needing to be embedded in an HTML page, and having restrictions on file/network access. The document also covers the applet lifecycle, writing applet code, and using HTML tags to embed applets in web pages.
This document provides an overview of Java applets, including:
- A Java applet is a small Java application delivered as bytecode and run within a Java Virtual Machine in the user's web browser.
- Applets are typically embedded in web pages and can display interactive elements like buttons and text boxes.
- The document discusses the lifecycle methods of applets like init(), start(), stop(), and destroy(), and provides simple code examples of basic "Hello World" applets.
An applet is a Java program that runs in a web browser. Applets extend the Applet class and have a lifecycle of init(), start(), stop(), and destroy() methods. Applets are embedded in HTML pages and have security restrictions enforced by the browser. When a user views an HTML page containing an applet, the applet code is downloaded and a JVM instance is created to run the applet.
The document discusses applet programming in Java. It defines an applet as an interactive panel embedded in a web page that can be run from a browser. Applets have a life cycle of init(), start(), stop(), and destroy() methods. The paint() method is used for any drawing or painting beyond standard GUI components. Repaint() requests a repaint but does not guarantee it. Example code demonstrates basic graphics methods and includes an applet example with supporting HTML. Advantages of applets include cross-platform capability and security sandboxing, while disadvantages are needing the Java plugin and slower initial startup.
This document provides an overview of Applets and Java GUI programming. It discusses Applets, their life cycle, how to run Applets using AppletViewer and HTML, and classes used in Applet programming like Applet, Graphics, Color, Font, and AWT components. It also covers Swing components like JApplet, JComponent, JLabel, JTextField, JButton, and JRadioButton. Code examples and demonstrations are provided for many of the concepts discussed.
introduction to Applets, life cycle of applets, methods of applets, examples,embedding apllets in html files, compiling and running of applets with appletviewer
Applets are small Java programs that run in web browsers. They have a lifecycle with methods like init(), start(), paint(), stop(), and destroy() that get called at different points. The init() method initializes variables, start() runs when the applet is displayed, paint() redraws the output, stop() runs when the browser closes, and destroy() removes the applet from memory. Sample code shows an applet class that extends Applet and overrides these methods to track calls and draw status messages. The status window can also be used to display messages to users.
This document discusses Java applets. It introduces applets as simple Java programs that can run in web browsers. It then describes the class hierarchy for applets, providing an example "Hello World" applet code. The document concludes by explaining how to create an HTML page that embeds the applet so it can be viewed using appletviewer from the command line.
This document provides an overview of Java applets, including:
- Applets are Java programs that run in a web browser and are typically embedded in web pages. They must extend the Applet class.
- There are two types of applets - AWT applets which use older GUI classes, and Swing applets which use newer GUI classes.
- The Applet class provides lifecycle methods like init(), start(), stop(), and destroy() that are called at different points in the applet's execution. It also includes painting and display methods like paint(), repaint(), and drawString().
Java Programming- Introduction to Java Applet ProgramsTrinity Dwarka
Java Programming- Introduction to Java Applet Programs
Java Applets
Java Applet Classes
Contrast Application with Applet
Applet Declaration
Body of an Applet
Applets
Applets and Web Pages – HTML
Running the Applet
The document discusses various event handling classes in Java including ActionEvent, KeyEvent, MouseEvent, MouseMotionEvent, FocusEvent, WindowEvent, and ItemEvent. It provides examples of how to use each event class by implementing the appropriate listener interface and defining event handling methods. Key points covered include common event handling terms like event, event source, and event listener. It also summarizes the typical methods provided by each event class.
This document provides an overview of applets and servlets, comparing their key differences. It defines applets as small Java programs embedded in web pages that provide interactive content in browsers using the Java interpreter. Servlets are server-side Java programs that dynamically generate content in response to client requests, allowing servers to handle multiple clients concurrently. The document outlines the lifecycles of applets and servlets, including their initialization, processing, and destruction methods. It concludes that the main differences are that applets run on clients while servlets run on servers, and servlets handle HTTP requests to dynamically generate pages rather than provide static content like applets.
The ServletContext represents the servlet context and allows communication between servlets and the servlet container. It provides access to context-wide resources such as initialization parameters, servlet context attributes, and logging. Some key things about the ServletContext:
- There is one instance per web application per Java Virtual Machine (JVM)
- Can be accessed by any servlet in the web application
- Contains information like context path, MIME types, etc.
- Allows servlets to share resources and configuration parameters
- Attributes set in the ServletContext are accessible by any servlet
So in summary, the ServletContext provides servlets with a way to share global data and configuration for a web application in a
Interfaces define methods that classes can implement. Classes implementing interfaces must define all interface methods. Interfaces can extend other interfaces, requiring implementing classes to define inherited methods as well. Interface variables are implicitly public, static, and final. A class can implement multiple interfaces and override methods with the same name across interfaces. Partial interface implementation requires the class to be abstract.
An applet is a Java program that runs within a web browser. Applets are embedded in HTML pages and run in a sandbox that prevents them from accessing the local computer's file system for security reasons. When writing an applet, you extend the JApplet class and override certain methods like init(), start(), stop(), destroy(), and paint() that are called at different points in the applet's lifecycle by the browser. The paint() method is used for any drawing or graphics output from the applet.
This document discusses Java applets and their life cycle. It explains that applets are subclasses of Applet that run in web browsers rather than via a main method. The life cycle of an applet involves initialization, start, paint, stop, and destroy methods. It provides an example "Hello World" applet code and explains how to compile, embed in an HTML file, and run it using an applet viewer. Finally, it contrasts applets and applications, noting that applets have limited system access for security while applications are fully trusted and run via a main method.
Applets allow Java programs to be run within web browsers. An applet is a Java class that extends Applet and overrides certain methods like init(), start(), stop(), and paint(). These methods control the applet's lifecycle and graphics rendering. Applets are subject to security restrictions like not being able to access the local file system. They can be embedded in HTML pages using special tags and retrieve configuration parameters from <param> tags.
Applets allow Java programs to be run within web browsers. An applet is a Java class that extends Applet and overrides certain methods like init(), start(), stop(), and paint(). These methods control the applet's lifecycle and graphics rendering. Applets are subject to security restrictions like not being able to access the local file system. They can be embedded in HTML pages using special tags and retrieve configuration parameters from <param> tags.
An applet is a Java program that runs in a web browser. It is embedded in an HTML page and runs in the Java Virtual Machine (JVM). To create an applet, a class must extend the Applet class. The applet lifecycle includes initialization, starting, painting, stopping, and destruction. Applets allow Java programs to be run from web pages and have graphical user interfaces.
An applet is a Java program that runs in a web browser. It can have full Java functionality. Applets have a lifecycle of init(), start(), paint(), stop(), destroy() methods. They are embedded in HTML pages and have security restrictions. The applet displays output using drawString() and requests repaints with repaint(). It can output to the browser status window.
An applet is a small Java program that runs in a web browser. It allows for interactive graphics and animation to be embedded in HTML pages. Applets differ from standalone Java applications in that they have no main method and run within the context of a web page. The lifecycle of an applet involves initialization, starting, stopping, and destruction as the user interacts with the web page. Parameters can be passed to applets using the <param> tag in HTML. The applet code uses methods like init(), paint(), start(), and stop() to control its execution and display output.
The document discusses object oriented programming concepts including applets, differences between applets and applications, the lifecycle of an applet, creating applets, passing parameters to applets, an introduction to Swing components and limitations of AWT. It also discusses the MVC architecture and its components - model, view and controller.
This document provides an overview of applet programming in Java. It discusses the basics of applets including the applet lifecycle, differences between applications and applets, parameter passing in applets, and event handling using listeners. It also covers input/output in applets, using repaint(), getDocumentBase(), and getCodeBase() methods. The document explains layout managers and creating buttons and text fields. It provides an example of a simple "Hello World" applet and discusses running applets in a browser or applet viewer.
This document provides an overview of Java applets including:
- Applets are programs that run in web browsers under control of the browser to provide interactive experiences on web pages.
- The lifecycle of an applet involves initialization, starting, stopping, and destruction controlled by the browser through specific methods.
- Security restrictions are placed on applets to prevent them from compromising the user's system.
Applets are small Java programs that run in web browsers. They are classified as local or remote based on where they are stored and executed. The applet lifecycle consists of init(), start(), stop(), and destroy() methods that are automatically called during execution. Applets differ from applications in that they are event-driven, run in a browser, and cannot access local files. The HTML <applet> tag is used to embed applets on web pages and supports attributes like code, width, height, and <param> tags for arguments.
This document discusses Java applets. It defines an applet as a small program that performs a specific task within a larger program. The document outlines the features of applets, providing examples of how to write a basic "Hello World" applet in Java. It also describes the lifecycle of an applet, including the init, start, stop, and destroy methods. The document notes advantages of applets like platform independence, and disadvantages like requiring the Java plugin.
- Applets are small Java applications that run within web pages. They are executed by a web browser or applet viewer once they have been compiled into class files.
- Applets have lifecycle methods like init(), start(), stop(), and destroy() that are called at different points in the applet's execution. The paint() method handles redrawing the applet's display.
- Applets can use methods like drawString() to output text and repaint() to refresh their display. Parameters can be passed to applets via the HTML <applet> tag and retrieved using getParameter().
An applet is a Java program that runs in a web browser. Applets allow interactive components and enhancements to be added to webpages. Advantages include faster response times since applets run on the client-side, security, and platform independence. The main methods in an applet's lifecycle are init(), start(), stop(), and destroy(). Drawbacks include requiring the Java plugin to be installed in the client's browser.
This document provides information about Java applets. It discusses what applets are, the Applet class, applet architecture and lifecycle, methods like init(), start(), stop(), destroy(), and paint(). It covers displaying output, requesting repainting, using the status window, the HTML <applet> tag and passing parameters. It also discusses getting the code base and document base, the AppletContext interface, and the two types of applets - those based on Applet and those based on JApplet.
This document discusses how to grow one's career with WordPress. It provides an overview of WordPress, including that it was founded in 2003 by Matt Mullenweg and Mike Little and currently powers 27% of the web. The document then suggests several career paths one can take with WordPress, such as being a blogger, support specialist, designer, developer, content writer, QA engineer, or internet marketer. It encourages the reader to choose one path, get good at it, and notes that one's thinking capacity is the limit.
Caching in WordPress provides three main ways to cache content:
1. Page caching stores entire page outputs to serve static content and avoid database queries on repeat visits.
2. Transients cache query and object results, like recent posts, and are stored in the database for retrieval until expiration.
3. Object caching stores content in memory for faster loading, but requires an external persistent data store like Memcached to remain available between page loads.
Operator overloading allows operators like + and << to be used with user-defined types like classes. It is done by defining corresponding operator functions like operator+() and operator<<(). This allows objects to be used with operators in a natural way while providing custom behavior for that type. The rules for overloading include maintaining precedence and associativity of operators. Common operators like +, -, *, /, <<, >>, ==, =, [] and () can be overloaded to allow user-defined types to work with them.
The document discusses arrays and pointers in C++. It covers:
- How to declare and initialize arrays
- Accessing array elements using subscripts
- Using parallel arrays when subscripts are not sequential numbers
- Special considerations for strings as arrays of characters
- Declaring pointer variables and using pointers to access array elements
- Potential issues with pointers like dangling references
This document provides an overview of C++ programming concepts including:
1. C++ programs consist of functions, with every program containing a main() function. Functions contain declarations, statements, comments, and can call libraries.
2. Variables must be declared with a type and can be used to store values. C++ supports integer, floating point, character, and other variable types.
3. C++ allows selection and decision making using if/else statements, switch statements, logical operators, and loops like while and for. Operators allow comparisons and boolean evaluations.
The document discusses various graph algorithms and representations including:
- Adjacency lists and matrices for representing graphs
- Breadth-first search (BFS) which explores edges from a source vertex s level-by-level
- Depth-first search (DFS) which explores "deeper" first, producing a depth-first forest
- Classifying edges as tree, back, forward, or cross based on vertex colors in DFS
- Topological sorting of directed acyclic graphs (DAGs)
- Strongly connected components (SCCs) in directed graphs and using the transpose
The heap data structure is a nearly complete binary tree implemented as an array. There are two types of heaps: max-heaps and min-heaps. The MAX-HEAPIFY algorithm maintains the heap property by allowing a value to "float down" the tree. BUILD-MAX-HEAP builds a max-heap by calling MAX-HEAPIFY on each node, and HEAPSORT sorts an array using the heap structure.
The document discusses divide and conquer algorithms and merge sort. It provides details on how merge sort works including: (1) Divide the input array into halves recursively until single element subarrays, (2) Sort the subarrays using merge sort recursively, (3) Merge the sorted subarrays back together. The overall running time of merge sort is analyzed to be θ(nlogn) as each level of recursion contributes θ(n) work and there are logn levels of recursion.
The document discusses lower bounds for sorting algorithms and the counting sort algorithm. It begins by explaining that sorting algorithms can only use comparisons between elements to determine their order. It then discusses decision trees that model the comparisons made by sorting algorithms and how the longest path in the tree represents the worst case number of comparisons. Finally, it provides pseudocode for counting sort and analyzes its running time as θ(k+n) where k is the range of input values and n is the number of elements.
The document discusses minimum spanning trees and Kruskal's algorithm. A minimum spanning tree is a subset of edges in a connected, undirected graph that connects all vertices with the minimum total weight. Kruskal's algorithm finds a minimum spanning tree by growing a forest of trees while ensuring each added edge connects two different trees without forming a cycle. It uses a disjoint-set data structure to keep track of the connected components in the forest as edges are added from lowest to highest weight.
The document discusses algorithms for solving single-source shortest path problems on weighted, directed graphs. It describes Dijkstra's algorithm, which finds the shortest paths from a single source node to all other nodes in a graph where all edge weights are non-negative. The algorithm works by repeatedly selecting the node with the smallest estimated shortest path distance, adding it to the set of visited nodes, and relaxing all outgoing edges to update neighboring nodes' distances.
The document discusses priority queues and quicksort. It defines a priority queue as a data structure that maintains a set of elements with associated keys. Heaps can be used to implement priority queues. There are two types: max-priority queues and min-priority queues. Priority queues have applications in job scheduling and event-driven simulation. Quicksort works by partitioning an array around a pivot element and recursively sorting the sub-arrays.
The document describes the quicksort algorithm. Quicksort works by:
1) Partitioning the array around a pivot element into two sub-arrays of less than or equal and greater than elements.
2) Recursively sorting the two sub-arrays.
3) Combining the now sorted sub-arrays.
In the average case, quicksort runs in O(n log n) time due to balanced partitions at each recursion level. However, in the worst case of an already sorted input, it runs in O(n^2) time due to highly unbalanced partitions. A randomized version of quicksort chooses pivots randomly to avoid worst case behavior.
Enabling BIM / GIS integrations with Other Systems with FMESafe Software
Jacobs has successfully utilized FME to tackle the complexities of integrating diverse data sources in a confidential $1 billion campus improvement project. The project aimed to create a comprehensive digital twin by merging Building Information Modeling (BIM) data, Construction Operations Building Information Exchange (COBie) data, and various other data sources into a unified Geographic Information System (GIS) platform. The challenge lay in the disparate nature of these data sources, which were siloed and incompatible with each other, hindering efficient data management and decision-making processes.
To address this, Jacobs leveraged FME to automate the extraction, transformation, and loading (ETL) of data between ArcGIS Indoors and IBM Maximo. This process ensured accurate transfer of maintainable asset and work order data, creating a comprehensive 2D and 3D representation of the campus for Facility Management. FME's server capabilities enabled real-time updates and synchronization between ArcGIS Indoors and Maximo, facilitating automatic updates of asset information and work orders. Additionally, Survey123 forms allowed field personnel to capture and submit data directly from their mobile devices, triggering FME workflows via webhooks for real-time data updates. This seamless integration has significantly enhanced data management, improved decision-making processes, and ensured data consistency across the project lifecycle.
Developing Schemas with FME and Excel - Peak of Data & AI 2025Safe Software
When working with other team members who may not know the Esri GIS platform or may not be database professionals; discussing schema development or changes can be difficult. I have been using Excel to help illustrate and discuss schema design/changes during meetings and it has proven a useful tool to help illustrate how a schema will be built. With just a few extra columns, that Excel file can be sent to FME to create new feature classes/tables. This presentation will go thru the steps needed to accomplish this task and provide some lessons learned and tips/tricks that I use to speed the process.
Ivanti’s Patch Tuesday breakdown goes beyond patching your applications and brings you the intelligence and guidance needed to prioritize where to focus your attention first. Catch early analysis on our Ivanti blog, then join industry expert Chris Goettl for the Patch Tuesday Webinar Event. There we’ll do a deep dive into each of the bulletins and give guidance on the risks associated with the newly-identified vulnerabilities.
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureSafe Software
When projects depend on fast, reliable spatial data, every minute counts.
AI Clearing needed a faster way to handle complex spatial data from drone surveys, CAD designs and 3D project models across construction sites. With FME Form, they built no-code workflows to clean, convert, integrate, and validate dozens of data formats – cutting analysis time from 5 hours to just 30 minutes.
Join us, our partner Globema, and customer AI Clearing to see how they:
-Automate processing of 2D, 3D, drone, spatial, and non-spatial data
-Analyze construction progress 10x faster and with fewer errors
-Handle diverse formats like DWG, KML, SHP, and PDF with ease
-Scale their workflows for international projects in solar, roads, and pipelines
If you work with complex data, join us to learn how to optimize your own processes and transform your results with FME.
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfällepanagenda
Webinar Recording: https://www.panagenda.com/webinars/domino-iq-was-sie-erwartet-erste-schritte-und-anwendungsfalle/
HCL Domino iQ Server – Vom Ideenportal zur implementierten Funktion. Entdecken Sie, was es ist, was es nicht ist, und erkunden Sie die Chancen und Herausforderungen, die es bietet.
Wichtige Erkenntnisse
- Was sind Large Language Models (LLMs) und wie stehen sie im Zusammenhang mit Domino iQ
- Wesentliche Voraussetzungen für die Bereitstellung des Domino iQ Servers
- Schritt-für-Schritt-Anleitung zur Einrichtung Ihres Domino iQ Servers
- Teilen und diskutieren Sie Gedanken und Ideen, um das Potenzial von Domino iQ zu maximieren
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...Safe Software
The National Fuels Treatments Initiative (NFT) is transforming wildfire mitigation by creating a standardized map of nationwide fuels treatment locations across all land ownerships in the United States. While existing state and federal systems capture this data in diverse formats, NFT bridges these gaps, delivering the first truly integrated national view. This dataset will be used to measure the implementation of the National Cohesive Wildland Strategy and demonstrate the positive impact of collective investments in hazardous fuels reduction nationwide. In Phase 1, we developed an ETL pipeline template in FME Form, leveraging a schema-agnostic workflow with dynamic feature handling intended for fast roll-out and light maintenance. This was key as the initiative scaled from a few to over fifty contributors nationwide. By directly pulling from agency data stores, oftentimes ArcGIS Feature Services, NFT preserves existing structures, minimizing preparation needs. External mapping tables ensure consistent attribute and domain alignment, while robust change detection processes keep data current and actionable. Now in Phase 2, we’re migrating pipelines to FME Flow to take advantage of advanced scheduling, monitoring dashboards, and automated notifications to streamline operations. Join us to explore how this initiative exemplifies the power of technology, blending FME, ArcGIS Online, and AWS to solve a national business problem with a scalable, automated solution.
➡ 🌍📱👉COPY & PASTE LINK👉👉👉 ➤ ➤➤ https://drfiles.net/
Wondershare Filmora Crack is a user-friendly video editing software designed for both beginners and experienced users.
Your startup on AWS - How to architect and maintain a Lean and Mean account J...angelo60207
Prevent infrastructure costs from becoming a significant line item on your startup’s budget! Serial entrepreneur and software architect Angelo Mandato will share his experience with AWS Activate (startup credits from AWS) and knowledge on how to architect a lean and mean AWS account ideal for budget minded and bootstrapped startups. In this session you will learn how to manage a production ready AWS account capable of scaling as your startup grows for less than $100/month before credits. We will discuss AWS Budgets, Cost Explorer, architect priorities, and the importance of having flexible, optimized Infrastructure as Code. We will wrap everything up discussing opportunities where to save with AWS services such as S3, EC2, Load Balancers, Lambda Functions, RDS, and many others.
מכונות CNC קידוח אנכיות הן הבחירה הנכונה והטובה ביותר לקידוח ארונות וארגזים לייצור רהיטים. החלק נוסע לאורך ציר ה-x באמצעות ציר דיגיטלי מדויק, ותפוס ע"י צבת מכנית, כך שאין צורך לבצע setup (התאמות) לגדלים שונים של חלקים.
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Impelsys Inc.
Web accessibility is a fundamental principle that strives to make the internet inclusive for all. According to the World Health Organization, over a billion people worldwide live with some form of disability. These individuals face significant challenges when navigating the digital landscape, making the quest for accessible web content more critical than ever.
Enter Artificial Intelligence (AI), a technological marvel with the potential to reshape the way we approach web accessibility. AI offers innovative solutions that can automate processes, enhance user experiences, and ultimately revolutionize web accessibility. In this blog post, we’ll explore how AI is making waves in the world of web accessibility.
Providing an OGC API Processes REST Interface for FME FlowSafe Software
This presentation will showcase an adapter for FME Flow that provides REST endpoints for FME Workspaces following the OGC API Processes specification. The implementation delivers robust, user-friendly API endpoints, including standardized methods for parameter provision. Additionally, it enhances security and user management by supporting OAuth2 authentication. Join us to discover how these advancements can elevate your enterprise integration workflows and ensure seamless, secure interactions with FME Flow.
Your startup on AWS - How to architect and maintain a Lean and Mean accountangelo60207
Prevent infrastructure costs from becoming a significant line item on your startup’s budget! Serial entrepreneur and software architect Angelo Mandato will share his experience with AWS Activate (startup credits from AWS) and knowledge on how to architect a lean and mean AWS account ideal for budget minded and bootstrapped startups. In this session you will learn how to manage a production ready AWS account capable of scaling as your startup grows for less than $100/month before credits. We will discuss AWS Budgets, Cost Explorer, architect priorities, and the importance of having flexible, optimized Infrastructure as Code. We will wrap everything up discussing opportunities where to save with AWS services such as S3, EC2, Load Balancers, Lambda Functions, RDS, and many others.
2. Introducing Applets Applets Java programs called from within another application Frequently run from a Web page Display as rectangular area Can respond to user-initiated events Behaviors come from Java class named JApplet Steps to write an applet Set up layout for applet Create components and add them to applet
3. Applets 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 to tell the browser about the applet You don’t need to supply a main method; the browser does that When you write an applet, you are writing only part of a program You supply certain methods that the browser calls For security reasons, applets run in a sandbox : they have no access to the client’s file system
4. What an applet is You write an applet by extending the class JApplet JApplet is just a class like any other; you can even use it in applications if you want When you write an applet, you are only writing part of a program; the browser supplies the main method Once you understand how applets work, you can write a program that function either as an applet or as an application—just write a main method that calls the right methods at the right time Such programs have the ugly name “ appletcations ”
5. The genealogy of JApplet java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----java.applet.Applet | +----javax.swing.JApplet
6. The simplest possible applet import javax.swing.JApplet; public class TrivialApplet extends JApplet { } <applet code="TrivialApplet.class" width="150" height="100"> </applet> TrivialApplet.java TrivialApplet.html
7. The simplest reasonable applet import java.awt.*; import javax.swing.JApplet; public class HelloWorld extends JApplet { public void paint(Graphics g) { g.drawString("Hello World!", 30, 30); } }
8. What are the disadvantages of applets? Applets can’t run any local executable programs Applets can’t with any host other than the originating server Applets can’t read/write to local computer’s file system
9. What are the disadvantages of applets? (Cont’d) Applets can’t find any information about the local computer All java-created pop-up windows carry a warning message Stability depends on stability of the client’s web server Performance directly depend on client’s machine
10. What are the advantages of applets? Automatically integrated with HTML; hence, resolved virtually all installation issues. Can be accessed from various platforms and various java-enabled web browsers. Can provide dynamic, graphics capabilities and visualizations Implemented in Java, an easy-to-learn OO programming language
11. What are the advantages of applets? (Cont’d) Alternative to HTML GUI design Safe! Because of the security built into the core Java language and the applet structure, you don’t have to worry about bad code causing damage to someone’s system Can be launched as a standalone web application independent of the host web server
12. Java Applets Can not Applets are programs designed to run as part of a Web Page (Applet = little application). Applets are similar to normal Java Applications but have extra security features to prevent a downloaded Applet damaging your computer or transmitting information from it. For instance an Applet cannot: Access local files Delete local files Run another program Find out your name Connect to another host
13. Running a Java Applet You write Java code using an editor javac MyApp.java appletviewer MyApp.html Text Editor You save the file with a .java extension You run the Java compiler ' javac ' You can view the applet with the command ' appletviewer ' This creates a file of bytecode with a .class extension Web Browser You write a web page in html using an editor You can view the web page from a web browser You save the file with a .html extension Java code: MyApp.java Bytecode: MyApp.class Window Web page: MyApp.html Text Editor
14. Creating an Applet Open " Notepad " (Start Programs Other Notepad) Type this in: Save As "Greetings.java" (Put the " " round the name otherwise it adds .txt to the end!) Open a DOS Window (Start MS-DOS Prompt) Type javac Greetings.java G:\> javac Greetings.java G:\> If it gives an error check you typed it in exactly right. import java.awt.*; import java.applet.Applet; public class Greetings extends Applet { public void paint(Graphics g) { g.drawString("Hello World!", 50, 50); } } If you type dir Greetings.* you should see Greetings.java and Greetings.class
15. Creating the Web Page In order to run an applet you have to embed it in a web page using a special <applet> tag e.g: <applet code="name.class" width=www height=hhh></applet> <html> <head> <title>Greetings Applet</title> </head> <body> <applet code="Greetings.class" width=300 height=200 ></applet> </body> </html> Using Notepad type in the following and save it as "Greetings.html" : Size of the applet in pixels
16. Running the Program G:\> appletviewer Greetings.html In the DOS window type appletviewer Greetings.html You should see something like this:
17. Running in a Web Browser In Netscape go to the File menu then Open Page ... Press Choose File... Find your file Greetings with the Netscape symbol alongside it (Greetings.html) - click on it and press Open (or double click on it) Back in the Open Page dialog press Open You should see something like: Title Your greeting Message
18. What does it mean? import java.awt.*; import java.applet.Applet; public class Greetings extends Applet { public void paint(Graphics g) { g.drawString("Hello World!", 50, 50); } } These 2 lines tell the computer to include ( import ) two standard libraries awt (Abstract Window Toolkit) and applet . This line tells the computer to display some text ( a string) on the screen. This line announces that the program ( class ) can be run by anyone ( public ), is called Greetings and is an Applet . This line declares what follows in the { } as a method called paint. This is where it is displayed in pixels across and down from the top left hand corner This is what is displayed
19. General Form of an Applet New applets are created by extending the Applet class contained in the java . applet package. Also, the package java.awt is needed for the graphical interface of the applet. In general, an applet program would look like the following: import java.applet.*; import java.awt.*; public class AppletName extends Applet { . . . }
20. General Form of an Applet (cont’d) An applet overrides a set of methods in the class Applet to implement its functionality. These methods are used as an interface with the browser or the applet viewer. An applet does not need to override those methods it does not use. The following lists the most important methods that are usually used: import java.applet.*; import java.awt.*; public class AppletName extends Applet { public void init (){ . . . } public void start (){ . . . } public void stop (){ . . . } public void destroy (){ . . .} public void paint (Graphics g ){ . . .} }
21. Applet Initialization and Termination When an applet begins, the browser calls the following methods, in this sequence: init() , start() . Every time the applet is redrawn, the method paint() is called. When an applet is terminated, the following sequence of methods is invoked: stop() , destroy(). Called just before the applet is terminated. Your applet should override this method if it needs to perform any cleanup prior to its destruction. destroy() Called to suspend execution of the applet. Once stopped, an applet is restarted when the execution environment calls start() . stop() Called by the execution environment when an applet should start or resume execution. It is automatically called after init() when an applet first begins. start() Applets do not usually have main method; instead they have the init() method that, like main() , is invoked by the execution environment. It is the first method called for any applet . It is called only once during the run-time of an applet. init() Comment Method
22. Applet methods public void init () public void start () public void stop () public void destroy () public void paint (Graphics) Also: public void repaint() public void update (Graphics) public void showStatus(String) public String getParameter(String)
23. public void init ( ) init() is the first method to execute init() is an ideal place to initialize variables init() is the best place to define the GUI Components (buttons, text fields, checkboxes, etc.), lay them out, and add listeners to them Almost every applet you ever write will have an init( ) method
24. start( ) , stop( ) and destroy( ) start() and stop( ) are used when the Applet is doing time-consuming calculations that you don’t want to continue when the page is not in front public void start() is called: Right after init( ) Each time the page is loaded and restarted public void stop( ) is called: When the browser leaves the page Just before destroy( ) public void destroy( ) is called after stop( ) Use destroy() to explicitly release system resources (like threads) System resources are usually released automatically
25. Methods are called in this order init and destroy are only called once each start and stop are called whenever the browser enters and leaves the page do some work is code called by your listeners paint is called when the applet needs to be repainted init() start() stop() destroy() do some work
26. public void paint(Graphics g) Needed if you do any drawing or painting other than just using standard GUI Component s Any painting you want to do should be done here, or in a method you call from here Painting that you do in other methods may or may not happen Never call paint( Graphics ) , call repaint( )
27. repaint( ) Call repaint( ) when you have changed something and want your changes to show up on the screen You do not need to call repaint() when something in Java’s own components (Buttons, TextFields, etc.) You do need to call repaint() after drawing commands ( drawRect(...) , fillRect(...) , drawString(...) , etc.) repaint( ) is a request --it might not happen When you call repaint( ) , Java schedules a call to update(Graphics g )
28. update( ) When you call repaint( ) , Java schedules a call to update(Graphics g) Here's what update does: public void update(Graphics g) { // Fills applet with background color, then paint(g); }
29. The paint() method The paint() method is called by the execution environment (i.e. the browser) each time the applet has to be redrawn. The inherited paint() method is empty. In order to draw anything on the applet, this method must be overridden. paint() method takes an object of class Graphics as an input argument, which is passed by the execution environment. public void paint(Graphics g){ . . . } This Graphics object represents a drawing area. It has methods to draw strings and many shapes. Also, it can manipulate fonts and colors.
30. The Graphics Object A Graphics object has a coordinate system that is illustrated below: Anything that is drawn on the Graphics object, appears on the applet. Some of the drawing methods of the Graphics object are: drawString() drawLine() drawRect() drawOval() (0,0) x y
31. Displaying Strings Using the Graphics Object To display a string on the Graphics object, the method drawString() can be used. It has the following arguments: void drawString( String str, int x, int y) str is the string to be displayed, x and y are the coordinates of the top left point of the string. For example, the following applet displays the string “Hello World!!” starting at the point (50,25). Its file name must be HelloApplet.java. import java.applet.*; import java.awt.*; public class HelloApplet extends Applet { public void paint(Graphics g) { // overriding paint() method g.drawString("Hello world!", 50, 25); } }
32. Placing an Applet in a Web Page Recall that web pages are written in HTML. HTML language describes the appearance of a page using tags . For example, <html> is a tag. Another tag is <body> . Some tags have a closing tag . For example, <html> is closed by </html> . HTML is based on text, just like Java. You can use any editor (like Notepad or JCreator) to write HTML files. HTML files should have the extension HTML, like (first.html). All HTML pages should look like: <html> <body> The body of the html page… write whatever you like here. </body> </html>
33. Placing an Applet in a Web Page (cont’d) To place an applet in a web page, the <applet> tag is used in the body of an HTML page as follows: < applet code =“HelloApplet.class” width =600 height =100> </ applet > The parts in green are called attributes . The applet tag has three mandatory (non-optional) attributes: code: the name of the class file of the applet. width: the width of the applet, in pixels. height: the height of the applet, in pixels. If the class file is not at the same folder as the HTML page, the codebase attribute is used to indicate the location of the class file relative to the directory that has the HTML page. < applet code =“HelloApplet.class” codebase =“app\” width =600 height =100> </ applet >
34. Colors The class Color of java . awt package is used to define Color objects. All colors can be specified as a mix of three primary colors : red, green, and blue. A particular color can be specified by three integers, each between 0 and 255, or by three float values, each between 0.0 and 1.0. The class Color has some pre-defined colors that are commonly used. 255, 255, 0 1.0F, 1.0F, 0.0F Color.yellow 255, 255, 255 1.0F, 1.0F, 1.0F Color.white 255, 0, 0 1.0F, 0.0F, 0.0F Color.red 255, 175, 175 1.0F, 0.7F, 0.7F Color.pink 255, 200, 0 1.0F, 0.8F, 0.0F Color.orange 255, 0, 255 1.0F, 0.0F, 1.0F Color.magenta RGB Value (integer) RGB Value (float) Color 0, 255, 0 0.0F, 1.0F, 0.0F Color.green 192, 192, 192 0.75F, 0.75F, 0.75F Color.lightGray 64, 64, 64 0.25F, 0.25F, 0.25F Color.darkGray 128, 128, 128 0.5F, 0.5F, 0.5F Color.gray 0, 255, 255 0.0F, 1.0F, 1.0F Color.cyan 0, 0, 255 0.0F, 0.0F, 1.0F Color.blue 0, 0, 0 0.0F, 0.0F, 0.0F Color.black RGB Value (integer) RGB Value (float) Color
35. Colors (cont’d) A Color object can be created using one of two constructors: Color(int red, int green, int blue) Color(float red, float green, float blue) For example: Color c1 = new Color(255, 100, 18); Color c2 = new Color(0.2F, 0.6F, 0.3F); By default, the Graphics object has a black foreground and a light gray background . This can be changed using the following methods (of the Graphics object): void setBackground(Color newColor) void setForeground(Color newColor) void setColor(Color newColor)
36. Colors (cont’d) The following example displays some strings in different colors. Although it is possible to set the background and foreground colors in the paint() method, a good place to set these colors is in the init() method. import java.awt.*; import java.applet.*; public class MyApplet extends Applet { public void init() { setBackground(Color.blue); setForeground(Color.yellow); } public void paint(Graphics g) { g.drawString("A yellow string", 50, 10); g.setColor(Color.red) ; g.drawString("A red string", 50, 50); g.drawString("Another red string", 50, 90); g.setColor(Color.magenta) ; g.drawString("A magenta string", 50, 130); } }
37. Drawing Some Shapes An oval can be drawn using the method drawOval() as follows: void drawOval( int x, int y, int width, int height ) A rectangle can be drawn using the method drawRect() as follows: void drawRect( int x, int y, int width, int height ) A line linking two points can be drawn using the method drawLine() as follows: void drawLine( int x1, int y1, int x2, int y2 ) To draw a shape using a specific color, the method setColor() should be used before drawing the shape. There are no methods called drawCircle() or drawSquare(). How can we draw a circle or a square..???
38. Executing a Java Applet A Java applet must be compiled into bytecode before it can be used in a web page. When a web page containing an <applet> tag is opened, the associated bytecode is downloaded from the location specified by the CODE or CODEBASE attribute. This location can be in the local machine or in a machine across the web . To interpret the applet bytecode, the browser must have a Java plug-in . Also, an applet can be executed using the applet viewer , which comes with the JDK.
39. Comparing Applets with Applications Has a restricted access to the machine resources (cannot open files or run other programs) {Security reasons} Has an unrestricted access to the machine resources Almost always works with GUI Can work with command-line (like what are always doing), or using a graphical user-interface (GUI) {More on this in ICS-201} Has to extend java.applet.Applet class Doesn’t have to extend any class Starts by the init() method Starts by the main() method Has to run inside another program, called execution environment (like a web browser or an applet viewer ) Runs independently An Applet An Application
40. A Simple Java Applet: Drawing a String Now, create applets of our own Take a while before we can write applets like in the demos Cover many of same techniques Upcoming program Create an applet to display "Welcome to Java Programming!" Show applet and HTML file, then discuss them line by line
41. Java applet Program Output 1 // Fig. 3.6: WelcomeApplet.java 2 // A first applet in Java. 3 4 // Java core packages 5 import java.awt.Graphics; // import class Graphics 6 7 // Java extension packages 8 import javax.swing.JApplet; // import class JApplet 9 10 public class WelcomeApplet extends JApplet { 11 12 // draw text on applet’s background 13 public void paint( Graphics g ) 14 { 15 // call inherited version of method paint 16 super .paint( g ); 17 18 // draw a String at x-coordinate 25 and y-coordinate 25 19 g.drawString( "Welcome to Java Programming!" , 25 , 25 ); 20 21 } // end method paint 22 23 } // end class WelcomeApplet import allows us to use predefined classes (allowing us to use applets and graphics, in this case). extends allows us to inherit the capabilities of class JApplet . Method paint is guaranteed to be called in all applets. Its first line must be defined as above.
42. 3.3 A Simple Java Applet: Drawing a String Comments Name of source code and description of applet Import predefined classes grouped into packages import statements tell compiler where to locate classes used When you create applets, import the JApplet class (package javax.swing ) import the Graphics class (package java.awt ) to draw graphics Can draw lines, rectangles ovals, strings of characters import specifies directory structure 5 import java.awt.Graphics; // import class Graphics 8 import javax.swing.JApplet; // import class JApplet // Fig. 3.6: WelcomeApplet.java 2 // A first applet in Java.
43. 3.3 A Simple Java Applet: Drawing a String Applets have at least one class definition (like applications) Rarely create classes from scratch Use pieces of existing class definitions Inheritance - create new classes from old ones (ch. 15) Begins class definition for class WelcomeApplet Keyword class then class name extends followed by class name Indicates class to inherit from ( JApplet ) JApplet : superclass (base class) WelcomeApplet : subclass (derived class) WelcomeApplet now has methods and data of JApplet 10 public class WelcomeApplet extends JApplet {
44. 3.3 A Simple Java Applet: Drawing a String Class JApplet defined for us Someone else defined "what it means to be an applet" Applets require over 200 methods! extends JApplet Inherit methods, do not have to define them all Do not need to know every detail of class JApplet 10 public class WelcomeApplet extends JApplet {
45. 3.3 A Simple Java Applet: Drawing a String Class WelcomeApplet is a blueprint appletviewer or browser creates an object of class WelcomeApplet Keyword public required File can only have one public class public class name must be file name 10 public class WelcomeApplet extends JApplet {
46. 3.3 A Simple Java Applet: Drawing a String Our class inherits method paint from JApplet By default, paint has empty body Override (redefine) paint in our class Methods paint , init , and start Guaranteed to be called automatically Our applet gets "free" version of these by inheriting from JApplet Free versions have empty body (do nothing) Every applet does not need all three methods Override the ones you need Applet container “draws itself” by calling method paint 13 public void paint( Graphics g )
47. 3.3 A Simple Java Applet: Drawing a String Method paint Lines 13-21 are the definition of paint Draws graphics on screen void indicates paint returns nothing when finishes task Parenthesis define parameter list - where methods receive data to perform tasks Normally, data passed by programmer, as in JOptionPane.showMessageDialog paint gets parameters automatically Graphics object used by paint Mimic paint 's first line 13 public void paint( Graphics g )
48. 3.3 A Simple Java Applet: Drawing a String Calls version of method paint from superclass JApplet Should be first statement in every applet’s paint method Body of paint Method drawString (of class Graphics ) Called using Graphics object g and dot operator ( . ) Method name, then parenthesis with arguments First argument: String to draw Second: x coordinate (in pixels) location Third: y coordinate (in pixels) location Java coordinate system Measured in pixels (picture elements) Upper left is ( 0 , 0 ) 16 super .paint( g ); 19 g.drawString( "Welcome to Java Programming!" , 25 , 25 );
49. 3.3.1 Compiling and Executing WelcomeApplet Running the applet Compile javac WelcomeApplet.java If no errors, bytecodes stored in WelcomeApplet.class Create an HTML file Loads the applet into appletviewer or a browser Ends in .htm or .html To execute an applet Create an HTML file indicating which applet the browser (or appletviewer ) should load and execute
50. 3.3.1 Compiling and Executing WelcomeApplet Simple HTML file ( WelcomeApplet.html ) Usually in same directory as .class file Remember, .class file created after compilation HTML codes (tags) Usually come in pairs Begin with < and end with > Lines 1 and 4 - begin and end the HTML tags Line 2 - begins <applet> tag Specifies code to use for applet Specifies width and height of display area in pixels Line 3 - ends <applet> tag 1 <html> 2 <applet code = "WelcomeLines.class" width = "300" height = "40" > 3 </applet> 4 </html>
52. 3.4 Two More Simple Applets: Drawing Strings and Lines More applets First example Display two lines of text Use drawString to simulate a new line with two drawString statements Second example Method g.drawLine(x1, y1, x2, y2 ) Draws a line from ( x1 , y1 ) to ( x2 , y2 ) Remember that ( 0 , 0 ) is upper left Use drawLine to draw a line beneath and above a string
53. 1 // Fig. 3.8: WelcomeApplet2.java 2 // Displaying multiple strings in an applet. 3 4 // Java core packages 5 import java.awt.Graphics; // import class Graphics 6 7 // Java extension packages 8 import javax.swing.JApplet; // import class JApplet 9 10 public class WelcomeApplet2 extends JApplet { 11 12 // draw text on applet’s background 13 public void paint( Graphics g ) 14 { 15 // call inherited version of method paint 16 super .paint( g ); 17 18 // draw two Strings at different locations 19 g.drawString( "Welcome to" , 25 , 25 ); 20 g.drawString( "Java Programming!" , 25 , 40 ); 21 22 } // end method paint 23 24 } // end class WelcomeApplet2 1. import 2. Class WelcomeApplet2 ( extends JApplet ) 3. paint 3.1 drawString 3.2 drawString on same x coordinate, but 15 pixels down The two drawString statements simulate a newline. In fact, the concept of lines of text does not exist when drawing strings.
57. 3.4 Two More Simple Applets: Drawing Strings and Lines Method drawLine of class Graphics Takes as arguments Graphics object and line’s end points X and y coordinate of first endpoint X and y coordinate of second endpoint
58. 3.5 Another Java Applet: Adding Floating-Point Numbers Next applet Mimics application for adding two integers (Fig 2.9) This time, use floating point numbers (numbers with a decimal point) Using primitive data types Double – double precision floating-point numbers Float – single precision floating-point numbers Show program, then discuss
59. AdditionApplet.java 1. import 2. Class AdditionApplet ( extends JApplet ) 3. Instance variable 4. init 4.1 Declare variables 4.2 showInputDialog 4.3 parseDouble 1 // Fig. 3.12: AdditionApplet.java 2 // Adding two floating-point numbers. 3 4 // Java core packages 5 import java.awt.Graphics; // import class Graphics 6 7 // Java extension packages 8 import javax.swing.*; // import package javax.swing 9 10 public class AdditionApplet extends JApplet { 11 double sum; // sum of values entered by user 12 13 // initialize applet by obtaining values from user 14 public void init () 15 { 16 String firstNumber; // first string entered by user 17 String secondNumber; // second string entered by user 18 double number1; // first number to add 19 double number2; // second number to add 20 21 // obtain first number from user 22 firstNumber = JOptionPane.showInputDialog( 23 "Enter first floating-point value" ); 24 25 // obtain second number from user 26 secondNumber = JOptionPane.showInputDialog( 27 "Enter second floating-point value" ); 28 29 // convert numbers from type String to type double 30 number1 = Double.parseDouble( firstNumber ); 31 number2 = Double.parseDouble( secondNumber ); 32 2 // Adding two floating-point numbers 3 import java.awt.Graphics; // import class Graphics 5 6 public class AdditionApplet extends JApplet { 7 double sum; // sum of the values entered by the user 8 9 public void init() 10 { 11 String firstNumber, // first string entered by user 12 secondNumber; // second string entered by user 13 double number1, // first number to add 14 number2; // second number to add 15 16 // read in first number from user 17 firstNumber = 18 JOptionPane.showInputDialog( 19 "Enter first floating-point value" ); 20 21 // read in second number from user 22 secondNumber = 23 JOptionPane.showInputDialog( 24 "Enter second floating-point value" ); 25 26 27 // convert numbers from type String to type double * allows any class in the the package to be used. Instance variable sum may be used anywhere in the class, even in other methods. Data type double can store floating point numbers.
60. 5. Draw applet contents 5.1 Draw a rectangle 5.2 Draw the results HTML file 33 // add numbers 34 sum = number1 + number2; 35 } 36 37 // draw results in a rectangle on applet’s background 38 public void paint( Graphics g ) 39 { 40 // call inherited version of method paint 41 super .paint( g ); 42 43 // draw rectangle starting from (15, 10) that is 270 44 // pixels wide and 20 pixels tall 45 g.drawRect( 15 , 10 , 270 , 20 ); 46 47 // draw results as a String at (25, 25) 48 g.drawString( "The sum is " + sum, 25 , 25 ); 49 50 } // end method paint 51 52 } // end class AdditionApplet 1 <html> 2 <applet code = "WelcomeLines.class" width = "300" height = "40" > 3 </applet> 4 </html> 31 // add the numbers 32 sum = number1 + number2; 33 } 34 35 public void paint( Graphics g ) 36 { 37 // draw the results with g.drawString 38 g.drawRect( 15, 10, 270, 20 ); 39 g.drawString( "The sum is " + sum, 25, 25 ); 40 } 41 } 1 <html> 2 <applet code="AdditionApplet.class" width=300 height=50> 3 </applet> 4 </html> drawRect takes the upper left coordinate, width, and height of the rectangle to draw.
62. 3.5 Another Java Applet: Adding Floating-Point Numbers Lines 1-2: Comments Line 5: import s class Graphics import not needed if use full package and class name public void paint ( java.awt.Graphics g ) Line 8: specify entire javax.swing package * indicates all classes in javax.swing are available Includes JApplet and JOptionPane Use JOptionPane instead of javax.swing.JOptionPane * does not not load all classes Compiler only loads classes it uses 5 import java.awt.Graphics; 8 import javax.swing.*;
63. 3.5 Another Java Applet: Adding Floating-Point Numbers Begin class definition Inherit from JApplet , import ed from package javax.swing Instance variable declaration Each object of class gets own copy of the instance variable Declared in body of class, but not inside methods Variables declared in methods are local variables Can only be used in body of method Instance variables can be used anywhere in class Have default value ( 0.0 in this case) 10 public class AdditionApplet extends JApplet { 11 double sum; // sum of values entered by user
64. 3.5 Another Java Applet: Adding Floating-Point Numbers Primitive data type double Used to store floating point (decimal) numbers Method init Normally initializes instance variables and applet class Guaranteed to be first method called in applet First line must always appear as above Returns nothing ( void ), takes no arguments Begins body of method init 11 double sum; // sum of values entered by user 14 public void init () 15 {
65. 3.5 Another Java Applet: Adding Floating-Point Numbers Declare variables Two types of variables Reference variables (called references) Refer to objects (contain location in memory) Objects defined in a class definition Can contain multiple data and methods paint receives a reference called g to a Graphics object Reference used to call methods on the Graphics object Primitive data types (called variables) Contain one piece of data 16 String firstNumber; // first string entered by user 17 String secondNumber; // second string entered by user 18 double number1; // first number to add 19 double number2; // second number to add
66. 3.5 Another Java Applet: Adding Floating-Point Numbers Distinguishing references and variables If data type is a class name, then reference String is a class firstNumber , secondNumber If data type a primitive type, then variable double is a primitive data type number1 , number2 16 String firstNumber; // first string entered by user 17 String secondNumber; // second string entered by user 18 double number1; // first number to add 19 double number2; // second number to add
67. 3.5 Another Java Applet: Adding Floating-Point Numbers Method JOptionPane.showInputDialog Prompts user for input with string Enter value in text field, click OK If not of correct type, error occurs In Chapter 14 learn how to deal with this Returns string user inputs Assignment statement to string Lines 26-27: As above, assigns input to secondNumber 22 firstNumber = JOptionPane.showInputDialog( 23 "Enter first floating-point value" );
68. 3.5 Another Java Applet: Adding Floating-Point Numbers static method Double.parseDouble Converts String argument to a double Returns the double value Remember static method syntax ClassName.methodName( arguments ) Assignment statement sum an instance variable, can use anywhere in class Not defined in init but still used 34 sum = number1 + number2; 30 number1 = Double.parseDouble( firstNumber ); 31 number2 = Double.parseDouble( secondNumber );
69. 3.5 Another Java Applet: Adding Floating-Point Numbers Ends method init appletviewer (or browser) calls inherited method start start usually used with multithreading Advanced concept, in Chapter 15 We do not define it, so empty definition in JApplet used Next, method paint called Method drawRect( x1, y1, width, height ) Draw rectangle, upper left corner ( x1, y1 ), specified width and height Line 45 draws rectangle starting at (15, 10) with a width of 270 pixels and a height of 20 pixels 33 } 45 g.drawRect( 15 , 10 , 270 , 20 );
70. 3.5 Another Java Applet: Adding Floating-Point Numbers Sends drawString message (calls method) to Graphics object using reference g "The sum is" + sum - string concatenation sum converted to a string sum can be used, even though not defined in paint Instance variable, can be used anywhere in class Non-local variable 48 g.drawString( "The sum is " + sum, 25 , 25 );
71. 3.6 Viewing Applets in a Web Browser Applets can execute on Java-enabled browsers Many different browser version supporting different Java version specifications Some support for Java 1.0, many for Java 1.1 inconsistently Netscape Navigator 6 supports Java 2 (section 3.6.1) Use Java Plug-in to execute Java 2 applets on other browsers (section 3.6.2)
72. Fonts By default, strings are drawn using the default font, plain style and default font size. To change the font, style or size, we need to create an object of class java.awt.Font and pass it to the setFont() method of the graphics object used in the paint() method. To create such a Font object, we need to specify the following parameters: The font name. The Style (Font.PLAIN, Font.BOLD, Font.ITALIC, or Font.BOLD + Font.ITALIC). The font size. The font name can be the name of any font available on the particular computer (such as: TimesRoman, Courier, Helvetica etc.,) or any of the logical names shown in the table below: A screen font suitable for user input in text fields DialogInput A screen font suitable for labels in dialogs Dialog A font in which all characters have the same width. e.g. Courier Monospaced A font without small segments, e.g. Helvetica SansSerif A font with small segments at the end, e.g. Times New Roman Serif
73. Fonts (cont’d) Example: The following applet displays the word Applet in large SansSerif font. import java.applet.*; import java.awt.*; public class BigFontApplet extends Applet{ public void paint(Graphics g){ final int SIZE = 48; Color myColor = new Color(0.25F, 0.5F, 0.75F); Font myFont = new Font("SansSerif", Font.BOLD, SIZE); g.setColor(myColor); g.setFont(myFont); g.drawString("Applet",5,60); } }
74. Fonts (cont’d) If an applet will use several fonts , it is good to create the font objects in the init() method: import java.applet.*; import java.awt.*; public class FontExamples extends Applet{ private Font f, fb, fi, fbi; public void init() { setBackground(Color.yellow); f = new Font("TimesRoman", Font.PLAIN, 18); fb = new Font("Courier", Font.BOLD, 20); fi = new Font("TimesRoman", Font.ITALIC, 18); fbi = new Font("Helvetica", Font.BOLD + Font.ITALIC, 25); } public void paint(Graphics g){ g.setColor(Color.blue); g.setFont(f); g.drawString("This is TimesRoman plain font", 10, 25); //... } }
75. Drawing in an Applet import java.applet.Applet; import java.awt.*; // assume that the drawing area is 150 by 150 public class SquareAndRectangle extends Applet { final int areaSide = 150 ; final int width = 100, height = 50; public void paint ( Graphics gr ) { setBackground( Color.green ); gr.setColor( Color.red ); // outline the drawing area gr.drawRect( 0, 0, areaSide-1, areaSide-1 ); // draw interiour rectange. gr.drawRect( areaSide/2 - width/2 , areaSide/2 - height/2, width, height ); } }
76. Java’s coordinate system Java uses an (x, y) coordinate system (0, 0) is the top left corner (50, 0) is 50 pixels to the right of (0, 0) (0, 20) is 20 pixels down from (0, 0) (w - 1, h - 1) is just inside the bottom right corner, where w is the width of the window and h is its height (0, 0) (0, 20) (50, 0) (50, 20) (w-1, h-1) (50, 0) (0, 0) (0, 20) (50, 20)
77. Drawing rectangles There are two ways to draw rectangles: g.drawRect( left , top , width , height ); g.fillRect( left , top , width , height );
78. Drawing strings A String is a sequence of characters enclosed in double quote marks "Hello, World!" A double quote mark in a String must be preceded by a backslash ( \ ) "He said, \"Please don't go!\" " To draw a string, you need to specify not only what you want to say, but where to say it g.drawString( string , left , top ); For example, g.drawString("Example JApplet", 20, 80);
79. The complete applet import javax.swing.JApplet; import java.awt.*; // CIT 591 example public class Drawing extends JApplet { public void paint(Graphics g) { g.setColor(Color.BLUE); g.fillRect(20, 20, 50, 30); g.setColor(Color.RED); g.fillRect(50, 30, 50, 30); g.setColor(Color.BLACK); g.drawString("Example JApplet", 20, 80); } }
80. More java.awt.Graphics methods g.drawLine( x1 , y1 , x2 , y2 ); g.drawOval( left , top , width , height ); g.fillOval( left , top , width , height ); g.drawRoundRect( left , top , width , height, arcWidth , arcHeight ); arcWidth , arcHeight define the “roundedness” of corners g.fillRoundRect( left , top , width , height, arcWidth , arcHeight ); g.drawArc( left , top , width , height , startAngle , arcAngle ); Angles are in degrees 0 degrees is the 3 o’clock position Positive angles are to the right g.FillArc( left , top , width , height , startAngle , arcAngle );
81. Still more Graphics methods g.drawPolygon( xPoints , yPoints , n ); g.fillPolygon( xPoints , yPoints , n ); xPoints and yPoints are int arrays of size n One way to write an int array is: new int[] { value1 , value2 , ..., valueN } Example: g.drawPolygon(new int[] { 250, 290, 210 }, new int[] { 210, 290, 290 }, 3); draws a triangle using the 3 points (250, 210), (290, 290), and (210, 290). g.drawPolyline( xPoints , yPoints , n ); A “polyline” is like a polygon, except the first and last points are not automatically connected Hence, there is no “fillPolyline” method
82. The HTML page You can only run an applet from an HTML page The HTML looks something like this: <html> <body> <h1>Drawing Applet</h1> <applet code="Drawing.class" width="100" height="150"> </applet> </body> </html> Eclipse will create this HTML for you You don’t even need to think about the HTML just yet
83. Other useful JApplet methods System.out.println(String s ) Works from appletviewer , not from browsers Automatically opens an output window. showStatus(String s ) displays the String in the applet’s status line. Each call overwrites the previous call. You have to allow time to read the line!