SlideShare uma empresa Scribd logo
1 de 30
Collaborate


Knowledge Byte
    In this section, you will learn about:


         •   Trusted and untrusted applets
         •   Advanced Drawing methods in Java
         •   Setting Color, Font, Style, and Size of Text in an Applet
         •   Gridbag Layout Manager
         •   Anonymous classes




 ©NIIT                          Collaborate                    Lesson 2C / Slide 1 of 30
Collaborate


Trusted and Untrusted Applets
•    An applet is an interactive Java program that runs inside an appletviewer or a
     Java-compatible Web browser.
•    The sandbox model of Java ensures the security of Java code when an applet runs.
•    Being confined to the sandbox model, an applet cannot perform functions, such as
     reading, writing, or deleting files from the local file system.
•    This type of applet is known as an untrusted applet.
•    An untrusted applet is prevented from accessing files on the local computer and
     accessing network connection from the computer.
•    A trusted applet enables you to perform operations, such as reading and writing
     data to a local computer.
•    A trusted applet is digitally signed by a trusted source.
•    PolicyTool is the trusted source provided by the JDK 1.2.




    ©NIIT                       Collaborate                  Lesson 2C / Slide 2 of 30
Collaborate


Trusted and Untrusted Applets
(Contd.)
    •    Steps to create a policy
         • Open the command prompt window.
         • Type PolicyTool and press the Enter key to open the Policy Tool dialog
           box




 ©NIIT                       Collaborate                  Lesson 2C / Slide 3 of 30
Collaborate


Trusted and Untrusted Applets
(Contd.)
         •   Click the Add Policy Entry button in the Policy Tool dialog box to add an
             entry for new policy.




 ©NIIT                         Collaborate                   Lesson 2C / Slide 4 of 30
Collaborate


Trusted and Untrusted Applets
(Contd.)
         •   Click the Add Permission button in the Policy Entry dialog box to
             specify the permissions for a desired file. The Permissions dialog box is
             displayed.




         •   Select the required permissions from the FilePermission drop-down list.
         •   Select the file on which you want to apply permissions from the Target
             Name drop-down list.

 ©NIIT                          Collaborate                   Lesson 2C / Slide 5 of 30
Collaborate


Trusted and Untrusted Applets
(Contd.)
         •   Select the permissions, such as read, write, and execute from the Actions
             drop-down list.
         •   Click the OK button in the Permissions dialog box to apply the desired
             settings for adding a new permission.
         •   Click the Done button in the Policy Entry dialog box to complete the
             process of adding the new policy entry.
         •   Save the file by the name java.policy in the C:Documents and Settings
             Administrator by selecting the Save or Save As option from the File
             menu.




 ©NIIT                         Collaborate                   Lesson 2C / Slide 6 of 30
Collaborate


Trusted and Untrusted applets
(Contd.)
    •    When an applet is loaded on the Web, it is first checked if an applet by the
         same name exists in the classpath.
    •    If an applet of the same name exists, the applet found in the classpath is
         loaded.
    •    An applet loaded in this manner is a trusted applet.
    •    If no applet is found with the same name in the class path, then the applet is
         loaded from the location specified by the page that contains the applet.
    •    An applet loaded in this manner is an untrusted applet.




 ©NIIT                           Collaborate                   Lesson 2C / Slide 7 of 30
Collaborate


Drawing Methods in Java
    •    The drawRoundRect(), draw3DRect(), and fillRoundRect() methods are the
         advanced drawing methods used for creating drawings in an applet.

    •    The drawRoundRect() method is used to draw a rectangle with rounded
         corners.

    •    The fillRoundRect() method is used to draw a filled round cornered rectangle.

    •    A 3D rectangle and a filled 3D rectangle can be drawn using the draw3DRect()
         and fill3DRect() methods.




 ©NIIT                          Collaborate                   Lesson 2C / Slide 8 of 30
Collaborate


Setting Color, Font, Style, and Size of
Text in an Applet
    •    Java provides the Color class that contains various color methods to apply the
         foreground and background colors to an applet.
    •    Syntax to set a desired color for an applet is Color.color_name.
           • The Color class accepts the color_name argument to set the desired
              color, such as Color.red for drawing or writing text in an applet.
    •    The syntax to create your own colors for an applet is Color(int red, int green,
         int blue)
           • The arguments of the Color class specify the proportion of three different
              colors, red, green, and blue. The integer values lie in the range of 0 to
              255.
    •    The setColor() method applies drawing color to an applet.




 ©NIIT                           Collaborate                   Lesson 2C / Slide 9 of 30
