View RSS Feed

Java AWT

Java Abstract Window Toolkit (AWT)

  1. Drawing a Line

    by , 03-06-2012 at 08:46 PM
    Line2D class is used to present the line segment(x,y) in coordinate space. To specify the lines in double precision & float, use these lines.

    • Line2D.Double
    • Line2D.Float

    Code below explains the drawing of a line.
    Java Code:
    // draw Line2D.Double
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    Different setline() methods are used by the Line class for explaining end points of line. End point of line will be specified by this given ...
  2. Drawing a Point

    by , 03-06-2012 at 08:45 PM
    Point class creates location presenting x,y coordinate space. Point class consist of these sub classes.

    • Point2D.Float
    • Point2D.Double

    Double precision and float are provided by these given classes to store the point’s coordinates, respectively.
    Java Code:
    //Create Point2D.Double
    Point2D.Double point = new Point2D.Double(x, y);
    For creation of coordinate along with 0,0, default constructor Point 2D.Double can be used.
    Point’s position ...
  3. Drawing Geometric Primitives

    by , 03-06-2012 at 08:43 PM
    Several classes are provided in the Java 2D API that defines common geometric object like:
    • Points
    • Lines
    • Curves
    • Rectangles

    These geometry classes are part of the java.awt.geom package.

    To retrieve methods from the path, the PathIterator interface defines and provides methods. For describing and inspecting geometric path objects, the Shape interface provides a set of methods. The GeneralPath class implements this interface and other geometry classes. ...
  4. Supporting User Interaction

    by , 03-06-2012 at 08:41 PM
    User interaction is supported with the graphics you want to display. You need to be able to determine when the user clicks on one of them. To determine whether a mouse click occurred over a particular Shape object, The Graphics2D class provides a hit method. You can also get the location of the mouse click. Call the contains method on the Shape class to determine whether the click was within the bounds of the Shape.

    You can perform simple hit testing, if you are using primitive text ...
  5. Constructing Complex Shapes from Geometry Primitives

    by , 03-06-2012 at 08:40 PM
    New geometric shapes are created by operations of Boolean at the existing ones. This is what is known as CAG i.e. constructive area geometry. In Java 2D API, shape interface is implemented by the area class. Following Boolean operations are supported by it.

    Name:  1.JPG
