3. WHAT IS GUI?
• A graphical user interface (GUI) is a human-computer interface (i.e., a
way for humans to interact with computers) that uses windows, icons
and menus and which can be manipulated by a mouse and to some
extent using keyboard.
• A major advantage of GUIs is that they make computer operation
easier to learn and use. For example, it is much easier for a new user
to move a file from one directory to another by dragging its icon with
the mouse than by having to remember and type many commands to
accomplish the same task.
4. GUI Programming
• Uses a simplified approach to programming.
• Most of the components are predefined in a generic way.
• Can be incorporated according to the needs or requirements of
the application.
• It provides a very comfortable feel to the programmer to
develop applications without getting into complicated and
cumbersome logic and commands.
• Most of the GUI tools are developed
To provide simplified approach to programming.
To provide enormous inbuilt functionality to the programmer.
6. 1. Understand the need of the application
before starting the development.
Eg: Fahrenheit Conversion Application
Why we need it, its advantages?
•
•
For the easy conversion of values without doing it
manually.
Time saving, any one can access the application and use
it, user friendly etc.
7. 2. Find out all possible inputs, which are
required to produce the desired result
or results.
E.g. Fahrenheit Conversion Application
•
•
Both decimal values as well as integer values as input.
Allow only numeric values as input
8. 3.
Make sure that the user provides appropriate
information with minimum efforts to avoid
ambiguity in data.
•
•
•
Appropriately deciding on the various input components
Maximize use of radio button, checkbox, combo box, and list.
Wherever possible avoid use of text field and text area for accepting
inputs from the user to reduce ambiguity.
9. E.g. While inputting Marital status in a form
using TEXT FIELD (values are given according to user)
Restrict the user by using COMBOBOX:
(Reduce the no: of options to the user)
10. 4.
Radio Button should be used wherever one of the option out of
limited number of options are required to be taken from the user.
For example,
For accepting gender (Male or Female)
For marital status (Single or Married)
For Membership type(Monthly , Annual, Life Time)
11. 5. Checkbox should be used wherever multiple
options are required to be selected from a limited number of known set
of options.
For example,
For accepting multiple hobbies (Swimming, Singing,
Dancing, Debating)
12. 6.
Combo box should be used wherever only one of the option from a
large number of known set of options is required to be taken from
the user
For example,
For selecting marital status
13. 7.
List should be used wherever multiple options are required to be
selected from a large number of known set of options.
For example,
For selecting activities
14. List and Combo box
8.
It is advisable to use List and Combo box when there are too
many options as they help save space and are less cumbersome to
design as compared to radio button and checkbox.
9.
Options in a list or a combo box may be
displayed in alphabetical order so that it is easier
for the user to locate the appropriate option or
may be displayed according to the probability of
choice. The most probable answer should be at
the top.
15. For example,
To take input of name of a state
• The names should be displayed according to alphabetical order.
To take input of employee designation
• The highest level should be put at last and the lowest level should be
put at top.
The explanation for this is since there are more
employees at lower levels as compared to higher
levels, the probability of choosing the lower level
is more.
16. 10.
It is advisable to use appropriate labels for each input and output
options to help the user to correctly interpret them.
For example,
User has to input user id and password
17. 11.
While writing the code do not use variable names as A, B, C etc.
Instead use meaningful names and follow naming conventions. All the
variables and constants must be named according to the naming
conventions. They make the code easier to read, understand and
maintain.
For example,
A variable storing total marks – Total
A variable holding cost price - CP
18. 12. Ensure Clarity of expressions. All the expressions should be easy to
understand for the user. There should not be a compromise to reduce
the statements by loosing their clarity.
For example,
double farenconv;
farenconv=9/5*(jTextfeild1.getText()+32);
This can be rewritten as:
double farenconv, Tc;
Tc=Integer.parseInt(jTextfeild1.getText());
farenconv=(9/5)*(Tc+32);
19. Control Structures
13.
The conditional construct if..else should be preferred when there
are very few alternative execution paths to choose from and also when
decisions are to be made based on ranges of values or conditions. For
example, to show gender
based title etc.
For example,
20. Control Structures
13. The conditional construct if..else should be preferred when there are very
few alternative execution paths to choose from and also when decisions are
to be made based on ranges of values or conditions.
For example, to show gender based title etc.
14. The switch construct should be used when there are too many alternative
execution paths and decisions is based only on a single integer or countable
value.
For example, to show weekday based message etc.
15. For repeating code a known number of times, the for loop is the best choice
and when the number of iterations is not preknown, use the while or the
do..while loop. When you want to test a condition at the end of the loop to
see whether some block should be repeated, the do..while statement should
be preferred.
For example,
• To sum 10 numbers for loop can be used
• To accept password, the do..while is the best.
21. 16. Use appropriate comments.
Comments are very essential.
• It provides internal documentation of a program.
• It can be used to explain the various complicated steps of the program
thereby making the program more understandable for the user.
In Java single line comments begin with // and multiple lines of
comments are enclosed between /* and */ .
For example,
int length, breadth, area;
length=Integer.parseInt(jTextField1.getText());
//length variable accepting the value from jtextfield1
breadth=Integer.parseInt(jTextField2.getText());
//breadth variable accepting the value from jtextfield2
int area=length * breadth // area is calculated and stored in the variable area.
/* to display the area using a JOptionPane
the code is as follows */
JOptionPane.showMessageDialog(this, area);
22. 17. Insert blank lines and blank spaces where necessary to separate logical
group of statements.
18. Proper indentation must be used to highlight nesting of constructs like
if, select or loops.
19. Avoid using Free formatting styles. it makes program less readable and
difficult to debug. Pretty printing should be encouraged.
• We can type any number of statements in the same line separated by a;
(semi colon). This is called free formatting style.
int length,breadth,area;length=Integer.parseInt(jTextField1.getText());breadth=Integer.parseInt(jTextField2.getText());
•
•
Prettyprinting is the formatting of a program to make it more readable.
These formatting consist of
Changes in positioning, spacing, color, contrast, size and similar modifications
To make the content easier to view, read and understand.
Also called as code beautifiers or syntax highlighters.
The shortcut is Alt + Shift+ F.
int length , breadth, area;
length=Integer.parseInt(jTextField1.getText());
breadth=Integer.parseInt(jTextField2.getText());
23. 20. The application must be reliable. It must be capable of
handling situations like wrong input or no input. It should
display proper error messages in case of such errors.
if (English>100 || ASkills>100 || GK>100)
JOptionPane.showMessageDialog(this,"Re-Enter Marks (Out of 100)");
Check if the marks input by the user for any of the subjects are greater
than 100 or not an if they are then display the message
"Re-Enter Marks (Out of 100)”
21. The application should be portable. It should be able to run
on different platforms.
From System to System , In different Operating systems.