java ide programming - ii. controls for output in order to display information to the user, we need...

Post on 14-Jan-2016

224 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

JAVA IDE PROGRAMMING - II

Controls for Output

In order to display information to the user, we need certain controls. These are as follows:

Label

Label is the component of JLabel class. It is used to display the text that can not be edit.

Commonly Used properties of Label

• enabled: This property determines whether the label is active or not.

• font: This property is used to set the font of the text that appear on the label.

• foreground: This property is used to set the color of the text that appear on the label.

• text: This property is used to set the text of the label.

Commonly Used methods of Label

void setText(String)- It is used to set the text of the label with the string specified in parenthesis.The general syntax to use the setText() method with the label is as follows:

<labelname>.setText(string);

Commonly Used methods of Label

void getText()- It is used to get the text of the label. The general syntax to use getText() method with the Label is as follows

<labelname>.getText();

TextField

TextField is a component of JTextField class and it is used to obtain the input from the user or display the message to the user.

Commonly Used properties of TextField

• background: This property is used to set the background color of the JTextField.

• enabled: This property determines whether the JTextField is active or not.

• font: This property is used to set the font of the text that appear on the JTextField.

• foreground: This property is used to set the color of the text that appear on the JTextField.

• text : This property is used to set the text of the JTextField.

• editable: This property determines whether user can edit the text or not.

Commonly Used methods of TextField

void setText(String)- It is used to set the text of the TextField with the string specified in parenthesis. The general syntax to use the setText() method with the TextField is as follows:

<TextFieldname>.setText(string);

Commonly Used methods of TextField

void getText()- It is used to get the text of the TextField. The general syntax to use getText() method is as follows

<textfieldname>.getText();

Commonly Used methods of TextField

boolean isEditable()- It returns the setting (true/false) whether the user can edit the text in TextField or not. The general syntax to use this method is as follows:

<textfieldname>.isEditable();

Commonly Used methods of TextField

boolean isEnabled()- It returns the setting (true/false) whether the TextField is active or not. The general syntax to use this method is as follows:

<textfieldname>.isEnabled();

TextArea

It is a multi-line text component to display text or allow user to enter text. It is created through JTextArea class of swing.

Commonly Used properties of TextArea

• background: This property is used to set the background color of the JTextArea.

• enabled: This property determines whether the JTextArea is active or not.

• font: This property is used to set the font of the text that appear on the JTextArea.

• foreground: This property is used to set the color of the text that appear on the JTextArea.

Commonly Used properties of TextArea

• editable: This property determines whether user can edit the text or not.

• rows: This property is used to set the number of rows for the Text Area.

• columns : This property is used to set the number of columns of the Text Area.

Commonly Used methods of TextArea

void setText(String)- It is used to set the text of the TextArea with the string specified in parenthesis. The general syntax to use the setText() method is as follows:

<textareaname>.setText(string);

Commonly Used methods of TextArea

void getText()- It is used to get the text of the TextArea. The general syntax to use getText() method is as follows

<textareaname>.getText();

Commonly Used methods of TextArea

boolean isEditable()- It returns the setting (true/false) whether the user can edit the text in TextArea or not. The general syntax to use this method is as follows:

<textareaname>.isEditable();

Commonly Used methods of TextArea

boolean isEnabled()- It returns the setting (true/false) whether the TextArea is active or not. The general syntax to use this method is as follows:

<TextAreaname>.isEnabled();

Commonly Used methods of TextArea

void append(string)- It adds the string specified in parenthesis to the end of TextArea. The general syntax to use this method is as follows:

<TextAreaname>.append(string);

PasswordField

Password field is a field which display the text in encrypted form. It is a components of JPasswordField class of swing.

Commonly Used properties of PasswordField

• background: This property is used to set the background color of the JPasswordField.

• font: This property is used to set the font of the text that appear on the JPasswordField.

• foreground: This property is used to set the color of the text that appear on the JPasswordField.

• echoChar: This property determines which character will replace the text in display.

Commonly Used methods of Passwordfield

char getEchoChar: This method will return the echo character of a password field. The general syntax to use this method is as follows:

<passwordfieldname>.getEchoChar();

Commonly Used methods of Passwordfield

void setEchoChar(char)- It sets the echo character – the character displayed instead of the actual characters typed by the user.The general syntax to use this method is as follows:

<passwordfieldname>.setEchoChar(char);

CheckBox

Check box is a control that indicates whether a particular condition is on or off. It is a components of JCheckBox class

Commonly Used properties of CheckBox

• background: This property is used to set the background color of the CheckBox.

• enabled: This property determines whether the CheckBox is active or not.

