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)