Unit 5
JAR & Swing
JAR file format creation
A JAR (Java ARchive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. JAR files are archive files that include a Java-specific manifest file
How to Create a Jar File in Java
How to make an executable jar file in Java
The jar (Java Archive) tool of JDK provides the facility to create the executable jar file. An executable jar file calls the main method of the class if you double click it.
To create the executable jar file, you need to create .mf file, also known as manifest file.
Creating manifest file
To create manifest file, you need to write Main-Class, then colon, then space, then classname then enter. For example:
myfile.mf
As you can see, the mf file starts with Main-Class colon space class name. Here, class name is First.
In mf file, new line is must after the class name.
Java Archive (JAR) Files
Java Archive (JAR) is a platform-independent file format that allow you to compress and bundle multiple files associated with a Java application, applet, or WebStart application into a single file. JAR is based on the popular ZIP algorithm, and mimic the Unix's tar (or tape archive) file format (e.g., jar and tar tools have the same command-line options).
JAR files provide the following functions:
The Java Runtime (JRE) (or Java applications) can load classes from the JAR file directly, without un-jarring the file. Furthermore, the JAR files use the same file format as ZIP files, and can be opened and manipulated via ZIP programs such as WinZIP or WinRAR.
Creating JAR File
Needless to say, using IDE to create a JAR file is much more easier than the command-line jar tool.
Create JAR File using Command-Line "jar" Tool
Creating JAR file using command-line jar tool is clumpy! It is presented here for your basic understanding and completeness. In practice, you should use your IDE (such as Eclipse/NetBeans) to create JAR file instead (which are presented in the following sections).
Syntax
To create a JAR file using the jar tool, issue the jar command (on CMD shell) with 'c' option:
> jar cvf jarFile inputFileDir1 inputFileDir2 ...
where:
Example
For example, suppose that "images" is an sub-directory under the current directory, the following command jar-up all the ".class" files of the current directory and the entire "images" sub-directory into "hello.jar". The 'v' option instructs the tool to produce the information messages.
Internationalization
Internationalization is also abbreviated as I18N because there are total 18 characters between the first letter 'I' and the last letter 'N'.
Internationalization is a mechanism to create such an application that can be adapted to different languages and regions.
Internationalization is one of the powerful concept of java if you are developing an application and want to display messages, currencies, date, time etc. according to the specific region or language.
Localization
Localization is also abbreviated as I10N because there are total 10 characters between the first letter 'L' and last letter 'N'. Localization is the mechanism to create such an application that can be adapted to a specific language and region by adding locale-specific text and component.
Understanding the culturally dependent data before starting internationalization
Before starting the internationalization, Let's first understand what are the informations that differ from one region to another. There is the list of culturally dependent data:
Fields of Locale class
There are fields of Locale class:
Constructors of Locale class
There are three constructors of Locale class.They are as follows:
Commonly used methods of Locale class
There are given commonly used methods of Locale class.
Example of Local class that prints the informations of the default locale
Output:United States
English
English (United States)
USA
eng
en
US
Example of Local class that prints english in different languages
Example of Local class that print display language of many locales
Output:en_US: English
es_ES: espa?ol
it_IT: italiano
Swing Programming
Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java.
Unlike AWT, Java Swing provides platform-independent and lightweight components.
The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.
No.
Java AWT
Java Swing
1)
AWT components are platform-dependent.
Java swing components are platform-independent.
2)
AWT components are heavyweight.
Swing components are lightweight.
3)
AWT doesn't support pluggable look and feel.
Swing supports pluggable look and feel.
4)
AWT provides less components than Swing.
Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.
5)
AWT doesn't follows MVC(Model View Controller) where model represents data, view represents presentation and controller acts as an interface between model and view.
Swing follows MVC.
Java AWT
Java Swing
JQuery: Introduction-
jQuery tutorial for beginners and professionals provides deep knowledge of jQuery technology. Our jQuery tutorial will help you to learn jQuery fundamentals, example, selectors, events, effects, traversing, CSS and attributes.
What is jQuery
jQuery Example
Many of the biggest companies on the Web use jQuery, such as:
There are several ways to start using jQuery on your web site. You can:
The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag (notice that the <script> tag should be inside the <head> section):
<head>�<script src="jquery-3.3.1.min.js"></script>�</head>
Syntax | Description | Example |
$("*") | Selects all elements | |
$(this) | Selects the current HTML element | |
$("p.intro") | Selects all <p> elements with class="intro" | |
$("p:first") | Selects the first <p> element | |
$("ul li:first") | Selects the first <li> element of the first <ul> | |
$("ul li:first-child") | Selects the first <li> element of every <ul> | |
$("[href]") | Selects all elements with an href attribute | |
$("a[target='_blank']") | Selects all <a> elements with a target attribute value equal to "_blank" | |
$("a[target!='_blank']") | Selects all <a> elements with a target attribute value NOT equal to "_blank" | |
$(":button") | Selects all <button> elements and <input> elements of type="button" | |
$("tr:even") | Selects all even <tr> elements | |
$("tr:odd") | Selects all odd <tr> elements |
jQuery Animations - The animate() Method
The jQuery animate() method is used to create custom animations.
Syntax:
$(selector).animate({params},speed,callback);
The required params parameter defines the CSS properties to be animated.
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.
The optional callback parameter is a function to be executed after the animation completes.
The following example demonstrates a simple use of the animate() method; it moves a <div> element to the right, until it has reached a left property of 250px:
Example
$("button").click(function(){� $("div").animate({left: '250px'});�});
jQuery animate() - Manipulate Multiple Properties
Notice that multiple properties can be animated at the same time:
Example
$("button").click(function(){� $("div").animate({� left: '250px',� opacity: '0.5',� height: '150px',� width: '150px'� });�});
jQuery animate() - Using Relative Values
It is also possible to define relative values (the value is then relative to the element's current value). This is done by putting += or -= in front of the value:
Example
$("button").click(function(){� $("div").animate({� left: '250px',� height: '+=150px',� width: '+=150px'� });�});
jQuery animate() - Using Pre-defined Values
You can even specify a property's animation value as "show", "hide", or "toggle":
Example
$("button").click(function(){� $("div").animate({� height: 'toggle'� });�});
jQuery animate() - Uses Queue Functionality
By default, jQuery comes with queue functionality for animations.
This means that if you write multiple animate() calls after each other, jQuery creates an "internal" queue with these method calls. Then it runs the animate calls ONE by ONE.
So, if you want to perform different animations after each other, we take advantage of the queue functionality:
Example 1
$("button").click(function(){� var div = $("div");� div.animate({height: '300px', opacity: '0.4'}, "slow");� div.animate({width: '300px', opacity: '0.8'}, "slow");� div.animate({height: '100px', opacity: '0.4'}, "slow");� div.animate({width: '100px', opacity: '0.8'}, "slow");�});
The example below first moves the <div> element to the right, and then increases the font size of the text:
Example 2
$("button").click(function(){� var div = $("div");� div.animate({left: '100px'}, "slow");� div.animate({fontSize: '3em'}, "slow");�});