• font: This property is used to set the font of the text that appear on the CheckBox.

• foreground: This property is used to set the color of the text that appear on the CheckBox.

• text : This property is used to set the text of the JCheckBox.

• selected: if sets to true checkbox appear selected.

Commonly Used methods of CheckBox

boolean isSelected(): it returns the state of the checkbox. “true” if selected otherwise “false”. The general syntax to use this method is as follows:

<checkboxname>.isSelected();

Commonly Used methods of CheckBox

void setSelected(booleanvalue): it is used to check or uncheck the Checkbox. The general syntax to use this method is as follows:

<checkboxname>.setSelected(booleanvalue);

Commonly Used methods of CheckBox

void setText(String)- It is used to set the text of the CheckBox with the string specified in parenthesis. The general syntax to use the setText() method is as follows:

<CheckBoxname>.setText(string);

Commonly Used methods of CheckBox

void getText()- It is used to get the text of the CheckBox. The general syntax to use getText() method is as follows

<CheckBoxname>.getText();

RadioButton

RadioButton is used to provide the set of choices, out of that user can select one and only one.

Commonly Used properties of RadioButton

• background: This property is used to set the background color of the RadioButton.

• enabled: This property determines whether the RadioButton is active or not.

• font: This property is used to set the font of the text that appear on the RadioButton.

• foreground: This property is used to set the color of the text that appear on the RadioButton.

Commonly Used properties of RadioButton

• text : This property is used to set the text of the JRadioButton.

• selected: if sets to true RadioButton appear selected.

• buttongroup: it specifies the name of group of buttons to which radiobutton belongs.

Commonly Used methods of RadioButton

boolean isSelected(): it returns the state of the RadioButton. “true” if selected otherwise “false”. The general syntax to use this method is as follows:

<RadioButtonname>.isSelected();

Commonly Used methods of RadioButton

void setSelected(booleanvalue): it is used to check or uncheck the RadioButton. The general syntax to use this method is as follows:

<RadioButtonname>.setSelected(booleanvalue);

Commonly Used methods of RadioButton

void setText(String)- It is used to set the text of the RadioButton with the string specified in parenthesis. The general syntax to use the setText() method is as follows:

<RadioButtonname>.setText(string);

Commonly Used methods of RadioButton

void getText()- It is used to get the text of the RadioButton. The general syntax to use getText() method is as follows

<RadioButtonname>.getText();

ScrollPane

To show any component which is bigger than display area, you can put that component in a scroll pane.

others

JOptionPane

It allows to create popup window( such as alert or message boxes or input box ) with varied content. The JOptionPane comes with some built-in styles that you can use as per your requirement.

JAVA IDE PROGRAMMING - III

List

A List( also called List box sometimes) is a box-shaped control containing a list of attributes or objects from which single or multiple selections can be made.

Commonly Used properties of List

• background: This property is used to set the background color of the List.

• enabled: This property determines whether the List is active or not.

• font: This property is used to set the font of the text that appear on the List.

• foreground: This property is used to set the color of the text that appear on the List.

Commonly Used properties of List

• model: it is the object containing the data to be exhibited by the list.

• selectedIndex: returns the index of selected item. default is -1.

• selectionMode: It describes the mode for selecting list items. It defines three modes of selection: SINGLE, SINGLE_INTERVAL, MULTIPLE_INTERVAL.

Different list selection modes

SINGLE: User can select a single item.

SINGLE_INTERVAL: User can select single range of items.

MULTIPLE_INTERVAL: User can select multiple range of items.

Commonly Used methods of List

• Object getSelectedValue() : Returns the selected value when only a single Item is selected. When multiple Items are selected, it returns the first selected value. Returns null if there is no selection.

• int getSelectedIndex() : Returns the index of selected value when only a single Item is selected. When multiple Items are selected, it returns the index of first selected value. Returns -1 if there is no selection.

ComboBox

A combobox appears as a text field along with a drop-down list arrow from which the user can choose a value. By default, the text field of a combo box is uneditable, but you can change it to be editable by setting its editable property to true. If the text field portion of the control is editable, the user can enter a value into the field or edit a value retrieved from the drop-down list.

Commonly Used properties of ComboBox

• background: This property is used to set the background color of the ComboBox.

• enabled: This property determines whether the ComboBox is active or not.

• font: This property is used to set the font of the text that appear on the ComboBox.

• foreground: This property is used to set the color of the text that appear on the ComboBox.

Commonly Used properties of ComboBox

• model: it is the object containing the data to be exhibited by the ComboBox.

• selectedIndex: returns the index of selected item. default is -1.

Commonly Used methods of ComboBox

