SlideShare ist ein Scribd-Unternehmen logo
1 von 23
PROGRAMMING IN JAVA
A. SIVASANKARI
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATION
SHANMUGA INDUSTRIES ARTS AND SCIENCE
COLLEGE,
TIRUVANNAMALAI. 606601.
Email: sivasankaridkm@gmail.com
PROGRAMMING IN JAVA
UNIT – 4
PART I
 APPLET
 APPLETS - GUI
COMPONENTS
 APPLET PARAMETERS
 LIFE CYCLE OF AN APPLET
 APPLICATION
CONVERSION TO APPLETS
 AWT AND AWT HIERARCHY
 SWING COMPONENTS
A. SIVASANKARI - SIASC-TVM UNIT-4
PROGRAMMING IN JAVA
APPLET BASICS
• An applet is a Java program that runs in a Web browser. An applet can be a fully functional
Java application because it has the entire Java API at its disposal.
• There are some important differences between an applet and a standalone Java application,
including the following
• An applet is a Java class that extends the java.applet.Applet class.
• A main() method is not invoked on an applet, and an applet class will not define main().
• Applets are designed to be embedded within an HTML page.
• When a user views an HTML page that contains an applet, the code for the applet is
downloaded to the user's machine.
• A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or
a separate runtime environment.
• The JVM on the user's machine creates an instance of the applet class and invokes various
methods during the applet's lifetime.
• Applets have strict security rules that are enforced by the Web browser. The security of an
applet is often referred to as sandbox security, comparing the applet to a child playing in a
sandbox with various rules that must be followed.
• Other classes that the applet needs can be downloaded in a single Java Archive (JAR) file.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
APPLETS (GUI COMPONENTS)
• Applets are small java programs that run inside of a web browser.
• It is also stored as part of webpage.
• The applet classes contained in the java applet package.
• It also defines three interfaces.
1. Applet context
2. Audio clip
3. Applet stub
• It will be executed within HTML tag.
• It is an intelligent program.
• It is an application designed to be transmitted over internet and executed by a java compatible
with browser.
SYNTAX
• <applet code= “ program name” width=200 height=200> </applet>
APPLET INITIALIZATION AND TERMINATION
When started
• Init( )
• Start( )
• Paint( )
When Applet is terminated
• Stop( )
• Destroy( )
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
Another method is overriding update( )
EXAMPLE
• Public void paint (Graphics g)
• {
• Update(g);
• }
APPLET CLASSES OR METHODS
APPLET METHODS DESCRIPTION
void destroy( ) It called by the browser just before an applet is
terminated.
String getAppletinfo( ) It should return String.
URL getcodeBase( ) It returns URL
image getimage(URL url) It returns image object.
void init( ) It begins execution.
void start( ) It should starts of execution.
Void stop( ) Browser to suspend execution of applets.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
EXAMPLE
• import java.awt.*;
• import java.applet.*;
• /*<applet code=”sample” width=300 height=200></applet>
• public class sample extends Applet{
• Public void init( ){
• setBackground(color.cyan)}
• Public void paint( Graphics g){
• g.drawString(“This is sample”,10,20);
• show status(“This is status window”);}}
HTMLAPPLET TAGS
• <APPLET[CODE BASE=code base URL] name of file CODE=applet file
• [ALT= alternate text] [NAME= applet instance name]name of attributes
• [WIDTH=pixels, HEIGHT=PIXELS]height and width of window
• [ALIGN= alignment]top, bottom, up, down, middle
• [VSPACE=Pixels]vertical space [HSPACE=Pixels]>horizontal space
• [<param name=attribute name VALUE=attribute value>]
• </APPLET>
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
LIFE CYCLE OF AN APPLET
• Four methods in the Applet class gives you the framework on which you build any
serious applet
• init − This method is intended for whatever initialization is needed for your applet.
It is called after the param tags inside the applet tag have been processed.
• start − This method is automatically called after the browser calls the init method.
It is also called whenever the user returns to the page containing the applet after
having gone off to other pages.
• stop − This method is automatically called when the user moves off the page on
which the applet sits. It can, therefore, be called repeatedly in the same applet.
• destroy − This method is only called when the browser shuts down normally.
Because applets are meant to live on an HTML page, you should not normally leave
resources behind after a user leaves the page that contains the applet.
• paint − Invoked immediately after the start() method, and also any time the applet
needs to repaint itself in the browser. The paint() method is actually inherited from
the java.awt.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
A "Hello, World" Applet
Following is a simple applet named HelloWorldApplet.java
• import java.applet.*;
• import java.awt.*;
• public class HelloWorldApplet extends Applet {
• public void paint (Graphics g) {
• g.drawString ("Hello World", 25, 50);
• }
• }
These import statements bring the classes into the scope of our applet class
• java.applet.Applet
• java.awt.Graphics
• Without those import statements, the Java compiler would not recognize the classes Applet
and Graphics, which the applet class refers to.
The Applet Class
• Every applet is an extension of the java.applet.Applet class. The base Applet class provides
methods that a derived Applet class may call to obtain information and services from the
browser context.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
These include methods that do the following
• Get applet parameters
• Get the network location of the HTML file that contains the applet
• Get the network location of the applet class directory
• Print a status message in the browser
• Fetch an image
• Fetch an audio clip
• Play an audio clip
• Resize the applet
• Additionally, the Applet class provides an interface by which the viewer or browser obtains
information about the applet and controls the applet's execution. The viewer may
• Request information about the author, version, and copyright of the applet
Request a description of the parameters the applet recognizes
1. Initialize the applet
2. Destroy the applet
3. Start the applet's execution
4. Stop the applet's execution
• The Applet class provides default implementations of each of these methods. Those
implementations may be overridden as necessary.
• The "Hello, World" applet is complete as it stands. The only method overridden is the paint
method.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
Invoking an Applet
• An applet may be invoked by embedding directives in an HTML file and viewing the file
through an applet viewer or Java-enabled browser.
• The <applet> tag is the basis for embedding an applet in an HTML file. Following is an
example that invokes the "Hello, World" applet
• <html>
• <title>The Hello, World Applet</title>
• <hr>
• <applet code = "HelloWorldApplet.class" width = "320" height = "120">
• If your browser was Java-enabled, a "Hello, World" message would appear here.
• </applet>
• <hr>
• </html>
• The code attribute of the <applet> tag is required. It specifies the Applet class to run. Width
and height are also required to specify the initial size of the panel in which an applet runs. The
applet directive must be closed with an </applet> tag.
• If an applet takes parameters, values may be passed for the parameters by adding <param>
tags between <applet> and </applet>. The browser ignores text and other tags between the
applet tags.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
GETTING APPLET PARAMETERS
• The following example demonstrates how to make an applet respond to setup
parameters specified in the document. This applet displays a checkerboard pattern
of black and a second color.
• The second color and the size of each square may be specified as parameters to the
applet within the document.
• CheckerApplet gets its parameters in the init() method. It may also get its
parameters in the paint() method. However, getting the values and saving the
settings once at the start of the applet, instead of at every refresh, is convenient and
efficient.
• The applet viewer or browser calls the init() method of each applet it runs. The
viewer calls init() once, immediately after loading the applet. (Applet.init() is
implemented to do nothing.) Override the default implementation to insert custom
initialization code.
• The Applet.getParameter() method fetches a parameter given the parameter's name
(the value of a parameter is always a string). If the value is numeric or other non-
character data, the string must be parsed.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
The following is a skeleton of CheckerApplet.java
• import java.applet.*;
• import java.awt.*;
• public class CheckerApplet extends Applet {
• int squareSize = 50; // initialized to default size
• public void init() {}
• private void parseSquareSize (String param) {}
• private Color parseColor (String param) {}
• public void paint (Graphics g) {}}
Here are CheckerApplet's init() and private parseSquareSize() methods
• public void init () {
• String squareSizeParam = getParameter ("squareSize");
• parseSquareSize (squareSizeParam);
• String colorParam = getParameter ("color");
• Color fg = parseColor (colorParam);
• setBackground (Color.black); setForeground (fg);
• } private void parseSquareSize (String param) {
• if (param == null) return;
• try { squareSize = Integer.parseInt (param); }
• catch (Exception e) { // Let default value remain }}
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• The applet calls parseSquareSize() to parse the squareSize parameter. parseSquareSize() calls
the library method Integer.parseInt(), which parses a string and returns an integer.
Integer.parseInt() throws an exception whenever its argument is invalid.
• Therefore, parseSquareSize() catches exceptions, rather than allowing the applet to fail on bad
input.
• The applet calls parseColor() to parse the color parameter into a Color value. parseColor()
does a series of string comparisons to match the parameter value to the name of a predefined
color.
• We need to implement these methods to make this applet work.
• Specifying Applet Parameters
The following is an example of an HTML file with a CheckerApplet embedded in it.
• The HTML file specifies both parameters to the applet by means of the <param> tag.
• <html>
• <title>Checkerboard Applet</title>
• <hr> <applet code = "CheckerApplet.class" width = "480" height = "320">
• <param name = "color" value = "blue">
• <param name = "squaresize" value = "30">
• </applet>
• <hr>
• </html>
• Note − Parameter names are not case sensitive.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
APPLICATION CONVERSION TO APPLETS
• It is easy to convert a graphical Java application (that is, an application that uses the AWT and
that you can start with the Java program launcher) into an applet that you can embed in a web
page.
Following are the specific steps for converting an application to an applet.
• Make an HTML page with the appropriate tag to load the applet code.
• Supply a subclass of the JApplet class. Make this class public. Otherwise, the applet cannot be
loaded.
• Eliminate the main method in the application. Do not construct a frame window for the
application. Your application will be displayed inside the browser.
• Move any initialization code from the frame window constructor to the init method of the
applet. You don't need to explicitly construct the applet object. The browser instantiates it for
you and calls the init method.
• Remove the call to setSize; for applets, sizing is done with the width and height parameters in
the HTML file.
• Remove the call to setDefaultCloseOperation. An applet cannot be closed; it terminates
when the browser exits.
• If the application calls setTitle, eliminate the call to the method. Applets cannot have title
bars. (You can, of course, title the web page itself, using the HTML title tag.)
• Don't call setVisible(true). The applet is displayed automatically
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT AND AWT HIERARCHY
• Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based
applications in java.
• Java AWT components are platform-dependent i.e. components are displayed according to the
view of operating system. AWT is heavyweight i.e. its components are using the resources of
OS.
• The java.awt package provides classes for AWT api such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
SWING COMPONENTS
• It is a set of classes that provides more powerful and flexible components that are possible
with the awt.
• Swing components are also called Java Foundation classes(JFC)
METHOD NAME COMMANDS
Abstract button Abstract super class for swing buttons.
Button group Encapsulates a mutually exclusive set of buttons.
Image Icon Encapsulates an icon.
JApplet The swing version of applet.
JButton The swing push button class.
JCheckBox Check box.
JComboBox The swing combination of dropdown list and text field.
JLabel Label.
JRadioButton Swing version of Radio Button.
JScrollpane Encapsulates a scrollable window.
JTabbedWindow Encapsulates a tabbed window.
JTable Encapsulates a table based control.
JTextField Text Box.
JTree Tree based Control.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• JAPPLETS:
• Swing must be subclasses of JApplet. Use add( ) method.
• Syntax:
• Container getContentpane( )
• Example:
• void add( components)
• ICONS AND LABELS:
• Syntax:
• ImageIcon( String filename)
• Example:
• ImageIcon(URL url)
• Methods:
• int getIconHeight( )
• int getIconWidth( )
• void paintIcon(Component comp, Graphics g, int x, int y)
• JLABEL:
• JLabel(Icon i)
• JLabel(String s)
• JLabel(String s, Icon I, int align)
• JTEXT FIELDS:
• JText component are JTextFields.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• Example:
• JTextField( )
• JTextField(int cols)
• JTextField(String s, int cols)
• JBUTTONS:
• Abstract button is a super class for push buttons, check boxes and radio buttons.
• Example:
• JButton(Icon i)
• JButton(String s)
• JButton(String s, Icon i)
• JCHECKBOX:
• Example:
• JCheckbox(Icon i)
• JCheckbox(Icon i, Boolean State)
• JCheckbox(String s)
• JCheckbox(String s, Icon i, Boolean State)
• Example:
• Void setselected(Boolean State)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• JRadioButton:
• Example 1:
• JRadioButton(Icon i)
• JRadioButton(Icon i, String s)
• JRadioButton(String s)
• JRadioButton(String s, Icon i, Boolean State)
• Example 2:
• JRadioButton jb=new JRadioButton(“SAI”);
• JCOMBOBOX:
• Example 1:
• JCombobox( )
• JComboBox(vector v)
• Example 2:
• Void additem(Object obj);
• Example 3:
• JComboBox jb=new JComboBox( );
• jb.addItem(“INDIA”);
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• JTABBED PANE:
• Tabbed pane is a component that appears as a group of folders in a file cabinet.
• Example:
• void addtab(String str, Component comp)
• Here str is titile for the tab, comp is a add to tabs.
• JSCROLLPANE :
• Example 1:
• Jscrollpane(Component comp)
• Jscrollpane(int vsb, int hsb)
• Jscrollpane(Component comp, int vsb, int hsb)
• Example 2:
• JPanel jp=new JPanel( );
• JScrollpane jsb=new JScrollpane(jp,v,h);
• JTREES:
• It is a hierarchical view of data.
• Syntax:
• JTree( hash table ht)
• JTree(vector v)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
METHODS
• Add
• Remove
• Example:
• Void add( )
• Void remove( )
• JTABLES:
• It is a combination of rows and columns.
• Syntax:
• JTable(object data[][], object colsheads[])
A. SIVASANKARI - SIASC-TVM
A. SIVASANKARI - SIASC-TVM

Weitere ähnliche Inhalte

Was ist angesagt?

Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010Arun Gupta
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCSimba Technologies
 
JAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARIJAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARISivaSankari36
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camelkrasserm
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterSimon Ritter
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1PawanMM
 
Java 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx FranceJava 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx FranceTrisha Gee
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingTurbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingSteven Feuerstein
 

Was ist angesagt? (20)

Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Css
CssCss
Css
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
JAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARIJAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARI
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Jdbc basic features
Jdbc basic featuresJdbc basic features
Jdbc basic features
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Dao example
Dao exampleDao example
Dao example
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1
 
Java 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx FranceJava 8 in Anger, Devoxx France
Java 8 in Anger, Devoxx France
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Java 101
Java 101Java 101
Java 101
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingTurbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk Processing
 

Ähnlich wie PROGRAMMING IN JAVA- unit 4-part I

Ähnlich wie PROGRAMMING IN JAVA- unit 4-part I (20)

applet.pptx
applet.pptxapplet.pptx
applet.pptx
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
Applet.pptx
Applet.pptxApplet.pptx
Applet.pptx
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Applets
AppletsApplets
Applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Applet intro
Applet introApplet intro
Applet intro
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And Graphics
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Java applet
Java appletJava applet
Java applet
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Advanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.pptAdvanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.ppt
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
java applets
java appletsjava applets
java applets
 
Java Applets
Java AppletsJava Applets
Java Applets
 

Mehr von SivaSankari36

DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARISivaSankari36
 
CLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARICLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARISivaSankari36
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARISivaSankari36
 
MOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARIMOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARISivaSankari36
 
Functional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationFunctional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationSivaSankari36
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to MethodsSivaSankari36
 

Mehr von SivaSankari36 (6)

DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARI
 
CLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARICLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARI
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
 
MOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARIMOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARI
 
Functional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationFunctional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data Application
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
 

Kürzlich hochgeladen

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 

Kürzlich hochgeladen (20)

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 

PROGRAMMING IN JAVA- unit 4-part I

  • 1. PROGRAMMING IN JAVA A. SIVASANKARI ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATION SHANMUGA INDUSTRIES ARTS AND SCIENCE COLLEGE, TIRUVANNAMALAI. 606601. Email: sivasankaridkm@gmail.com
  • 2. PROGRAMMING IN JAVA UNIT – 4 PART I  APPLET  APPLETS - GUI COMPONENTS  APPLET PARAMETERS  LIFE CYCLE OF AN APPLET  APPLICATION CONVERSION TO APPLETS  AWT AND AWT HIERARCHY  SWING COMPONENTS A. SIVASANKARI - SIASC-TVM UNIT-4
  • 3. PROGRAMMING IN JAVA APPLET BASICS • An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. • There are some important differences between an applet and a standalone Java application, including the following • An applet is a Java class that extends the java.applet.Applet class. • A main() method is not invoked on an applet, and an applet class will not define main(). • Applets are designed to be embedded within an HTML page. • When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine. • A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate runtime environment. • The JVM on the user's machine creates an instance of the applet class and invokes various methods during the applet's lifetime. • Applets have strict security rules that are enforced by the Web browser. The security of an applet is often referred to as sandbox security, comparing the applet to a child playing in a sandbox with various rules that must be followed. • Other classes that the applet needs can be downloaded in a single Java Archive (JAR) file. A. SIVASANKARI - SIASC-TVM
  • 4. PROGRAMMING IN JAVA APPLETS (GUI COMPONENTS) • Applets are small java programs that run inside of a web browser. • It is also stored as part of webpage. • The applet classes contained in the java applet package. • It also defines three interfaces. 1. Applet context 2. Audio clip 3. Applet stub • It will be executed within HTML tag. • It is an intelligent program. • It is an application designed to be transmitted over internet and executed by a java compatible with browser. SYNTAX • <applet code= “ program name” width=200 height=200> </applet> APPLET INITIALIZATION AND TERMINATION When started • Init( ) • Start( ) • Paint( ) When Applet is terminated • Stop( ) • Destroy( ) A. SIVASANKARI - SIASC-TVM
  • 5. PROGRAMMING IN JAVA Another method is overriding update( ) EXAMPLE • Public void paint (Graphics g) • { • Update(g); • } APPLET CLASSES OR METHODS APPLET METHODS DESCRIPTION void destroy( ) It called by the browser just before an applet is terminated. String getAppletinfo( ) It should return String. URL getcodeBase( ) It returns URL image getimage(URL url) It returns image object. void init( ) It begins execution. void start( ) It should starts of execution. Void stop( ) Browser to suspend execution of applets. A. SIVASANKARI - SIASC-TVM
  • 6. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 7. PROGRAMMING IN JAVA EXAMPLE • import java.awt.*; • import java.applet.*; • /*<applet code=”sample” width=300 height=200></applet> • public class sample extends Applet{ • Public void init( ){ • setBackground(color.cyan)} • Public void paint( Graphics g){ • g.drawString(“This is sample”,10,20); • show status(“This is status window”);}} HTMLAPPLET TAGS • <APPLET[CODE BASE=code base URL] name of file CODE=applet file • [ALT= alternate text] [NAME= applet instance name]name of attributes • [WIDTH=pixels, HEIGHT=PIXELS]height and width of window • [ALIGN= alignment]top, bottom, up, down, middle • [VSPACE=Pixels]vertical space [HSPACE=Pixels]>horizontal space • [<param name=attribute name VALUE=attribute value>] • </APPLET> A. SIVASANKARI - SIASC-TVM
  • 8. PROGRAMMING IN JAVA LIFE CYCLE OF AN APPLET • Four methods in the Applet class gives you the framework on which you build any serious applet • init − This method is intended for whatever initialization is needed for your applet. It is called after the param tags inside the applet tag have been processed. • start − This method is automatically called after the browser calls the init method. It is also called whenever the user returns to the page containing the applet after having gone off to other pages. • stop − This method is automatically called when the user moves off the page on which the applet sits. It can, therefore, be called repeatedly in the same applet. • destroy − This method is only called when the browser shuts down normally. Because applets are meant to live on an HTML page, you should not normally leave resources behind after a user leaves the page that contains the applet. • paint − Invoked immediately after the start() method, and also any time the applet needs to repaint itself in the browser. The paint() method is actually inherited from the java.awt. A. SIVASANKARI - SIASC-TVM
  • 9. PROGRAMMING IN JAVA A "Hello, World" Applet Following is a simple applet named HelloWorldApplet.java • import java.applet.*; • import java.awt.*; • public class HelloWorldApplet extends Applet { • public void paint (Graphics g) { • g.drawString ("Hello World", 25, 50); • } • } These import statements bring the classes into the scope of our applet class • java.applet.Applet • java.awt.Graphics • Without those import statements, the Java compiler would not recognize the classes Applet and Graphics, which the applet class refers to. The Applet Class • Every applet is an extension of the java.applet.Applet class. The base Applet class provides methods that a derived Applet class may call to obtain information and services from the browser context. A. SIVASANKARI - SIASC-TVM
  • 10. PROGRAMMING IN JAVA These include methods that do the following • Get applet parameters • Get the network location of the HTML file that contains the applet • Get the network location of the applet class directory • Print a status message in the browser • Fetch an image • Fetch an audio clip • Play an audio clip • Resize the applet • Additionally, the Applet class provides an interface by which the viewer or browser obtains information about the applet and controls the applet's execution. The viewer may • Request information about the author, version, and copyright of the applet Request a description of the parameters the applet recognizes 1. Initialize the applet 2. Destroy the applet 3. Start the applet's execution 4. Stop the applet's execution • The Applet class provides default implementations of each of these methods. Those implementations may be overridden as necessary. • The "Hello, World" applet is complete as it stands. The only method overridden is the paint method. A. SIVASANKARI - SIASC-TVM
  • 11. PROGRAMMING IN JAVA Invoking an Applet • An applet may be invoked by embedding directives in an HTML file and viewing the file through an applet viewer or Java-enabled browser. • The <applet> tag is the basis for embedding an applet in an HTML file. Following is an example that invokes the "Hello, World" applet • <html> • <title>The Hello, World Applet</title> • <hr> • <applet code = "HelloWorldApplet.class" width = "320" height = "120"> • If your browser was Java-enabled, a "Hello, World" message would appear here. • </applet> • <hr> • </html> • The code attribute of the <applet> tag is required. It specifies the Applet class to run. Width and height are also required to specify the initial size of the panel in which an applet runs. The applet directive must be closed with an </applet> tag. • If an applet takes parameters, values may be passed for the parameters by adding <param> tags between <applet> and </applet>. The browser ignores text and other tags between the applet tags. A. SIVASANKARI - SIASC-TVM
  • 12. PROGRAMMING IN JAVA GETTING APPLET PARAMETERS • The following example demonstrates how to make an applet respond to setup parameters specified in the document. This applet displays a checkerboard pattern of black and a second color. • The second color and the size of each square may be specified as parameters to the applet within the document. • CheckerApplet gets its parameters in the init() method. It may also get its parameters in the paint() method. However, getting the values and saving the settings once at the start of the applet, instead of at every refresh, is convenient and efficient. • The applet viewer or browser calls the init() method of each applet it runs. The viewer calls init() once, immediately after loading the applet. (Applet.init() is implemented to do nothing.) Override the default implementation to insert custom initialization code. • The Applet.getParameter() method fetches a parameter given the parameter's name (the value of a parameter is always a string). If the value is numeric or other non- character data, the string must be parsed. A. SIVASANKARI - SIASC-TVM
  • 13. PROGRAMMING IN JAVA The following is a skeleton of CheckerApplet.java • import java.applet.*; • import java.awt.*; • public class CheckerApplet extends Applet { • int squareSize = 50; // initialized to default size • public void init() {} • private void parseSquareSize (String param) {} • private Color parseColor (String param) {} • public void paint (Graphics g) {}} Here are CheckerApplet's init() and private parseSquareSize() methods • public void init () { • String squareSizeParam = getParameter ("squareSize"); • parseSquareSize (squareSizeParam); • String colorParam = getParameter ("color"); • Color fg = parseColor (colorParam); • setBackground (Color.black); setForeground (fg); • } private void parseSquareSize (String param) { • if (param == null) return; • try { squareSize = Integer.parseInt (param); } • catch (Exception e) { // Let default value remain }} A. SIVASANKARI - SIASC-TVM
  • 14. PROGRAMMING IN JAVA • The applet calls parseSquareSize() to parse the squareSize parameter. parseSquareSize() calls the library method Integer.parseInt(), which parses a string and returns an integer. Integer.parseInt() throws an exception whenever its argument is invalid. • Therefore, parseSquareSize() catches exceptions, rather than allowing the applet to fail on bad input. • The applet calls parseColor() to parse the color parameter into a Color value. parseColor() does a series of string comparisons to match the parameter value to the name of a predefined color. • We need to implement these methods to make this applet work. • Specifying Applet Parameters The following is an example of an HTML file with a CheckerApplet embedded in it. • The HTML file specifies both parameters to the applet by means of the <param> tag. • <html> • <title>Checkerboard Applet</title> • <hr> <applet code = "CheckerApplet.class" width = "480" height = "320"> • <param name = "color" value = "blue"> • <param name = "squaresize" value = "30"> • </applet> • <hr> • </html> • Note − Parameter names are not case sensitive. A. SIVASANKARI - SIASC-TVM
  • 15. PROGRAMMING IN JAVA APPLICATION CONVERSION TO APPLETS • It is easy to convert a graphical Java application (that is, an application that uses the AWT and that you can start with the Java program launcher) into an applet that you can embed in a web page. Following are the specific steps for converting an application to an applet. • Make an HTML page with the appropriate tag to load the applet code. • Supply a subclass of the JApplet class. Make this class public. Otherwise, the applet cannot be loaded. • Eliminate the main method in the application. Do not construct a frame window for the application. Your application will be displayed inside the browser. • Move any initialization code from the frame window constructor to the init method of the applet. You don't need to explicitly construct the applet object. The browser instantiates it for you and calls the init method. • Remove the call to setSize; for applets, sizing is done with the width and height parameters in the HTML file. • Remove the call to setDefaultCloseOperation. An applet cannot be closed; it terminates when the browser exits. • If the application calls setTitle, eliminate the call to the method. Applets cannot have title bars. (You can, of course, title the web page itself, using the HTML title tag.) • Don't call setVisible(true). The applet is displayed automatically A. SIVASANKARI - SIASC-TVM
  • 16. PROGRAMMING IN JAVA AWT AND AWT HIERARCHY • Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications in java. • Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components are using the resources of OS. • The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. A. SIVASANKARI - SIASC-TVM
  • 17. PROGRAMMING IN JAVA SWING COMPONENTS • It is a set of classes that provides more powerful and flexible components that are possible with the awt. • Swing components are also called Java Foundation classes(JFC) METHOD NAME COMMANDS Abstract button Abstract super class for swing buttons. Button group Encapsulates a mutually exclusive set of buttons. Image Icon Encapsulates an icon. JApplet The swing version of applet. JButton The swing push button class. JCheckBox Check box. JComboBox The swing combination of dropdown list and text field. JLabel Label. JRadioButton Swing version of Radio Button. JScrollpane Encapsulates a scrollable window. JTabbedWindow Encapsulates a tabbed window. JTable Encapsulates a table based control. JTextField Text Box. JTree Tree based Control. A. SIVASANKARI - SIASC-TVM
  • 18. PROGRAMMING IN JAVA • JAPPLETS: • Swing must be subclasses of JApplet. Use add( ) method. • Syntax: • Container getContentpane( ) • Example: • void add( components) • ICONS AND LABELS: • Syntax: • ImageIcon( String filename) • Example: • ImageIcon(URL url) • Methods: • int getIconHeight( ) • int getIconWidth( ) • void paintIcon(Component comp, Graphics g, int x, int y) • JLABEL: • JLabel(Icon i) • JLabel(String s) • JLabel(String s, Icon I, int align) • JTEXT FIELDS: • JText component are JTextFields. A. SIVASANKARI - SIASC-TVM
  • 19. PROGRAMMING IN JAVA • Example: • JTextField( ) • JTextField(int cols) • JTextField(String s, int cols) • JBUTTONS: • Abstract button is a super class for push buttons, check boxes and radio buttons. • Example: • JButton(Icon i) • JButton(String s) • JButton(String s, Icon i) • JCHECKBOX: • Example: • JCheckbox(Icon i) • JCheckbox(Icon i, Boolean State) • JCheckbox(String s) • JCheckbox(String s, Icon i, Boolean State) • Example: • Void setselected(Boolean State) A. SIVASANKARI - SIASC-TVM
  • 20. PROGRAMMING IN JAVA • JRadioButton: • Example 1: • JRadioButton(Icon i) • JRadioButton(Icon i, String s) • JRadioButton(String s) • JRadioButton(String s, Icon i, Boolean State) • Example 2: • JRadioButton jb=new JRadioButton(“SAI”); • JCOMBOBOX: • Example 1: • JCombobox( ) • JComboBox(vector v) • Example 2: • Void additem(Object obj); • Example 3: • JComboBox jb=new JComboBox( ); • jb.addItem(“INDIA”); A. SIVASANKARI - SIASC-TVM
  • 21. PROGRAMMING IN JAVA • JTABBED PANE: • Tabbed pane is a component that appears as a group of folders in a file cabinet. • Example: • void addtab(String str, Component comp) • Here str is titile for the tab, comp is a add to tabs. • JSCROLLPANE : • Example 1: • Jscrollpane(Component comp) • Jscrollpane(int vsb, int hsb) • Jscrollpane(Component comp, int vsb, int hsb) • Example 2: • JPanel jp=new JPanel( ); • JScrollpane jsb=new JScrollpane(jp,v,h); • JTREES: • It is a hierarchical view of data. • Syntax: • JTree( hash table ht) • JTree(vector v) A. SIVASANKARI - SIASC-TVM
  • 22. PROGRAMMING IN JAVA METHODS • Add • Remove • Example: • Void add( ) • Void remove( ) • JTABLES: • It is a combination of rows and columns. • Syntax: • JTable(object data[][], object colsheads[]) A. SIVASANKARI - SIASC-TVM
  • 23. A. SIVASANKARI - SIASC-TVM