Data Members and Properties of Netbeans IDE 7.0

Embed Size (px)

Citation preview

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    1/28

    NetBeans IDE

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    2/28

    After studying this lesson the students willbe able to:

    Identify, name and state the usage of

    the different components of theNetBeans IDE.

    Identify and name the various methodsand properties associated with thevarious form controls

    Create simple applications in Java usingNetBeans IDE.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    3/28

    NetBeans IDE allows us to develop applicationsby dragging and positioning GUI componentsfrom a palette onto a container. The GUI builderautomatically takes care of the correct spacingand alignment of the different componentsrelative to each other. The JFrame acts as acontainer for the elements like the JLabel,JButton, JTextArea and allows direct editing of

    their associated properties at the design time andrun time. The related methods are used in thecode to develop applications for a specific task.The concept of variables and control structuresare used to simplify the code of the applications.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    4/28

    It can be used to create java applications very easily

    using the efficient GUI builder. Let us quickly recap

    the different components of the NetBeans IDE:

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    5/28

    1) Title Bar

    2) Menu Bar with pull down menus

    3) Toolbars

    4) GUI builder: It is an area to place

    components on the form visually. There

    are two views of the GUI builder- theDesign View and the Source View. We

    can switch over from one view to

    another by simply clicking on the

    source and design tabs directly abovethe Design Area.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    6/28

    5. Palette: Palette contains controls orcomponents used to create GUI

    applications.

    6. Inspector Window: This window is usedto display a hierarchy of all thecomponents or controls placed on thecurrent form.

    7. Properties Window: Using this windowwe can make changes in the properties

    of currently selected control on the form.8. Code Editor Window: - It is the areawhere we write code for our javaapplication.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    7/28

    Components

    Components (also known as "widgets") are the basicinterface elements the user interacts with: jlabels,jbuttons, jtextfields etc. Components are placed on acontainer (like the jFrame). There are two types of

    controls :

    Parent or Container Control: They act as abackground for other controls. For example-Frame. When we delete a parent control, all its

    child controls get deleted. When we move a parentcontrol all its child controls also move along with it.

    Child Control: controls placed inside a containercontrol are called child controls. For example-TextField, Label, Button etc.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    8/28

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    9/28

    Creating a New Project

    The steps to create a new project are:

    1. Select New Project from the File menu. Youcan also click the New Project button in the

    IDE toolbar.2. In the Categories pane, select the General

    node. In the Projects pane, choose the JavaApplication type. Click the Next button.

    3. Enter the name of the project in the ProjectName field and specify the project location. Donot create a Main class here.

    4. Click the Finish button.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    10/28

    Project Window Showing Multiple Forms

    Further each form can have one or more elements - some of which

    may be visible and some invisible. The visible components are all

    shown under the Frame Component and the non-visible

    components are part of Other components.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    11/28

    Drag and Drop Feature

    We use the drag and drop feature of NetBeansto place components on the form to design aneffective interface for our applications. The firststep that we undertook while designing our

    applications was adding a new jFrame form.

    The jFrame is a window with Multiple Formsunder one Project Project Name, title, border,(optional) menu bar and is used to contain allother components placed by the user on theform. Some of the properties of the jFrameform are defaultCloseOperation and Title.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    12/28

    Properties of jFrame Form

    Any component of GUI front-end (the form itself and theswing containers and controls placed in the form) of anapplication is an object. Each of these objects belongs to itscorresponding class predefined in Java. For example, a

    form is an object of JFrame class, all the textfields areobjects of JTextField class, and so on. Each object hassome properties, methods, and events associated with itusing which you can control the object's appearance andbehaviour.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    13/28

    Properties, Methods and Events

    Properties

    Properties of an object are used to specify its appearance on the form. Forexample to set the background colour of a textfield you change itsbackground property; to set its font you change its font property; and so on.

    MethodsMethods are used to perform some action on the object. For example todisplay something in a textfield you can use its setText() method, to extractthe contents of a textfield you can use its getText() method.

    Methods can be divided into two categories getters and setters.

    Getters are the methods which extract some information from theobject and return it to the program. Getters start with the word get.Examples of getters are: getText(), getForeground(), getModel(),isEditable etc.

    Setters are the methods which set some properties of the object sothat the object's appearance changes. Setters start with the word set.Examples of setters are: setText(), setForground(), setModel() etc.

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    14/28

    Cont..

    Events

    Events are the actions which are performed oncontrols. Examples of events are: mouseClick,mouseMoved, keyPressed etc. When the userperforms any action on a control, an event happensand that event invokes (sends a call to) thecorresponding part of the code and the application

    behaves accordingly.

    After setting the properties of the jFrame we can startplacing components like jButton on the jFrame form. Abutton is a component that the user presses or

    pushes to trigger a specific action. When the userclicks on the button at runtime, the code associatedwith the click action gets executed. The variousmethods and properties associated with the jButtonare summarized

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    15/28

    Properties

    and

    methods

    ofjButton

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    16/28

    jTextField and jLabel

    jTextField allows editing/displaying of a

    single line of text. jTextField is an input

    area where the user can type in characters

    whereas a jLabel provides text instructionsor information. It displays a single line of

    read-only text, an image or both text and

    image. The various methods andproperties associated with the jTextField

    and jLabel are summarized

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    17/28

    Properties and Method of jTextField

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    18/28

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    19/28

    Properties and Methods of jLabel

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    20/28

    When we had become familiar with the usage of jTextField and jLabel controls then

    we developed an application in which we wanted to accept multiline input anddisplay multiline output. Well can you recall the name of the component. Exactly the

    component is Text Area component. This component allows us to accept multiline

    input from the user or display multiple lines of information. This component

    automatically adds vertical or horizontal scroll bars as and when required during run

    time. The various methods and properties associated with the jTextArea are

    summarized

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    21/28

    Properties and Methods of jTextArea

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    22/28

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    23/28

    Properties of jPassword

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    24/28

    Radio Button and Check Boxes

    We have used radio buttons when we wanted to provide theuser several choices and allowed him to select one of thechoices (the radio buttons belong to a group allowing the userto select single option). But radio buttons occupy a lot ofspace. Thus, in case of too many options we used Combo

    boxes as they help save space and are less cumbersome todesign as compared to radio button.

    We used check box and list when we wanted to displaymultiple options like selecting favourite sports or ordering

    multiple food items in a restaurant. The list is a preferredoption over check box in situations wherever multiple optionsare required to be selected from a large number of known setof options as they help save space and are less cumbersometo design as compared to check boxes. The properties andmethods of jRadioButton are summarized below:

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    25/28

    Properties and Methods of jRadioButton

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    26/28

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    27/28

    Properties and Methods of jCheckBox

    jCheckBox is a small box like component that is either marked or

    unmarked. When you click on it, it changes from checked to unchecked or

    vice versa automatically. The properties and methods of jCheckBox are

    summarized below:

  • 8/6/2019 Data Members and Properties of Netbeans IDE 7.0

    28/28