• Object getSelectedItem() : Returns the selected item.Returns null if there is no selection.

• int getSelectedIndex() : Returns the index of selected value. Returns -1 if there is no selection.

Differences between List and ComboBox

List ComboBox

We can select multiple items.

Only a single item can be selected.

User not have the option to edit the selected item.

User can edit the selected item.

User has to select directly from the list items

User can enter a value if it is not present in set of values

It takes more space. It takes less space.

Programming Guidelines

Stylistic Guidelines

• Meaningful names for identifier.

• Ensure clarity of expression

• Use comment and indentation

• Insert blank lines and spaces

• Statement formatting Style

Preetyprinting

• When program formatting is done to make a program more readable, it is called prettyprinting.

Characteristics of a good program

• Effective and Efficient: The program produces correct result and is faster.

• User Friendly: The program should not interact with user by understandable messages and user should not be concerned about what is happening inside the program.

• Self-Documenting code:

Characteristics of a good program

• Self-Documenting code: Source code uses meaningful name for identifier to clarify the meaning of the program.

• Reliable: It must be able to handle unexpected situations like wrong data or no data.

• Platform: it should be able to run on different platforms

Stages of Program Development Process

• Crack the Problem: An algorithm is formulated which gives the solution for the problem.

• Code the algorithm: algorithm is translated into source code using some programming language.

• Compile the program: In this, source code is converted into the object code.

• Execute the program: In this, program instruction are carried out.

Robustness

The ability of a program, to recover following an error and to continue operating with its environment is called Robustness.

Guard code

The code that can handle exceptional data errors and operational errors is called Guard Code.

Exception Handling

Contradictory or Unexpected situation or unexpected error is known as Exception. Way of handling anomalous situations in a program-run, is known as Exception Handling. To control an exception, Java provides try-catch construction.

Using try and catch block

try{

tested statements;}catch(ExceptionName e){ exceptionhandling statements;}

Problem Solving Methodology

and Techniques

Steps to create a working program

• Understand the problem well: In this step you must understand the problem well so as to figure out “what it is that is to be done”.

• Analyze the problem: It involves identify the program specifications and defining each program’s minimum number of inputs, required for output and processing components

Steps to create a working program

• Design programs: In this step you are supposed to determine the logical sequence of steps to solve the given problem. Such a logical sequence of steps are called algoritm.

• Code programs: It is the step to translate the algorithm into source code using programming language.

Steps to create a working program

• Test and debug the program: Testing is the process of finding the errors in the program and debugging is the process of correcting the errors found during the testing process.

• Complete the documentation: Documentation is intended to allow another person or the programmer at later date, to understand the program.

Documentation

It refer to written description, specifications, design, code and comment, internal and external to a program, which make a program more readable, understandable and more easily modifiable.

It is of two types: 1. internal documentation: refers to comments in

the program. 2. external documentation: refers to instruction

manual

Steps to create a working program

• Understand the problem well: In this step you must understand the problem well so as to figure out “what it is that is to be done”.

• Analyze the problem: It involves identify the program specifications and defining each program’s minimum number of inputs, required for output and processing components

Steps to create a working program

• Maintain programs: Maintaining programs involves modifying the programs to remove previously undetected errors, to enhance the program with different features or functionality or keep the program up-to-date as government regulations or companies polices changes.

Type of Maintenance

• Corrective Maintenance

• Adaptive Maintenance

• Preventive Maintenance

• Perfective Maintenacne

DBMS Concepts

Database

A database may be defined as a collection of interrelated data stored together to serve multiple applications.

DBMS

A DBMS(Data Base Management System) refers to a software that is responsible for storing, maintaining and utilizing databases.

Database System

A database along with a DBMS is referred to as a database system.

Advantages of Database System

• Databases reduces the data redundancy to a large extent.

Data Redundancy

Duplication of data is known as data redundancy.

Advantages of Database System

• Databases can control data inconsistency to a large extent.

• Databases facilitate sharing of data.

• Databases enforce standards.

• Databases can ensure data security.

Data Security

It refers to the protection of data against accidental or intentional disclosure to unauthorized persons, or unauthorized modification or destruction.

Privacy of Data

It refers to the rights of individuals and organizations to determine themselves when, how, and to what extent information about them is to be transmitted to other.

Advantages of Database System

• Integrity can be maintained through databases.

Levels of Database Implementation

• Internal Level(Physical Level): It describes how the data are actually stored on the storage medium.

• Conceptual Level(Logical Level): It describes what data are actually stored in the database.

• External Level(View Level): This level is closest to the user and is concerned with the way in which data are viewed by the individual user.

Data Independence

