You are on page 1of 6

IT12-IntProg (Intermediate of Programming)

PAMBAYANG DALUBHASAAN NG MARILAO


College of Computer Studies

I. INTRODUCTION
GUI (Graphical User Interface) in Java is an easy-
to-use visual experience builder
for Java applications. It is mainly made of
graphical components like buttons, labels,
windows, etc. through which the user can
Module 9 interact with an application. GUI plays an
important role to build easy interfaces
for Java applications.
DESIGNING GRAPHICAL
II. OBJECTIVES
USER INTERFACE IN JAVA 1. Design and develop a graphical user
Additional Learning Material interface using classes from the javax.swing
package
2. Apply the general concepts of Swing classes
3. Distinguish the different layout managers
4. Design and develop a Java application using
frame, panel, labels, text fields, buttons,
radio buttons, check boxes, and events
5. Create a Java program using combo box and
list box

***This learning material contains instructions how to create a Java-GUI application.

Page 1 of 6
IT12-IntProg (Intermediate of Programming)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
Creating a Java project and GUI application.

1. Create New Project. Select Java with Ant under Categories and Java Application under Projects.
Click Next.

2. Assign the project name. Uncheck Create Main Class. Click Finish.

Page 2 of 6
IT12-IntProg (Intermediate of Programming)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

3. To add a frame, click New File icon. Under Categories, choose Swing GUI Forms. Under File
Types, choose JFrame Form. Click Next.

4. Assign the class name. Double check if appropriate project is selected. Click Finish.

Page 3 of 6
IT12-IntProg (Intermediate of Programming)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
5. At the center of the NetBeans environment is your work area. Choose the containers, controls,
and other components from the Palette window and drag the components to the frame.

Example #1:

Design

Page 4 of 6
IT12-IntProg (Intermediate of Programming)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies
Source

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
double prelim, midterm,finals, average=0;
prelim = Double.parseDouble(tfPrelim.getText());
midterm = Double.parseDouble(tfMidterm.getText());
finals = Double.parseDouble(tfFinals.getText());
average = (prelim + midterm + finals)/3;

lbAverage.setText(Double.toString(average));

if (average <= 74)


lbFinalGrade.setText("5.0");
else if (average <= 76)
lbFinalGrade.setText("3.0");
else if (average <= 79)
lbFinalGrade.setText("2.75");
else if (average<= 82)
lbFinalGrade.setText("2.50");
else if (average <= 85)
lbFinalGrade.setText("2.25");
else if (average <= 88)
lbFinalGrade.setText("2.0");
else if (average <= 91)
lbFinalGrade.setText("1.75");
else if (average <= 94)
lbFinalGrade.setText("1.50");
else if (average <= 97)
lbFinalGrade.setText("1.25");
else if (average <=100)
lbFinalGrade.setText("1.0");
else
lbFinalGrade.setText("Invalid!");

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
tfPrelim.setText("");
tfMidterm.setText("");
tfFinals.setText("");
lbAverage.setText("");
}

Page 5 of 6
IT12-IntProg (Intermediate of Programming)
PAMBAYANG DALUBHASAAN NG MARILAO
College of Computer Studies

Example #2:

Design

Source
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfMidterm.setText("");
tfFinals.setText("");
lbMidterm.setText("");
lbFinal.setText("");
tfFinalGrade.setText("");
}

private void btnComputeActionPerformed(java.awt.event.ActionEvent evt) {


double midtermGrade=0, finalsGrade=0, fg=0;
double midterm = Double.parseDouble(tfMidterm.getText());
double finals = Double.parseDouble(tfFinals.getText());
midtermGrade = midterm * .50;
finalsGrade = finals *.50;
fg = midtermGrade + finalsGrade;

lbMidterm.setText(Double.toString(midtermGrade));
lbFinal.setText(Double.toString(finalsGrade));
tfFinalGrade.setText(Double.toString(fg));

Page 6 of 6

You might also like