Collaborate


Setting Color, Font, Style, and Size of
Text in an Applet (Contd.)
    •    Java provides the Font class that enables you to write text in an applet using
         different fonts.

    •    The syntax shows how to create an instance of the Font class is Font f = new
         Font(font family, font style, font size);
           • The Font class provides a variety of font family, such as Arial, Courier,
             Helvetica, and Futura. You can also apply different font sizes and styles,
             such as BOLD, ITALIC, and PLAIN.




 ©NIIT                           Collaborate                  Lesson 2C / Slide 10 of 30
Collaborate


GridBag Layout Manager
    •    The GridBag layout manager divides a container into a grid of equally sized
         cells. In the GridBag layout, a component can extend over multiple rows and
         columns.
    •    You specify the position of each component by specifying its x and y
         coordinates.
    •    You can resize the component by assigning weights to the components in the
         GridBag layout. Weights specify the horizontal and vertical space required to
         fill the display area of a container.
    •    The constructor to create an instance of the GridBagLayout class is
         GridBagLayout() g = new GridBagLayout();
    •    The syntax to define the setLayout() method is panel.setLayout(g);
    •    You need to specify the constraints for each component, when you want to size
         and position the components.
    •    You apply the constraints in the GridBag layout manager by using the
         setConstraints() method.


 ©NIIT                          Collaborate                 Lesson 2C / Slide 11 of 30
Collaborate


GridBag Layout Manager (Contd.)
    •    Constructors of the GridBagConstraints class
          • GridBagConstraints(): Creates a GridBagConstraints object with the
             default values for the gridbag layout attributes.
          • GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double
             weightx, double weighty, int anchor, int fill. Insets insets, int ipadx, int
             ipady): Creates a GridBagConstraints object with the specified values for
             the gridbag layout attributes.
                  Attribute                                Description

         gridx                             Specifies the row in the top-left display
                                           area of the component. The extreme left
                                           column has the value of gridx as zero.
         gridy                             Specifies the column in the top-left display
                                           area of the component. The topmost cell
                                           has the value of gridy as zero.

 ©NIIT                           Collaborate                   Lesson 2C / Slide 12 of 30
Collaborate


GridBag Layout Manager (Contd.)
                  Attribute                               Description


     gridheight                         Specifies the number of rows in the display
                                        area of a component. The default value for
                                        the gridheight argument is one.

     gridwidth                          Specifies the number of columns in the
                                        display area of a component. The default
                                        value for the gridwidth is one.

     weightx                            Specifies the horizontal space required to fill
                                        the display area of a container. The default
                                        value for the weightx argument is zero.

     weighty                            Specifies the vertical space required to fill the
                                        display area of the container. The default
                                        value for the weighty argument is zero.

 ©NIIT                        Collaborate                    Lesson 2C / Slide 13 of 30
Collaborate


GridBag Layout Manager (Contd.)
          Attribute                            Description


 anchor                      Determines the position of a component, when
                             the size of the component is smaller than its
                             display area.
 insets                      Specifies the minimum space between the
                             components and the edges of the display area.
                             The default value of insets is 0,0,0 that
                             represents the top, left, bottom, and right
                             coordinates.
 ipadx                       Specifies the minimum space added to the
                             horizontal side of a component. The default value
                             for the ipadx argument is zero.
 ipady                       Specifies the minimum space added to the
                             vertical side of a component. The default value
                             for the ipady argument is zero.

 ©NIIT                Collaborate                  Lesson 2C / Slide 14 of 30
Collaborate


GridBag Layout Manager (Contd.)
    •    Values for the anchor attribute


                  Value                                  Description


        GridBagConstraints.CENTER          Places the component at the center of a
                                           container.

        GridBagConstraints.NORTH           Places the component to the north of a
                                           container.

        GridBagConstraints.NORTH           Places the component to the north-east of
        EAST                               a container.

        GridBagConstraints.EAST            Places the component to the east of a
                                           container.

 ©NIIT                           Collaborate                    Lesson 2C / Slide 15 of 30
Collaborate


