Senin, 08 Juni 2015

Modul 8 Praktikum Object Oriented Programming



MODUL 8
JAVA SWING

A.   Objective
To understand how was java swing run.

B.   Basic Theory
          Swing is an other alternative to implement window program. Although implemented based on AWT class, swing not use components in AWT, so the components display in the swing not depend on system window local. So the graphic display from swing to all of operation system become similar.
C.   Tools and Materials
·        Laptop
·        NetBeans Software
·        Java Development Kit (JDK)
D.   Steps

1.       Open netbeans
2.       Right click project and make new jFrame Form
3.       Next, add jPanel component in form that has made
4.       Add the menus component and change the name become “Ubah Warna”
5.       Next, give an item component menu in menu, so after menu clicked then shown dropdown menu


6.     In the inspector panel, choose one of item menu that will given an action, so when the menu clicked, the window background color will change.
Right click on item menu - choose even – actionPerformed
7.     Add code below under the actionPerformed
jPanel1.setBackground(Color.red);
jLabel1.setText(“Warna Background Merah”);

the code:

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        jPanel1.setBackground(Color.red);
        jLabel1.setText("Warna Background Merah");
    }                                         

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        jPanel1.setBackground(Color.green);
        jLabel1.setText("Warna Background Hijau");
    }                                         

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        jPanel1.setBackground(Color.yellow);
        jLabel1.setText("Warna Background Kuning");
    }                                         

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        jPanel1.setBackground(Color.MAGENTA);
        jLabel1.setText("Warna Background Magenta");
    }                                         

8.     That following code will change background color become red and in the middle of window will shown “Warna Background Merah”

 Exercises
1.     Add another color, green and yellow.
    



2.     Add the icon next to the item menu


Tidak ada komentar:

Posting Komentar