The ability to modify the scheme definition in one level without affecting a scheme definition in next higher level is called Data Independence. Two level of data independence are:

Physical and Logical

Physical Data Independence

It refers to the ability to modify the scheme followed at the physical level without affecting the scheme at conceptual level.

Logical Data Independence

It refers to the ability to modify the scheme followed at the conceptual level without affecting the scheme at view level.

Data Model

It refers to a set of concepts to describe the structure of a database and certain constraints that the database should obey. Different data models are:

•Relational Data Model

•Hierarchical Data Model

•Network Data Model

•Object Oriented Data Model

Relational Data Model

It was propounded by E.F. Codd of the IBM.

In relational data model, the data is organized into tables(i.e. rows and columns). These tables are called relations.

Relational Data Model Terminology

View

It is a table that does not exist in its own right but is instead derived from one or more underlying base tables.

Primary Key

It is a set of one or more attributes that can uniquely identify tuples within the relation.

Candidate Key

All attribute combinations inside a relation that can serve as primary key are candidate keys.

Alternate Key

A candidate key that is not the primary key is called an alternate key.

Foreign Key

A non-key attribute, whose values are derived from the primary key of some other table, is known as Foreign-Key in the current table.

Referential Integrity

It is a system of rules that DBMS uses to ensure that relationships between records in related tables are valid, and that users don’t accidentally delete or change related data.

Introduction to MySQL

MySQL

It is freely available open source Relational Database Management System (RDBMS).

MySQL was created and is supported by MySQL, AB, a company based in Sweden (www.mysql.com). The chief inventor of MySQL was Michael Widenius. MySQL has been named after his daughter My.

Data Dictionary

It is a file that contains metadata. i.e. data about data.

Classification of SQL statements

• Data Definition Language (DDL) commands

• Data Manipulation Language (DML) commands

• Transaction Control Language (TCL) commands

• Session Control Commands

• System Control Commands

Data Definition Language (DDL) commands

It allows you to perform tasks related to data definition. You can perform tasks like:

Create, alter and drop schema objectsThis section of DDL commands is used to create or define or change or delete objects such as a table, a view, an index etc. e.g. CREATE TABLE, ALTER TABLE, DROP TABLE etc.

Data Definition Language (DDL) commands

Grant and revoke privileges and roles:

This section of DDL commands is used to grant or revoke permissions to work upon schema objects. e.g. GRANT, REVOKE etc. This section of DDL commands is also known as Data Control Language (DCL) commands

Data Definition Language (DDL) commands

Maintenance commands:

This section of DDL commands is used to analyze information on a table with an aim of maintaining it. e.g. ANALYZE TABLE, REPAIR TABLE etc.

Data Manipulation Language (DML) commands

By data manipulation, we mean : the retrieval of the information stored in

the database.the insertion of new information into the

databasethe deletion of the information from the

database.the modification of data stored in the

database.

Data Manipulation Language (DML) commands

DML is a language that enables user to access or manipulate data as organized by the appropriate data model. E.g INSERT, UPDATE, DELETE etc.

Transaction Control Language (TCL) commands

These commands manages the changes made by DML commands. E.g.

BEGIN / START TRANSACTION : It marks the beginning of a transaction.

COMMIT: It ends the current transaction by saving database changes and start new transaction.

Transaction Control Commands

ROLLBACK: It ends the current transaction by discarding database changes and start new transaction.

SAVEPOINT: It defines breakpoints for the transaction to allow partial rollbacks.

SIMPLE QUERIES IN

SQL

SQL

SQL was developed in 1970s in an IBM Laboratory. SQL sometimes also referred to as SEQUEL is 4th generation non-procedural language.

Dialogs in Java

Dialog

A dialog is a small separate sub window that appears to either provide or request information to/from the user.

Types of Dialog

• JDialog: Main dialog class (general purpose dialog)

• JOptionPane: Provides a variety of built-in dialog styles i.e. pre-defined styles.

• JFileChooser: Dialog for choosing files.

• JColorChooser: Dialog for choosing color.

Types of JOptionPane Dialog

• Input dialog: It provides some way for user to enter data. It is created

using showInputDialog method.

• Confirm dialog: It ask user to confirm some information. It is created using showConfirmDialog method.

Types of JOptionPane Dialog

• Message dialog: It simply inform the user by displaying a message. It is created using showMessageDialog method.

• Option dialog: It provides flexiblity, which you can use to create dialog as per your needs. It is created using showOptionDialog method.

Table

The jTable is a swing control that enables you to display data in a table and manipulate it in many ways. The model property of a jTable component specifies the source of data to be displayed by table.

top related