You are on page 1of 6

Modul 1:

Tujuan : Mengenal Java Net Beans

Java 2 di bagi atas tiga paket, yaitu :


1.J2EE ( Java 2 Enterprise Edition ) : digunakan untuk aplikasi server atau aplikasi web server.
2.J2SE ( Java 2 Standard Edition ) : digunakan untuk aplikasi desktop.
3.J2ME ( Java 2 Micro Edition ) : digunakan untuk aplikasi wireless device atau mobile device.

Instalasi NetBeans:

Membuat dan Penyimpan Project:


1.Buat Folder untuk Project dengan nama : java1
2.Buat Project.

3.Pilih Java Application

4.Nama Project : Modul 1 dan Folder : Java1

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |1
5.Komponen GUI ( AWT dan SWING ):

6.Membuat Desain Form Hello Word by Java:

7.Code Form Hello Word:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* java_frame.java
*
* Created on Jun 15, 2009, 3:12:13 PM
Write Once, Run Everywhere
Rahmadi, S.E, S.Kom
Page |2
*/
//import komponen java awt untuk perataan form center
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
/**
*
* @author Acer
* */
public class java_frame extends javax.swing.JFrame {
/** Creates new form java_frame */
public java_frame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jDialog1 = new javax.swing.JDialog();
lbl_helloswing = new javax.swing.JLabel();
btn_helloswing = new javax.swing.JButton();

javax.swing.GroupLayout jDialog1Layout = new


javax.swing.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Form Hello Word...!");
setAlwaysOnTop(true);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |3
lbl_helloswing.setBackground(new java.awt.Color(0, 255, 255));
lbl_helloswing.setFont(new java.awt.Font("Arial Black", 3, 48)); // NOI18N
lbl_helloswing.setForeground(new java.awt.Color(0, 0, 255));
lbl_helloswing.setText("Klik Button di Bawah..!");

btn_helloswing.setFont(new java.awt.Font("Algerian", 3, 24)); // NOI18N


btn_helloswing.setText("Hello Swing");
btn_helloswing.setToolTipText("Button Hello Swing");
btn_helloswing.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_helloswingMouseClicked(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
btn_helloswingMouseExited(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl_helloswing)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btn_helloswing)))
.addContainerGap(83, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lbl_helloswing)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_helloswing)
.addContainerGap(174, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void btn_helloswingMouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
lbl_helloswing.setText("Hello Swing");
}

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |4
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
lbl_helloswing.setText("Hello Word");
// Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2));
}

private void btn_helloswingMouseExited(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
lbl_helloswing.setText("Hello Word");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new java_frame().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton btn_helloswing;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel lbl_helloswing;
// End of variables declaration

8.Hasil berupa file Execuble Jar File:

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |5
9.Implementation:

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |6

You might also like