Views: 2869
Size:  12.4 KB
    Constructing Complex Shapes from Geometry Primitives

    An intersection at 2 overlapping circles is performed to create the leaves

    Java Code:
    leaf = new Ellipse2D.Double();
  6. Controlling Rendering Quality

    by , 03-04-2012 at 05:51 PM
    The Graphics2D class rendering are used for specifications like:

    • One wishes rendering objects as soon as possible.
    • Rendering of the higher quality graphics is required.

    Create a RenderingHint object. Pass to setRenderingHints of class Graphics 2D so that to alter or set rendering hint attribute, in context of Graphics2D.

    Graphics 2D’s setRenderingHint method is called so that to set 1 hint and pass it on a value pair key, for that hint which you ...
  7. Clipping the Drawing Region

    by , 03-04-2012 at 05:49 PM
    As a clipping path, shape object is used so that to restrict that drawing areas which will render. Clipping path is considered to be the portion of Graphic2D context. Call the Graphics2D.setClip & pass ahpe so that to set clip’s attributes. Clipping path gets shrink by clip method calling & then passing to other shape. A clip intersects to current shape and specified shape.

    To set clip method pass the ellipse & call clip so that for setting the clip path for intersection ...
  8. Transforming Shapes, Text, and Images

    by , 03-04-2012 at 05:48 PM
    One can do the modification of the graphic attributes so that for performing these graphic primitives in graphic 2D context.
    • Move
    • Scale
    • Rotate
    • Shear

    Transform attribute is defined by the instance of class AffineTransform. Parallel lines are found to be parallel no matter if the transformation has been done in affine transformation.

    Graphics 2D class provides number of methods to change the transform attribute. Graphic2Dtransform can be changed by calling ...
    Tags: images, shapes, text Add / Edit Tags
  9. Getting Started with Graphics

    by , 03-04-2012 at 05:46 PM
    The Java 2D API is considered to be a complex and powerful API which provides support to graphics. Just smaller feature sets are used by the Java 2D graphics, provided in class

    Graphic class is divided into 2 groups, as following.

    • Draw & fill method: This makes you able to render the basic text shapes & images.
    • Attributes setting method: Affects at filling appearance & drawing.

    The setColor & setFont method ...
    Tags: graphics Add / Edit Tags
  10. Java Printing

    by , 03-04-2012 at 05:44 PM
    Graphics rendered to print are given as following, by making use of Java 2D Printing API.
    • Swing
    • Composite graphics
    • Java 2D graphics
    • Images

    Document composition features are provided by the Java 2D printing API. Operations are facilitated to be performed by it. For example, ordering in which you need pages.

    Pages are rendered by the Rendering to screen and rendering to printer are same things. Printing system controls render the pages. At screen, there ...
  11. Java AWT Images

    by , 03-04-2012 at 05:42 PM
    A rectangular 2D pixel arrays is an image, in Java 2D API.

    • Color is presented by the pixel, at that position of image.
    • Image’s vertical and horizontal extent is presented by the dimensions.

    The class java.awt.image.BufferedImage is considered to be the most important image class to present images. For accessing image content directly, image’s content is stored by Java 2D API in memory.

    BufferedImage object can be created directly by the applications. ...
  12. AWT Text Layout

    by , 03-04-2012 at 05:41 PM
    Text characters shall be laid out by using proper glyphs, in a proper position. This is done before the text gets displayed. To manage the text layouts, these Java 2D mechanisms are used.

    Following is managed by the TextLayout:
    1. Text layout
    2. Hit detection
    3. Highlighting

    To handle cases, the TextLayout gives these facilities.

    1. Strings along with mixed fonts
    2. Bidirectional text
    3. Mixed languages

  13. Java AWT Fonts

    by , 03-04-2012 at 05:39 PM
    Glyphs are those shapes which are being used in a font to present string characters. A particular character or combination of characters is presented by the help of glyphs. E.g.

    • á is presented by 2 glyphs
    • The ligature fi is presented by the help of one glyph

    Collection of glyphs makes a font. Different faces are there for one single font, like regular, italic or bold. In font, all faces consist of same typographic features and are known to be the members ...
  14. Java AWT Text

    by , 03-04-2012 at 05:38 PM
    Text rendering capabilities are provided by the Java 2D API. These methods are included:
    • Rendering Strings
    • Text layouts are performed
    • Entire classes to set the font attributes

    Graphic class’s drawstring method is used to draw the static string. To render directly, this would be the direct approach. SetFont method is used for specification.

    Java 2D Layout class is used to do the implementation of text editing routines. Also, it might help you to have the ...
  15. Geometric Primitives

    by , 03-04-2012 at 05:36 PM
    Following set of the standard shapes are provided by the Java 2D API.
    • Points
    • Ellipses
    • Rectangles
    • Lines
    • Arcs
    • Curves

    To define geometric primitives, package java.awt.geom is considered to be the important one. By integration as well as the combination of straight geometric primitives, you can present arbitrary shapes.
    Shape interface which consists of an outline & interior, presents the geometric shape. These set of methods are provided by this interface. ...
  16. Java 2D Rendering

    by , 03-04-2012 at 05:35 PM
    Uniform rendering model is provided by the Java 2D™ API, across number of devices. Rendering process is similar at the application level no matter the targeted rendering devices is printer or screen. Update/ paint method automatically gets invoked (with appropriate graphic context) if component is required to displayed
    Class java.awt.Graphics2D is included in Java 2D API that provides graphic class an extension so that to give rendering feature and enhanced graphic access. Features included ...
  17. Java 2D API

    by , 03-04-2012 at 05:34 PM
    Following capabilities are provided for the Java program by the Java 2D API via Awt extensions.
    • 2D graphics
    • Image capabilities
    • Text capabilities

    Following supports are provided by these comprehensive rendering packages:
    • Text
    • Line art
    • Images
    • Sophisticated drawing program
    • Full featured framework to create a rich user-interface
    • Image editor

    These capabilities are being provided by the Java 2D API:
    • Rendering model (uniform) to
    Tags: java 2d api Add / Edit Tags
  18. Java 2D Graphics

    by , 03-04-2012 at 05:33 PM
    By the help of The Java 2D API, following tasks are performed easily.

    • Lines are drawn. Rectangles and many other geometric shapes are created.
    • Shapes are filled with gradients or solid colors & textures.
    • Text is drawn along with fine control at the font or rendering process
    • Images are drawn by application of the filtering operations.
    • Operations are applied like transformation or composition while doing the mentioned rendering operations.
  19. Java Graphics

    by , 03-04-2012 at 05:32 PM
    For graphic contexts, abstract base call is the Graphic class. Graphic class permits:

    • Applications to draw the components which have been realized at different devices.
    • Applications to draw the screen images off.

    Graphic objects encapsulate the information that has been stated required to do basic rendering. Following properties are included in the state information.

    1. The Component object.
    2. Translation origin to clip & render ...
  20. ComponentEvent

    by , 03-04-2012 at 05:30 PM
    The ComponentEvent is known as a low leveled event which indicates

    1. Changed Size
    2. Component Moved
    3. Change Visibility

    For sake of notifications, the component events are required. Resizing as well as component moves are handled automatically by AWT. Layout of GUI properly works without taking any special care for all events.

    For other events, this is considered to be a base class:

    • InputEvent
    • WindowEvent ...
  21. MouseEvent

    by , 03-04-2012 at 05:29 PM
    Mouse actions that take place in component are indicated by the MouseEvent. In a particular component, mouse action takes place if there is mouse cursor at the unobscured component parts, when such action occurs.

    In case of the lightweight components when mouse event are enabled at component, they are just dispatched to component.

    Appropriate EventListener addition to the mouse event takes place to enable them. If they are not enable at component the correspondent mouse ...
    Tags: mouseevent Add / Edit Tags
  22. Java AWT Events

    by , 03-04-2012 at 05:27 PM
    Various event types are generated by AWT application. Application is made efficient & effective by the help of such events. In Java AWT, twelve event types are used. They are:

    • ActionEvent
    • ComponentEvent
    • InputEvent
    • TextEvent
    • ContainerEvent
    • AdjustmentEvent
    • FocusEvent
    • ItemEvent
    • MouseEvent
    • KeyEvent
    • PaintEvent
    • WindowEvent
  23. Layout Managers and Containers

    by , 03-04-2012 at 05:26 PM
    A container must contain a layout manager to perform its work. If a layout manager is not associated with a container, the container will place the components wherever specified using following methods.
    A layout manager must be present in a container so that work could be performed. If container and layout manager are not associated with each other, the components will be placed by the container wherever specified by using these methods.

    1. setBounds()
    2. setSize()
    3. setLocation()
  24. GridBagLayout

    by , 03-04-2012 at 05:24 PM
    Components are arranged into grid of columns and rows by the GridBag Layout just the way grid layout manager did so. It also lets you to do the proper specification of the settings so that the components are positioned and sized in cells.

    It is not necessary for all components to be of one uniformed size. E.g. component’s position at grid can be changed or can be spanned to various columns & rows.

    Components present in longest row are used by the layout manager. ...
  25. GridLayout

    by , 03-04-2012 at 05:23 PM
    All components are arranged by the Grid layout manager. This arrangement is done in grid of columns and rows. One of the given options may be selected.
    • Number of columns & rows shall be specified.
    • Only rows are specified and no. of columns will be determined by the layout manager.
    • Just columns are specified and no. of rows will be determined by layout manager.

    Objects present in the layout manager grid have equal sizes which are based at the grid’s largest components. ...
    Tags: gridlayout Add / Edit Tags
  26. CardLayout

    by , 03-04-2012 at 12:12 PM
    Among number of component children, one container is displayed by the help of a card layout. This is similar to the flip cards present at your table. In a program, it can be used so that to show out various child component, to number of users.

    E.g. Interface might have different kind of functionality as shown to user in comparison with that interface which is displayed to administrator. Appropriate interfaces are shown by card layout’s help.

    Usage of the choice components ...
    Tags: cardlayout Add / Edit Tags
  27. FlowLayout

    by , 03-04-2012 at 12:09 PM
    Flow layout is considered as the default layout manager for all applets or panel objects. All components are placed by the flow layout in rows, totally in accordance with panel’s width & size or total no. of components.
    Resizing of the windows shall be done to understand fully the flow layout. It will show you that how from one row, components will float to other.

    Flow layout is given as following.

    Name:  1.JPG