GridBag Layout Manager (Contd.)
             Value                                  Description


   GridBagConstraints.SOUTHE         Places the component to the south-east of a
   AST                               container.

   GridBagConstraints.SOUTH          Places the component to the south of a
                                     container.

   GridBagConstraints.WEST           Places the component to the west of a
                                     container.

   GridBagConstraints.NORTHW         Places the component to the north-west of a
   EST                               container.



 ©NIIT                        Collaborate                  Lesson 2C / Slide 16 of 30
Collaborate


GridBag Layout Manager (Contd.)
    •    Values for the fill attribute

                 Value                                  Description


    GridBagConstraints.NONE              Applies the default values for the GridBag
                                         constraints.

    GridBagConstraints.HORIZ             Fills the display area horizontally but do
    ONTAL                                not change the height of the component.

    GridBagConstraints.VERTIC            Fills the display area vertically but do not
    AL                                   change the width of the component.

    GridBagConstraints.BOTH              Fills the whole display area.



 ©NIIT                             Collaborate                    Lesson 2C / Slide 17 of 30
Collaborate


GridBag Layout Manager (Contd.)
    •    Methods of the GridBagLayout class

                 Method                              Description


        AddLayoutComponent(Comp         Adds the specified component to the
        onent c, Object o)              layout by using the constraints
                                        specified by the passed parameter.
        addLayoutComponent(String       Adds the specified component with
        str, Component c)               the specified name to the layout.

        getConstraints(Component        Retrieves the constraints for the
        c)                              specified component.

        getLayoutAlignmentX(Contai      Retrieves the alignment along the
        ner con)                        x-axis of a container.


 ©NIIT                         Collaborate                   Lesson 2C / Slide 18 of 30
Collaborate


