Monday, 4 August 2014

Java Code to find the Area of Circle

Area of a Circle Using Java

A Java program to accept the radius of a Circle from user and calculate the area.


//A small java program to calculate the area of a circle
import java.util.Scanner;

public class JavaCircleArea {

    public static void main(String args[])
   {
      int radius;
      System.out.println("Enter the Radius of the Circle ");

      Scanner in = new Scanner(System.in);
      radius = in.nextInt(); 

      double areaCircle = Math.PI*radius*radius;
      System.out.println("Area of the Circle = "+areaCircle);
   }
    
}


Output:


Enter the Radius of the Circle 
3
Area of the Circle = 28.274333882308138

Wednesday, 2 July 2014

Odd or Even Program in Java

Odd or Even Check using Java Code

A Java program to accept a number from keyboard and check whether it is Odd or Even


//A small java program to check the accepted number is Odd or Even
import java.util.Scanner;

public class OddEven {

    public static void main(String args[])
   {
      int x;
      System.out.println("Enter an integer to check if it is odd or even ");
      Scanner in = new Scanner(System.in);
      x = in.nextInt();

      if ( x % 2 == 0 )
         System.out.println("You entered an even number.");
      else
         System.out.println("You entered an odd number.");
   }
    
}

Output:


Enter an integer to check if it is odd or even 
5
You entered an odd number.

Saturday, 17 May 2014

JAVA Program to Find the Factorial of a Number

Factorial of a number USING JAVA

A program to accept a number from keyboard and print the Factorial.


//A small java program to calculate the Factorial
import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{           final int fact;
             System.out.println("Enter a number to find the Factorial");
             Scanner in = new Scanner(System.in);
             fact=in.nextInt();
             System.out.println( "Factorial of " + fact + " is " + factorial(fact));
}

public static int factorial(int n)
{ 
             int result = 1;
for(int i = 2; i <= n; i++)
result *= i;
return result;
}

}

Output:


Enter a number to find the Factorial
5
Factorial of 5 is 120

Saturday, 10 May 2014

Lambda in Java 8

Lambda Expression in Java


Quick notes on How to use the Lambda feature in new Java


Lambda expressions are a new and important feature included in Java SE 8. They provide a clear and concise way to represent one method interface using an expression. Java code can be improved with the inclusion of lambda expressions.

Syntax of Lambda Expression



(argument) -> (body)



A lambda expression is composed of three parts.


Argument List Arrow Token          Body
(int x, int y)             ->                     x + y

Simple Example for Lambda Expression


(int x, int y) -> x + y

() -> 42

(String s) -> { System.out.println(s); }


           The first expression takes two integer arguments, named x and y, and uses the expression form to return x+y. The second expression takes no arguments and uses the expression form to return an integer 42. The third expression takes a string and uses the block form to print the string to the console, and returns nothing.

Friday, 18 April 2014

Multiplication Table using Java

Simple Multiplication Table in Java

Java Code to print Multiplication Table


//A small java program to print the Multiplication Table


import java.util.Scanner;
class MultiplicationTable
{
   public static void main(String args[])
   {
      int n, c;
      System.out.println("Enter an integer to print it's multiplication table");
      Scanner in = new Scanner(System.in);
      n = in.nextInt();
      System.out.println("Multiplication table of "+n+" is :-");
      for ( c = 1 ; c <= 10 ; c++ )
         System.out.println(n+"*"+c+" = "+(n*c));
   }
}


Output:

        The output of the program is as shown below

Mutiplication Table


Friday, 14 March 2014

LAYOUT MANAGERS:FlowLayout

FlowLayout places component in rows from left to right. Components towards the end of row are written on next row............

FlowLayout

FlowLayout places component in rows from left to right. Components towards the end of row are written on next row, if there is not enough space in the current row. The FlowLayout honors the specified size of a component. The size of a component never changes regardless of size of container.

 constructors of FlowLayout


Typically the constructor is called in the call to the container's setLayout method (see example code). The parameterless FlowLayout() constructor is probably most common, but there are some good places to use the alignment.

  • FlowLayout();
  • FlowLayout(int alignment);
  • FlowLayout(int alignment, int hor_gap, int ver_gap);