Views: 379
Size:  22.5 KB
    Tags: flowlayout Add / Edit Tags
  28. BorderLayout

    by , 03-04-2012 at 11:52 AM
    Border Layout is for all objects of window’s default layout. There are 5 fixed areas of it, which are:
    1. North
    2. West
    3. Center
    4. South
    5. East

    For container, this given figure illustrates the border layout that has been implemented.
    • In north area, Border Layout Label is present.
    • In the South area, Ok button is present.
    • In the Center area, FRUIT trees list is present.
    • Empty east area.
    • Empty West area. ...
    Tags: borderlayout Add / Edit Tags
  29. List of Layout Managers

    by , 03-04-2012 at 11:49 AM
    Pre-defined entire layout manager is present in java.awt. Interface java.awt.LayoutManager is implemented by the layout manager.

    Every AWT i.e Abstract Windows Toolkit & swing container consists of a pre-defined default layout manager.
    • container.setLayout can be used for setting or changing the layout manager.
    • Interface java.awt.LayoutManager is implemented for customized layout manager.

    Layout managers that are pre-defined are given here:
    • java.awt.BorderLayout
    • java.awt.FlowLayout
    • java.awt.CardLayout
    • java.awt.GridLayout
    • java.awt.GridBagLayout
  30. What is a Layout Manager?

    by , 03-04-2012 at 11:48 AM
    Layout manager is considered responsible for controlling the size or position of those components which are present in container object. E.g, different components (like buttons & labels) are present in window container. Components present in windows are Positioned and re-sized by layout manager.

    One container may possess other container in it. Like, one container window may contain container panel. Given figure shows the purposes of layout manager.

    1. Resizing ...
Page 2 of 3 FirstFirst 123 LastLast