GridBag Layout Manager (Contd.
                    Method                               Description


         getLayoutAlignmentY(Contai         Retrieves the alignment along the
         ner con)                           y-axis of a container.

         getLayoutDimensions()              Retrieves the dimensions of the
                                            layout grid.

         getLayoutWeights()                 Retrieves the weights of the rows
                                            and columns of the layout grid.

         location(int x, int y)             Retrieves the cell in the layout grid
                                            containing the point specified by x
                                            and y coordinates.


 ©NIIT                            Collaborate                   Lesson 2C / Slide 19 of 30
Collaborate


GridBag Layout Manager (Contd.)
               Method                             Description


  maximumLayoutSize(Container       Returns the maximum dimensions of the
  con)                              layout in the specified container.

  minimumLayoutSize(Container       Returns the minimum size of the
  con)                              container by using the GridBag layout.

  preferredLayoutSize(Container     Retrieves the preferred size of the
  con)                              container using the GridBag layout.

  removeLayoutComponent(Com         Removes the specified component from
  ponent c)                         the layout.

  toString()                        Returns a string representation of the
                                    GridBag layout values.

 ©NIIT                       Collaborate                  Lesson 2C / Slide 20 of 30
Collaborate


Anonymous Classes
    •    Anonymous classes combine the tasks of declaring a class and creating its
         instance in a single step.

    •    An anonymous class must implement the tasks
          • Extends a superclass
          • Implements all the abstract methods of the superclass
          • Uses the default constructor of the superclass to create its instance

    •    Anonymous classes are an enhancement of inner classes. An inner class is a
         nested class and its instance exists within an instance of its enclosing class.




 ©NIIT                           Collaborate                   Lesson 2C / Slide 21 of 30
Collaborate


From the Expert’s Desk

    In this section, you will learn:


         •   Best practices on:
                • Running Applets
                • Inner and Adapter Classes
         •   Tips and Tricks on:
                • Applets
         •   FAQs




 ©NIIT                           Collaborate   Lesson 2C / Slide 22 of 30
Collaborate


Best Practices
Running Applets

    •    You need to include all the graphics in an applet in separate threads. This
         makes the process of navigation easier as an end user does not have to wait
         for large pictures to be downloaded.


Inner and Adapter Classes

    •    You need to use inner classes for writing adapter classes so that you can
         directly operate on the methods and variables of a class.




 ©NIIT                          Collaborate                  Lesson 2C / Slide 23 of 30
Collaborate


Tips and Tricks
Applets

    •    You must override the stop() method of an applet to release all the resources,
         such as threads occupied by the applet. The stop() method enables you to
         use the resources released by an applet for another applet.




 ©NIIT                          Collaborate                 Lesson 2C / Slide 24 of 30
Collaborate


FAQs
    •    How is a Java applet different from a Java stand-alone application?

                 Applet                               Application


     Can be embedded in an             Cannot be embedded in an HTML Web
     HTML Web page                     page


     Runs inside a Java-capable        Runs on the command prompt by using
     browser, such as Internet         the Java interpreter
     Explorer, Netscape
     Navigator, and HotJava

     Cannot read or write to the       Can read or write to the file system
     file system



 ©NIIT                          Collaborate                  Lesson 2C / Slide 25 of 30
Collaborate


FAQs (Contd.)
    •    How can you run an applet in a browser, which is not Java-compatible?
         You can run an applet with the appletviewer tool included with the JDK, when a
         browser is not Java-compatible.



    •    Why would you use parameters with an applet?
         You need to pass parameters to an applet whenever you want to send the
         details to a Java file through an HTML file. You pass parameters to an applet by
         using the <PARAM> tag. The <PARAM> tag contains the NAME and VALUE
         attributes. The NAME attribute specifies the name of the parameter passed to
         an applet, and the VALUE attribute specifies the value of the variable to be
         passed.




 ©NIIT                          Collaborate                   Lesson 2C / Slide 26 of 30
Collaborate


FAQs (Contd.)
    •    Which mouse event is most commonly captured and responded in a Java
         applet?
         MOUSE_CLICKED is the most commonly captured and responded event in a
         Java applet.


    •    How can you convert an applet to an application?
         You can convert an applet to an application by including the main() method in
         the applet. The declarations included in the init() method of the applet need
         to perform in the constructor of the class. The applet class needs to extend
         from a frame and size, and visibility of the frame is set in the main() method.


    •    If you want to handle all events in a single method, which method can you use
         to override in your applet?
         You can handle all the events in a single method by overriding the
         handleEvent() method.


 ©NIIT                          Collaborate                   Lesson 2C / Slide 27 of 30
Collaborate


Challenge
    1. What special HTML tag is used to place a Java program in a Web page?
    a. <APPLET>
    b. <PROGRAM>
    c. <RUN>
    d. <HEAD>

    2. Match the following:
    a. init()      i. Called by the browser when the user moves to another page.
    b. stop()       ii. Called the first time an applet is loaded into the memory of the
                        computer.
    c. update()    iii. Called the first time an applet is displayed on the screen.
    d. start()       iv. Called every time an applet loses the focus.
    e. paint()        v. Called every time an applet receives the focus.
    f. destroy()    vi. Called to clear the screen.

 ©NIIT                         Collaborate                   Lesson 2C / Slide 28 of 30
Collaborate


Challenge(Contd.)
    3. The FlowLayout Manager is the default layout manager for swing applications.
       (True/False)

    4. The Adapter class used for the _____ interface is the WindowAdapter class.

    5.An anonymous class cannot have a constructor. (True/False)




 ©NIIT                        Collaborate                  Lesson 2C / Slide 29 of 30
Collaborate


Solutions to Challenge
    1. (a)
    2. a-ii, b-iv, c-vi, d-v, e-iii, f-i
    3. True
    4.WindowListener
    5. True




 ©NIIT                              Collaborate   Lesson 2C / Slide 30 of 30

Mais conteúdo relacionado

Mais procurados

Ado.net session02
Ado.net session02Ado.net session02
Ado.net session02Niit Care
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 
Easy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolEasy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolHasitha Guruge
 
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its ModuleMuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its ModuleJitendra Bafna
 

Mais procurados (8)

Ado.net session02
Ado.net session02Ado.net session02
Ado.net session02
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
Intake 37 ef1
Intake 37 ef1Intake 37 ef1
Intake 37 ef1
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Easy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolEasy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping Tool
 
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its ModuleMuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 

Destaque

15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20Niit Care
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16Niit Care
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13Niit Care
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01Niit Care
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19Niit Care
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_cNiit Care
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItAzul Systems Inc.
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c languageHareem Aslam
 

Destaque (20)

 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
 
Oops recap
Oops recapOops recap
Oops recap
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Rdbms xp 01
Rdbms xp 01Rdbms xp 01
Rdbms xp 01
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
 
14 ooad uml-19
14 ooad uml-1914 ooad uml-19
14 ooad uml-19
 
Deawsj 7 ppt-2_c
Deawsj 7 ppt-2_cDeawsj 7 ppt-2_c
Deawsj 7 ppt-2_c
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Ds 8
Ds 8Ds 8
Ds 8
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Dacj 1-1 a
Dacj 1-1 aDacj 1-1 a
Dacj 1-1 a
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c language
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Dacj 1-1 b
Dacj 1-1 bDacj 1-1 b
Dacj 1-1 b
 

Semelhante a Dacj 2-2 c

Combo box and List box in VB.Net.ppt
Combo box and List box in VB.Net.pptCombo box and List box in VB.Net.ppt
Combo box and List box in VB.Net.pptUjwala Junghare
 
Vb net xp_03
Vb net xp_03Vb net xp_03
Vb net xp_03Niit Care
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptKevinNemo
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Debugging MAD lecture june .pptx
Debugging MAD lecture june .pptxDebugging MAD lecture june .pptx
Debugging MAD lecture june .pptxArishaNaz2
 
9781337102087 ppt ch09
9781337102087 ppt ch099781337102087 ppt ch09
9781337102087 ppt ch09Terry Yoast
 
250903944 3 homework2010_3
250903944 3 homework2010_3250903944 3 homework2010_3
250903944 3 homework2010_3Jerry Snow
 
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docx
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docxStudent Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docx
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docxemelyvalg9
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 uiMengChun Lam
 
RS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfRS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfSatishKhadse3
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 

Semelhante a Dacj 2-2 c (20)

Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-2 c
Dacj 1-2 cDacj 1-2 c
Dacj 1-2 c
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Combo box and List box in VB.Net.ppt
Combo box and List box in VB.Net.pptCombo box and List box in VB.Net.ppt
Combo box and List box in VB.Net.ppt
 
Vb net xp_03
Vb net xp_03Vb net xp_03
Vb net xp_03
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
Debugging MAD lecture june .pptx
Debugging MAD lecture june .pptxDebugging MAD lecture june .pptx
Debugging MAD lecture june .pptx
 
Dacj 2-1 c
Dacj 2-1 cDacj 2-1 c
Dacj 2-1 c
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
9781337102087 ppt ch09
9781337102087 ppt ch099781337102087 ppt ch09
9781337102087 ppt ch09
 
250903944 3 homework2010_3
250903944 3 homework2010_3250903944 3 homework2010_3
250903944 3 homework2010_3
 
a3.pdf
a3.pdfa3.pdf
a3.pdf
 
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docx
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docxStudent Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docx
Student Lab Activity A. Lab # CIS CIS170A-A1B. Lab 6.docx
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 ui
 
RS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdfRS and GIS TW- 1&2.pdf
RS and GIS TW- 1&2.pdf
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 

Mais de Niit Care (19)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Dacj 1-1 c
Dacj 1-1 cDacj 1-1 c
Dacj 1-1 c
 
Dacj 2-2 b
Dacj 2-2 bDacj 2-2 b
Dacj 2-2 b
 
Dacj 2-2 a
Dacj 2-2 aDacj 2-2 a
Dacj 2-2 a
 

Último

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Dacj 2-2 c

  • 1. Collaborate Knowledge Byte In this section, you will learn about: • Trusted and untrusted applets • Advanced Drawing methods in Java • Setting Color, Font, Style, and Size of Text in an Applet • Gridbag Layout Manager • Anonymous classes ©NIIT Collaborate Lesson 2C / Slide 1 of 30
  • 2. Collaborate Trusted and Untrusted Applets • An applet is an interactive Java program that runs inside an appletviewer or a Java-compatible Web browser. • The sandbox model of Java ensures the security of Java code when an applet runs. • Being confined to the sandbox model, an applet cannot perform functions, such as reading, writing, or deleting files from the local file system. • This type of applet is known as an untrusted applet. • An untrusted applet is prevented from accessing files on the local computer and accessing network connection from the computer. • A trusted applet enables you to perform operations, such as reading and writing data to a local computer. • A trusted applet is digitally signed by a trusted source. • PolicyTool is the trusted source provided by the JDK 1.2. ©NIIT Collaborate Lesson 2C / Slide 2 of 30
  • 3. Collaborate Trusted and Untrusted Applets (Contd.) • Steps to create a policy • Open the command prompt window. • Type PolicyTool and press the Enter key to open the Policy Tool dialog box ©NIIT Collaborate Lesson 2C / Slide 3 of 30
  • 4. Collaborate Trusted and Untrusted Applets (Contd.) • Click the Add Policy Entry button in the Policy Tool dialog box to add an entry for new policy. ©NIIT Collaborate Lesson 2C / Slide 4 of 30
  • 5. Collaborate Trusted and Untrusted Applets (Contd.) • Click the Add Permission button in the Policy Entry dialog box to specify the permissions for a desired file. The Permissions dialog box is displayed. • Select the required permissions from the FilePermission drop-down list. • Select the file on which you want to apply permissions from the Target Name drop-down list. ©NIIT Collaborate Lesson 2C / Slide 5 of 30
  • 6. Collaborate Trusted and Untrusted Applets (Contd.) • Select the permissions, such as read, write, and execute from the Actions drop-down list. • Click the OK button in the Permissions dialog box to apply the desired settings for adding a new permission. • Click the Done button in the Policy Entry dialog box to complete the process of adding the new policy entry. • Save the file by the name java.policy in the C:Documents and Settings Administrator by selecting the Save or Save As option from the File menu. ©NIIT Collaborate Lesson 2C / Slide 6 of 30
  • 7. Collaborate Trusted and Untrusted applets (Contd.) • When an applet is loaded on the Web, it is first checked if an applet by the same name exists in the classpath. • If an applet of the same name exists, the applet found in the classpath is loaded. • An applet loaded in this manner is a trusted applet. • If no applet is found with the same name in the class path, then the applet is loaded from the location specified by the page that contains the applet. • An applet loaded in this manner is an untrusted applet. ©NIIT Collaborate Lesson 2C / Slide 7 of 30
  • 8. Collaborate Drawing Methods in Java • The drawRoundRect(), draw3DRect(), and fillRoundRect() methods are the advanced drawing methods used for creating drawings in an applet. • The drawRoundRect() method is used to draw a rectangle with rounded corners. • The fillRoundRect() method is used to draw a filled round cornered rectangle. • A 3D rectangle and a filled 3D rectangle can be drawn using the draw3DRect() and fill3DRect() methods. ©NIIT Collaborate Lesson 2C / Slide 8 of 30
  • 9. Collaborate Setting Color, Font, Style, and Size of Text in an Applet • Java provides the Color class that contains various color methods to apply the foreground and background colors to an applet. • Syntax to set a desired color for an applet is Color.color_name. • The Color class accepts the color_name argument to set the desired color, such as Color.red for drawing or writing text in an applet. • The syntax to create your own colors for an applet is Color(int red, int green, int blue) • The arguments of the Color class specify the proportion of three different colors, red, green, and blue. The integer values lie in the range of 0 to 255. • The setColor() method applies drawing color to an applet. ©NIIT Collaborate Lesson 2C / Slide 9 of 30
  • 10. Collaborate Setting Color, Font, Style, and Size of Text in an Applet (Contd.) • Java provides the Font class that enables you to write text in an applet using different fonts. • The syntax shows how to create an instance of the Font class is Font f = new Font(font family, font style, font size); • The Font class provides a variety of font family, such as Arial, Courier, Helvetica, and Futura. You can also apply different font sizes and styles, such as BOLD, ITALIC, and PLAIN. ©NIIT Collaborate Lesson 2C / Slide 10 of 30
  • 11. Collaborate GridBag Layout Manager • The GridBag layout manager divides a container into a grid of equally sized cells. In the GridBag layout, a component can extend over multiple rows and columns. • You specify the position of each component by specifying its x and y coordinates. • You can resize the component by assigning weights to the components in the GridBag layout. Weights specify the horizontal and vertical space required to fill the display area of a container. • The constructor to create an instance of the GridBagLayout class is GridBagLayout() g = new GridBagLayout(); • The syntax to define the setLayout() method is panel.setLayout(g); • You need to specify the constraints for each component, when you want to size and position the components. • You apply the constraints in the GridBag layout manager by using the setConstraints() method. ©NIIT Collaborate Lesson 2C / Slide 11 of 30
  • 12. Collaborate GridBag Layout Manager (Contd.) • Constructors of the GridBagConstraints class • GridBagConstraints(): Creates a GridBagConstraints object with the default values for the gridbag layout attributes. • GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill. Insets insets, int ipadx, int ipady): Creates a GridBagConstraints object with the specified values for the gridbag layout attributes. Attribute Description gridx Specifies the row in the top-left display area of the component. The extreme left column has the value of gridx as zero. gridy Specifies the column in the top-left display area of the component. The topmost cell has the value of gridy as zero. ©NIIT Collaborate Lesson 2C / Slide 12 of 30
  • 13. Collaborate GridBag Layout Manager (Contd.) Attribute Description gridheight Specifies the number of rows in the display area of a component. The default value for the gridheight argument is one. gridwidth Specifies the number of columns in the display area of a component. The default value for the gridwidth is one. weightx Specifies the horizontal space required to fill the display area of a container. The default value for the weightx argument is zero. weighty Specifies the vertical space required to fill the display area of the container. The default value for the weighty argument is zero. ©NIIT Collaborate Lesson 2C / Slide 13 of 30
  • 14. Collaborate GridBag Layout Manager (Contd.) Attribute Description anchor Determines the position of a component, when the size of the component is smaller than its display area. insets Specifies the minimum space between the components and the edges of the display area. The default value of insets is 0,0,0 that represents the top, left, bottom, and right coordinates. ipadx Specifies the minimum space added to the horizontal side of a component. The default value for the ipadx argument is zero. ipady Specifies the minimum space added to the vertical side of a component. The default value for the ipady argument is zero. ©NIIT Collaborate Lesson 2C / Slide 14 of 30
  • 15. Collaborate GridBag Layout Manager (Contd.) • Values for the anchor attribute Value Description GridBagConstraints.CENTER Places the component at the center of a container. GridBagConstraints.NORTH Places the component to the north of a container. GridBagConstraints.NORTH Places the component to the north-east of EAST a container. GridBagConstraints.EAST Places the component to the east of a container. ©NIIT Collaborate Lesson 2C / Slide 15 of 30
  • 16. Collaborate GridBag Layout Manager (Contd.) Value Description GridBagConstraints.SOUTHE Places the component to the south-east of a AST container. GridBagConstraints.SOUTH Places the component to the south of a container. GridBagConstraints.WEST Places the component to the west of a container. GridBagConstraints.NORTHW Places the component to the north-west of a EST container. ©NIIT Collaborate Lesson 2C / Slide 16 of 30
  • 17. Collaborate GridBag Layout Manager (Contd.) • Values for the fill attribute Value Description GridBagConstraints.NONE Applies the default values for the GridBag constraints. GridBagConstraints.HORIZ Fills the display area horizontally but do ONTAL not change the height of the component. GridBagConstraints.VERTIC Fills the display area vertically but do not AL change the width of the component. GridBagConstraints.BOTH Fills the whole display area. ©NIIT Collaborate Lesson 2C / Slide 17 of 30
  • 18. Collaborate GridBag Layout Manager (Contd.) • Methods of the GridBagLayout class Method Description AddLayoutComponent(Comp Adds the specified component to the onent c, Object o) layout by using the constraints specified by the passed parameter. addLayoutComponent(String Adds the specified component with str, Component c) the specified name to the layout. getConstraints(Component Retrieves the constraints for the c) specified component. getLayoutAlignmentX(Contai Retrieves the alignment along the ner con) x-axis of a container. ©NIIT Collaborate Lesson 2C / Slide 18 of 30
  • 19. Collaborate GridBag Layout Manager (Contd. Method Description getLayoutAlignmentY(Contai Retrieves the alignment along the ner con) y-axis of a container. getLayoutDimensions() Retrieves the dimensions of the layout grid. getLayoutWeights() Retrieves the weights of the rows and columns of the layout grid. location(int x, int y) Retrieves the cell in the layout grid containing the point specified by x and y coordinates. ©NIIT Collaborate Lesson 2C / Slide 19 of 30
  • 20. Collaborate GridBag Layout Manager (Contd.) Method Description maximumLayoutSize(Container Returns the maximum dimensions of the con) layout in the specified container. minimumLayoutSize(Container Returns the minimum size of the con) container by using the GridBag layout. preferredLayoutSize(Container Retrieves the preferred size of the con) container using the GridBag layout. removeLayoutComponent(Com Removes the specified component from ponent c) the layout. toString() Returns a string representation of the GridBag layout values. ©NIIT Collaborate Lesson 2C / Slide 20 of 30
  • 21. Collaborate Anonymous Classes • Anonymous classes combine the tasks of declaring a class and creating its instance in a single step. • An anonymous class must implement the tasks • Extends a superclass • Implements all the abstract methods of the superclass • Uses the default constructor of the superclass to create its instance • Anonymous classes are an enhancement of inner classes. An inner class is a nested class and its instance exists within an instance of its enclosing class. ©NIIT Collaborate Lesson 2C / Slide 21 of 30
  • 22. Collaborate From the Expert’s Desk In this section, you will learn: • Best practices on: • Running Applets • Inner and Adapter Classes • Tips and Tricks on: • Applets • FAQs ©NIIT Collaborate Lesson 2C / Slide 22 of 30
  • 23. Collaborate Best Practices Running Applets • You need to include all the graphics in an applet in separate threads. This makes the process of navigation easier as an end user does not have to wait for large pictures to be downloaded. Inner and Adapter Classes • You need to use inner classes for writing adapter classes so that you can directly operate on the methods and variables of a class. ©NIIT Collaborate Lesson 2C / Slide 23 of 30
  • 24. Collaborate Tips and Tricks Applets • You must override the stop() method of an applet to release all the resources, such as threads occupied by the applet. The stop() method enables you to use the resources released by an applet for another applet. ©NIIT Collaborate Lesson 2C / Slide 24 of 30
  • 25. Collaborate FAQs • How is a Java applet different from a Java stand-alone application? Applet Application Can be embedded in an Cannot be embedded in an HTML Web HTML Web page page Runs inside a Java-capable Runs on the command prompt by using browser, such as Internet the Java interpreter Explorer, Netscape Navigator, and HotJava Cannot read or write to the Can read or write to the file system file system ©NIIT Collaborate Lesson 2C / Slide 25 of 30
  • 26. Collaborate FAQs (Contd.) • How can you run an applet in a browser, which is not Java-compatible? You can run an applet with the appletviewer tool included with the JDK, when a browser is not Java-compatible. • Why would you use parameters with an applet? You need to pass parameters to an applet whenever you want to send the details to a Java file through an HTML file. You pass parameters to an applet by using the <PARAM> tag. The <PARAM> tag contains the NAME and VALUE attributes. The NAME attribute specifies the name of the parameter passed to an applet, and the VALUE attribute specifies the value of the variable to be passed. ©NIIT Collaborate Lesson 2C / Slide 26 of 30
  • 27. Collaborate FAQs (Contd.) • Which mouse event is most commonly captured and responded in a Java applet? MOUSE_CLICKED is the most commonly captured and responded event in a Java applet. • How can you convert an applet to an application? You can convert an applet to an application by including the main() method in the applet. The declarations included in the init() method of the applet need to perform in the constructor of the class. The applet class needs to extend from a frame and size, and visibility of the frame is set in the main() method. • If you want to handle all events in a single method, which method can you use to override in your applet? You can handle all the events in a single method by overriding the handleEvent() method. ©NIIT Collaborate Lesson 2C / Slide 27 of 30
  • 28. Collaborate Challenge 1. What special HTML tag is used to place a Java program in a Web page? a. <APPLET> b. <PROGRAM> c. <RUN> d. <HEAD> 2. Match the following: a. init() i. Called by the browser when the user moves to another page. b. stop() ii. Called the first time an applet is loaded into the memory of the computer. c. update() iii. Called the first time an applet is displayed on the screen. d. start() iv. Called every time an applet loses the focus. e. paint() v. Called every time an applet receives the focus. f. destroy() vi. Called to clear the screen. ©NIIT Collaborate Lesson 2C / Slide 28 of 30
  • 29. Collaborate Challenge(Contd.) 3. The FlowLayout Manager is the default layout manager for swing applications. (True/False) 4. The Adapter class used for the _____ interface is the WindowAdapter class. 5.An anonymous class cannot have a constructor. (True/False) ©NIIT Collaborate Lesson 2C / Slide 29 of 30
  • 30. Collaborate Solutions to Challenge 1. (a) 2. a-ii, b-iv, c-vi, d-v, e-iii, f-i 3. True 4.WindowListener 5. True ©NIIT Collaborate Lesson 2C / Slide 30 of 30