Alignment can take values of constants - LEFT, CENTER and RIGHT. The default alignment for the components in a row is center. Default horizontal and vertical gaps are 5 pixels.


  • FlowLayout.LEFT
  • FlowLayout.CENTER
  • FlowLayout.RIGHT

LAYOUT MANAGERS:BorderLayout

The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center. 

Border Layout

The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center. Each region is can contain only one component and each component in each region is identified by the corresponding constant NORTH, SOUTH, EAST, WEST, and CENTER.

constructors


  • BorderLayout():Constructs a new border layout with no gaps between components.

  • BorderLayout(int hgap, int vgap):Constructs a border layout with the specified gaps between components.

Thursday, 13 March 2014

LAYOUT MANAGERS

A Layoutmanager automatically arrange your controls within a window by using some type of algorithm.Java technology uses Layout Managers to define the location and size of Graphical User Interface components.


UNDERSTANDING LAYOUT MANAGERS:



A Layoutmanager automatically arrange your controls within a window by using some type of algorithm.Java technology uses Layout Managers to define the location and size of Graphical User Interface components. Java technology does not encourage programmers to use absolute location and size of components. Java technology instead places components based on specified Layout Manager. 

          A Layout Manager implements a layout policy that defines constraints between components in a container.Create a new layout object (using one of its constructors) and use the container's setLayout method to set the layout. Each layout has its own way to resize components to fit the layout, and you must become familiar with these.A layout manager is an object that implements the LayoutManager interface* and determines the size and position of the components within a container. Although components can provide size and alignment hints, a container's layout manager has the final say on the size and position of the components within the container.

Basic Layout Managers


  • FlowLayout:

Default for java.applet.Applet, java.awt.Panel and java.swing.JPanel. Places components sequentially (left to right) in the order they were added. You can specify the order.

FileDialog Box

Actually, you have already written code to open a file. ......

Open FileDialog Box

Actually, you have already written code to open a file. The process is no different for the open file dialogue box. And because you have already written the classes that open and write to a file, you can just import them into the current project.To import a class that you have already written, have a look at the Properties window on the left of NetBeans. (If you can't see the properties window, click the Window menu item at the top of NetBeans. From the Window menu, select Properties.)

Expand the entry for your current project, and right-click the Libraries item:

Wednesday, 12 March 2014

MENUS

Java's Abstract Windowing Toolkit (AWT) includes four concrete menu classes: Menu, MenuItem ,MenuBar ,CheckboxMenuItem......

MENU BARS AND MENUS


Java's Abstract Windowing Toolkit (AWT) includes four concrete menu classes: menu bars representing a group of menus that appears across the top of the window or the screen (class MenuBar); pull-down menus that pull from menu bars or from other menus (class Menu); menu items that represent menu selections (class MenuItem); and menu items that the user can turn on and off (class CheckBoxMenuItem).
                  These classes are all subclasses of MenuComponent, not subclasses of Component. Because they aren't components, they can't be placed in any container -- the way you would place buttons and lists in a container. In a graphical user interface (GUI) the only way to use these menu classes is to place a menu bar (which can contain additional menus) in a frame using the frame's setMenuBar method. Since the applet class is not a subclass of Frame, it does not inherit the setMenuBar method. 

This means you cannot simply place a menu bar in an applet.


The main advantages of using AWT menus in applets rather than using a custom pop-up-menu class are:

Tuesday, 11 March 2014

LAYOUT MANAGERS:CardLayout

A CardLayout object is a layout manager for a container. It treats each component in the container as a card.......

CardLayout


A CardLayout object is a layout manager for a container. It treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout object is the visible component when the container is first displayed. The ordering of cards is determined by the container's own internal ordering of its component objects. CardLayout defines a set of methods that allow an application to flip through these cards sequentially, or to show a specified card. The addLayoutComponent(java.awt.Component, java.lang.Object) method can be used to associate a string identifier with a given card for fast random access.

CardLayout provides these two constructors


  • CardLayout():Creates a new card layout with gaps of size zero.
  • CardLayout(int hgap, int vgap):Creates a new card layout with the specified horizontal and vertical gaps.

LAYOUT MANAGERS:GridLayout

A GridLayout places components in a grid of cells


GridLayout

GridLayout lays out components in a two dimensional grid.When you instantiate a gridLayout ,you define the number of rows and columns.A GridLayout places components in a grid of cells.Each component takes all the available space within its cell.Each cell is exactly the same size.Components are added to the layout from left to right, top to bottom.

The constructers supported by the GridLayout are shown here


  • GridLayout():create a single_column grid layout
  • GridLayout(int rows, int columns):Creates a grid layout with the specified number of rows and columns.
  •  GridLayout(int rows, int columns, int horizontalGap, int verticalGap):To specify the horizontal and vertical space left between components in horzontalGap and verticalGap

Thursday, 6 March 2014

AWT CONTROLS:TextField

TextField  is subclasses of TextComponent.................

Using a TextField


      A TextField object is a text component that allows for the editing of a single line of text. A scrollable text display object with one row of characters is known as the TextField. 

TextField defines the following constructors:


  •  TextField(): Constructs a new text field.

  •  TextField(int numChars): Constructs a new empty TextField with the specified number of columns.

  •  TextField(String str): Constructs a new text field initialized with the specified text.

  •  TextField(String str, int numChars): Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of characters.


TextField defines the following methods:


  • getEchoChar():Gets the character that is to be used for echoing.

                syntax
                    char  getEchoChar()

  •  echoCharIsSet():Indicates whether or not this text field has a character set for echoing.

                syntax
                    boolean echoCharIsSet()

AWT CONTROLS:ScrollBars

A scrollbar is represented by a "slider" widget.......

using Scroll bars

          Scrollbar control represents a scroll bar component in order to enable user to select from range of values.The Scrollbar class embodies a scroll bar, a familiar user-interface object. A scroll bar provides a convenient means for allowing a user to select from a range of values.

Common Constructors:


  • Scrollbar ():

                Creates a Scrollbar instance with a range of 0-100, an initial value of 0, and vertical orientation.

  • Scrollbar(int style):

                     Constructs a new scroll bar with the specified orientation.

  • Scrollbar(int style, int initialValue, int thumbSize, int min, int max)

                   Constructs a new scroll bar with the specified orientation, initial value, page size, and minimum and maximum values.


common methods


  •  getUnitIncrement():  Gets the unit increment for this scrollbar.

                 syntax
                     int getUnitIncrement()

  •  getValue() : Gets the current value of this scroll bar

                syntax:
                      int getValue()

Wednesday, 5 March 2014

AWT CONTROLS:Lists control

The List represents a list of text items............ 

using lists


         The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.The List provides a compact,multiple-choice ,scrolling selection list.Unlike the choice object,which shows only the single selected item in the menu,aList object can be constructed to show any number of choices in the visible window.Itcan also be constructed to allow multiple selections.

List provides these constructors:


  •  List()

              Creates a new scrolling list. Initially there are no visible lines, and only one item can be selected from the list. 

  •  List(int numRows)

             Creates a new scrolling list initialized with the specified number of visible lines. By default, multiple selections are not allowed.Parameter,rows specified by the number of items to show.

  •  List(int numRows,boolean multipleMode)

             Creates a new scrolling list initialized to display the specified number of rows. If the value of multipleMode is true, then the user can select multiple items from the list. If it is false, only one item at a time can be selected.Parameters,numRows specified by the number of items to show and multipleMode,if true, then multiple selections are allowed; otherwise, only one item can be selected at a time .

Lists provides these methods:


  • add(String item) :Adds the specified item to the end of scrolling list.

           syntax:
                void add(String item) 

  • add(String item, int index) :Adds the specified item to the the scrolling list at the position indicated by the index

          syntax:
         void add(String item, int index) 

  • getSelectedIndex():Gets the index of the selected item on the list,

Tuesday, 4 March 2014

AWT CONTROLS:CHOICE CONTROLS

Choice defines only the default constructor, which creates an empty list....................

Choice controls:

       The Choice class is used to create a pop-up list of items from which the user may choose. Thus, a Choice control is a form of menu. When inactive, a Choice component takes up only enough space to show the currently selected item. When the user clicks on it, the whole list of choices pops up, and a new selection can be made. Each item in the list is a string that appears as a left-justified label in the order it is added to the Choice object. Choice defines only the default constructor, which creates an empty list.


choice control: constructors

  • Choice():   Creates a new choice menu.

choice control:methods


  • add( ):To add a selection to the list, call add( ). 

syntax:
         void add(String name)


  • getSelectedIndex():Returns the index of the currently selected item.

syntax:
         int getSelectedIndex()


  • getSelectedItem():Gets a representation of the current choice as a string.

syntax:
        string getSelectedItem()

AWT CONTROLS IN JAVA:CHECK BOXES

A check box is a graphical component that can be in either an "on" (true) or "off" ........

Applying checkbox

A check box is a control that is used to turn an option on or off. It consists of a small box that can either contain a check mark or not. There is a label associated with each check box that describes what option the box represents. You change the state of a check box by clicking on it. Check boxes can be used individually or as part of a group. Check boxes are objects of the Checkbox class.A check box is a graphical component that can be in either an "on" (true) or "off" (false) state. Clicking on a check box changes its state from "on" to "off," or from "off" to "on."

Checkbox supports these constructors:


  • Checkbox():

               Creates a check box with an empty string for its label.

  • Checkbox(String label):

                 Creates a check box with the specified label.

  • Checkbox(String label, boolean state):

                   Creates a check box with the specified label and sets the specified state.

  • Checkbox(String label, boolean state, CheckboxGroup group):

                   Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group.

Monday, 3 March 2014

AWT CONTROLS IN JAVA:BUTTONS

AWT BUTTON Class

Create AWT Buttons with simple Example..........

The java.awt package comes with many GUI components of which Button is the most important and most frequently used. A button functionality (what for it is) can be known by its label like OK or Cancel etc. A mouse click on the button generates an action.

Following is the class signature

public class Button extends Component implements Accessible

Any GUI component with event handling can be broadly divided into 8 steps.

  • Import java.awt and java.awt.event packages
  • Extending frame or applet and implementing appropriate listener interface that can handle    the events of the component successfully.
  • Set the layout.
  • Create components
  • Register or link the component with the listener interface
  • Beautification of the components (optional)
  • Adding the components to the frame or applet
  • Override all the abstract methods of the listener interface

AWT CONTROLS IN JAVA:LABELS

AWT Label Class

Create AWT Label with simple Example..........

INTRODUCTION

Label component displays text just like a drawString(). The difference is Label gets the status of a component so that it can be added in position format using layout manager. Label displays text in one line only. User cannot edit the text of the label. It is meant only for the programmer to display some information. The label does not raise any events (the other only component that does not raise events is Panel). 

FIELDS

Following are the fields for java.awt.Component class:
  • static int CENTER
  • static int LEFT 
  • static int RIGHT 

public static final int LEFT = 0       label is aligned to left
public static final int CENTER = 1 label is aligned to center
public static final int RIGHT = 2         label is aligned to right

USING AWT CONTROLS,LAYOUT MANAGERS,AND MENUS

CONTROL FUNDAMENTALS IN JAVA

What are the different  types of AWT support  control fundamentals in java..........

The AWT supports the following types of controls:-
  • Labels
  • Push buttons
  • Check boxes
  • Choice lists
  • Lists
  • Scroll bars
  • Text editing
ADDING AND REMOVING CONTROLS:

To include a control in a window, you must add it to the window. To do this, you must first create an instance of the desired control and then add it to a window by calling add( ), which is defined by Container. 

The add( ) method has several forms


Component add(Component compObj)

Thursday, 27 February 2014

METHODS FOR FONTS IN GRAPHICS CLASS

WORKING WITH FONTS

Font Class in java applet with sample program..........

The AWT supports multiple type fonts. Within AWT, a font is specified by its name, style, and size. Each platform that supports Java provides a basic set of fonts. Beginning with Java 2, fonts have a family name, a logical font name, and a face name. The family name is the general name of the font, such as Courier. The logical name specifies a category of font, such as Monospaced. The face name specifies a specific font, such as Courier Italic.
An instance of the Font class represents a specific font to the system.

The Font class defines these variables:-


 Variable                     Meaning


 protected String name                    Name of the font
 protected int size                              Size of the font in points
 protected int style                            Font style


There are four styles for displaying fonts in Java: plain, bold, italic, and bold italic. Three class constants are used to represent font styles:

public static final int BOLD:The BOLD constant represents a boldface font.

public static final int ITALIC:The ITALIC constant represents an italic font.

public static final int PLAIN:The PLAIN constant represents a plain or normal font.

The combination BOLD/ITALIC represents a bold italic font. PLAIN combined with either BOLD or ITALIC represents bold or italic, respectively.

INTRODUCING THE AWT:Working With Color

Java supports color in a portable, device-independent fashion.


Working with Color

Java supports color in a portable, device-independent fashion. The AWT color system allows you to specify any color you want. It then finds the best match for that color, given the limits of the display hardware currently executing your program or applet. Thus, your code does not need to be concerned with the differences in the way color is supported by various hardware devices. Color is encapsulated by the Color class.


color constructors


To create your own colors,using one of the color constructors.the most commly used forms are shown here:

  • Color (int red, int green, int blue)
  • Color (int rgbValue) //int rgbValue = (0xff000000 | (0xc0<<16) | (0x00 <<8) | 0x00);
  • Color (float red, float green, float blue)

The first constructors take three integers that specify the color as the mix of red,green and blue. these values must be between 0 and 255.

example:
new color(255,100,100); // light red.


The second color constructor takes a single integer that contain the mix of red,greenand blue packed into an integer.the integer is organized with red in bits 16 to 23,green in bits 8 to 15,and blue in bits 0 to 7.

BASIC GRAPHICS IN JAVA WITH EXAMPLE

SETTING THE PAINT MODE

set drawing mode to XOR  example..........

PAINTING MODE:


There are two painting or drawing modes for the Graphics class:- paint mode which is the default mode and XOR mode. In paint mode, anything we draw replaces whatever is already on the screen i.e. it overwrites any preexisting contents. If you draw a green circle, you get a green circle, no matter what was underneath.The paint mode determines how objects are drawn in a window. It is possible to have new objects XORed on to the window by using setXORMode().

Syntax

void setXORMode(Color XORColor)

INTRODUCING THE AWT:Working With Graphics

AWT supports a rich assortment of graphics method.All graphics are drawn reative to window..........

Working with Graphics

The AWT supports a rich assortment of graphics method.All graphics are drawn reative to window.This can be a main wi ndow of an applet,a child window of an applet ,or stand alone appliction of window.The origin of each window is at the top-left corner and is 0,0. Coordinates are specified in pixels. All output to a window takes place through a graphics context. 

A graphics context is encapsulated by the Graphics class and is obtained in two ways:

• It is passed to a method, such as paint( ) or update( ), as an argument.

• It is returned by the getGraphics( ) method of Component.

The Graphics class defines a number of drawing functions.Each shape can be drawn edge only or filled .several drawing methods are:

  • Drawing Lines

      Lines are drawn by means of the drawLine() method,shown here:

                               void drawLine(int startX,int startY,int endX,int endY)

simple applet program to drawn a line


import java.applet.*;
import java.awt.*;
public class DrawingLines extends Applet
 {
   int width, height;
   public void init()
 {
      width = getSize().width;
      height = getSize().height;
      setBackground( Color.black );
   }
   public void paint( Graphics g ) 
{
      g.setColor( Color.green );
      for ( int i = 0; i < 10; ++i ) 
{
         g.drawLine( width, height, i * width / 10, 0 );
      }
   }
}

Wednesday, 26 February 2014

CREATING A WINDOWED PROGRAM

How to  Create an AWT-based application.

Creating applets is the most commom use for java's AWT
But,it is possible to create stand-alone AWT based applications to do this

  • simply create an instance of the window or windows you need inside main()
  • e.g. create frame window with in main()

The example program is  shown below:

// Create an AWT-based application.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
// Create a frame window.
public class AppWindow extends Frame 
{
String keymsg = "This is a test.";
String mousemsg = "";
int mouseX=30, mouseY=30;
public AppWindow() 
{
addKeyListener(new MyKeyAdapter(this));
addMouseListener(new MyMouseAdapter(this));
addWindowListener(new MyWindowAdapter());
}
public void paint(Graphics g) {
g.drawString(keymsg, 10, 40);
g.drawString(mousemsg, mouseX, mouseY);
}

CREATING A FRAME WINDOW IN AN APPLET

How to create a child frame window from within an applet...........

Creating a new frame window from within an applet is actually quite easy.
The following steps may be used to do it,
  • Create a subclass of Frame
  • Override any of the standard window methods,such as init(),start(),stop(),and paint().
  • Implement the windowClosing() method of the windowlistener interface,calling setVisible(false)when the window is closed
  • Once you have defined a Frame subclass,you can create an object of that class.But it will note be initially visible
  • When created,the window is given a default height and width
  • You can set the size of the window explicitly by calling the setSize() method
The example program is  shown below:

Tuesday, 25 February 2014

WORKING WITH FRAME WINDOWS

HOW TO MAKE FRAMES(MAIN WINDOW)


How to Creating a frame window in an applet

   Creating a new frame window from within an applet is actually quite easy. First, create a subclass of Frame. Next, override any of the standard applet methods, such as init( ), start( ), and stop( ), to show or hide the frame as needed. Finally, implement the windowClosing( ) method of the WindowListener interface, calling setVisible(false) when the window is closed.After the applet, the type of window you will most often create is derived from Frame.

Frame’s constructors are as follows:

Frame( )
Frame(String title)

    The first form creates a standard window that does not contain a title.The second form creates a window with the title specified by title. We cannot specify the dimensions of the window. We must set the size of the window after it has been created. Some of the methods used when working with windows are as follows:

SETTING THE WINDOW'S DIMENSIONS:

The setSize( ) method is used to set the dimensions of the window.

Its signature is shown here:

                       void setSize(int newWidth, int newHeight)
                       void setSize(Dimension newSize)

EVENT CLASSES:WindowEvent Class

WindowEvent is a subclass of ComponentEvent.....................

The WindowEvent Class


              A low-level event that indicates that a window has changed its status. This low-level event is generated by a Window object when it is opened, closed, activated, deactivated, iconified, or deiconified, or when focus is transfered into or out of the Window.The event is passed to every WindowListener or WindowAdapter object which registered to receive such events using the window's addWindowListener method. (WindowAdapter objects implement the WindowListener interface.) Each such listener object gets this WindowEvent when the event occurs.

TheWindowEvent class: integer constants


  • WINDOW_ACTIVATED           : The window was activated.
  • WINDOW_CLOSED                 :The window has been closed.
  • WINDOW_CLOSING                 : The user requested that the window be closed.
  • WINDOW_DEACTIVATED       :The window was deactivated.
  • WINDOW_DEICONIFIED          :The window was deiconified.
  • WINDOW_GAINED_FOCUS    :The window gained input focus.
  • WINDOW_ICONIFIED                :The window was iconified.
  • WINDOW_LOST_FOCUS         :The window lost input focus.
  • WINDOW_OPENED                   :The window was opened.
  • WINDOW_STATE_CHANGED :The state of the window changed.

 

WindowEvent:- constructors. 


  • WindowEvent(Window src, int type)
  • WindowEvent(Window src, int type, Window other)
  • WindowEvent(Window src, int type, int fromState, int toState)
  • WindowEvent(Window src, int type, Window other, int fromState, int toState)

         Here,src is a reference to the object that generated this event. other specifies the

WINDOW FUNDAMENTALS

SOME JAVA FUNDAMENTALS OF THE AWT

Concept of window and advanced components in java


   The AWT defines windows according to a class hierarchy that adds functionality and specificity with each level. The two most common windows are those derived from Panel, which is used by applets, and those derived from Frame, which creates a standard window. Much of the functionality of these windows is derived from their parent classes.

Component


         At the top of the AWT hierarchy is the Component class. Component is an abstract class that encapsulates all of the attributes of a visual component. All user interface elements that are displayed on the screen and that interact with the user are subclasses of Component. It defines over a hundred public methods that are responsible for managing events, such as mouse and keyboard input, positioning and sizing the window, and repainting. A Component object is responsible for remembering the current foreground and background colors and the currently selected text font.

EVENT CLASS:TextEvent class

Instances of this class describe text events.........

The TextEvent Class


           Instances of this class describe text events. These are generated by text fields and text areas when characters are entered by a user or program.TextEvent defines the integer constant TEXT_VALUE_CHANGED.

TextEvent Class: constructor

         
       TextEvent(Objectsrc, int type)

            Here,src is a reference to the object that generated this event. The type of the event is specified by type.

Monday, 24 February 2014

INTRODUCTION TO THE AWT

WHAT ARE AWT CLASSES IN JAVA


A description of Java's user interface toolkit

The Abstract Window Toolkit(AWT) contains numerous classes and methods that allow you to create and manage windows. Although the main purpose of the AWT is to support applet windows, it can also be used to create stand-alone windows that run in GUI environment, such as windows.The AWT classes are contained in the 'java.awt' package. Fortunately, because it is logically organized in a top-down,hierarchical fashion, it is easier to understand and use.

EVENT CLASSES:MouseWheelEvent class

The MouseWheelEvent class encapsulates a mouse wheel event.........

The MouseWheelEvent Class:

        
The MouseWheelEvent class encapsulates a mouse wheel event. It is a subclass of MouseEvent. Not all mice have wheels. If a mouse has a wheel, it is located between the left and right buttons. Mouse wheels are used for  scrolling.

MouseWheelEvent :- integer constants:

  • WHEEL_BLOCK_SCROLL :      A page-up or page-down scroll event occurred.
  • WHEEL_UNIT_SCROLL      :          A line-up or line-down scroll event occurred.

EVENTLISTENER INTERFACES IN JAVA

THE JAVA LISTENER INTERFACES AND THEIR METHODS

Provides interfaces and classes for dealing with different types of events fired by AWT components.

An event listener registers with an event source to receive notifications about the events of a particular type.
Various event listener interfaces defined in the java.awt.event package are given below :


EVENT CLASSES:MouseEvent Class

 KeyEvent and MouseEvent are subclasses of abstract InputEvent class..................

The MouseEvent Class

                    KeyEvent and MouseEvent are subclasses of abstract InputEvent class. Both these events are generated by objects of type Component class and its subclasses.The MouseEvent is generated when the user presses the mouse or moves the mouse.


The MouseEvent class defines the following integer constants:


  • MOUSE_CLICKED    :     The user clicked the mouse.
  • MOUSE_DRAGGED  :     The user dragged the mouse.
  • MOUSE_ENTERED   :     The mouse entered a component.
  • MOUSE_EXITED        :     The mouse exited from a component.
  • MOUSE_MOVED        :     The mouse moved.
  • MOUSE_PRESSED   :     The mouse was pressed.
  • MOUSE_RELEASED:    The mouse was released.
  • MOUSE_WHEEL        :    The mouse wheel was moved.


 MouseEvent constructors:


MouseEvent(Componentsrc, int type, long when, int modifiers,int x, int y, int clicks, boolean triggersPopup)

Saturday, 22 February 2014

EVENT CLASSES:The KeyEvent Class

KeyEvent and MouseEvent are subclasses of abstract InputEvent class .............


The KeyEvent class


                 A KeyEvent is gnerated when the keyboard input occurs.This low-level event is generated by a component object (such as a text field) when a key is pressed, released, or typed. The event is passed to every KeyListener or KeyAdapter object which registered to receive such events using the component's addKeyListener method.

Integer constants:


CHAR_UNDEFINED:
KEY_PRESSED and KEY_RELEASED events which do not map to a  valid Unicode character use this for the keyChar value.

KEY_FIRST:
               The first number in the range of ids used for key events.
KEY_LAST:
             The last number in the range of ids used for key events.

KEY_PRESSED:
          The "key pressed" event.