Program Sederhana (Luas segitiga) dengan JAVA 6 SE

Posted on


Ketikkan program berikut

package com.wordpress.hasim319.luassegitiga;

/**

* @author M Hasyim

*/

public class mainForm extends javax.swing.JFrame {

/** konstruktor */

public mainForm() {

initComponents();

}

@SuppressWarnings(“unchecked”)

// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>

private void initComponents() {

panel = new usu.widget.glass.PanelGlassStyle();

lbAlas = new usu.widget.Label();

lbTinggi = new usu.widget.Label();

txtTinggi = new usu.widget.glass.TextBoxGlass();

tmbHitung = new usu.widget.ButtonGlass();

txtLuas = new usu.widget.glass.TextBoxGlass();

txtAlas = new usu.widget.glass.TextBoxGlass();

lbLuas = new usu.widget.Label();

tmbKosongkan = new usu.widget.ButtonGlass();

lbJudul = new usu.widget.Label();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle(“By : Hasyim”);

setResizable(false);

panel.setBackground(new java.awt.Color(0, 0, 255));

lbAlas.setForeground(new java.awt.Color(255, 255, 255));

lbAlas.setText(“Alas”);

lbAlas.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N

lbTinggi.setForeground(new java.awt.Color(255, 255, 255));

lbTinggi.setText(“Tinggi”);

lbTinggi.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N

txtTinggi.setForeground(new java.awt.Color(255, 255, 51));

txtTinggi.setToolTipText(“Masukkan nilai tinggi”);

txtTinggi.setCaretColor(new java.awt.Color(51, 255, 51));

txtTinggi.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N

tmbHitung.setForeground(new java.awt.Color(102, 255, 51));

tmbHitung.setText(“Hitung”);

tmbHitung.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N

tmbHitung.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

tmbHitungActionPerformed(evt);

}

});

txtLuas.setEditable(false);

txtLuas.setForeground(new java.awt.Color(102, 255, 102));

txtLuas.setToolTipText(“Nilai Luas”);

txtLuas.setCaretColor(new java.awt.Color(51, 255, 51));

txtLuas.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N

txtAlas.setForeground(new java.awt.Color(255, 255, 51));

txtAlas.setToolTipText(“Masukkan nilai alas”);

txtAlas.setCaretColor(new java.awt.Color(51, 255, 51));

txtAlas.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N

lbLuas.setForeground(new java.awt.Color(255, 255, 255));

lbLuas.setText(“Luas”);

lbLuas.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N

tmbKosongkan.setForeground(new java.awt.Color(102, 255, 51));

tmbKosongkan.setText(“Kosongkan”);

tmbKosongkan.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N

tmbKosongkan.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

tmbKosongkanActionPerformed(evt);

}

});

lbJudul.setForeground(new java.awt.Color(255, 255, 204));

lbJudul.setText(“Program Luas Segitiga”);

lbJudul.setFont(new java.awt.Font(“Tahoma”, 1, 24)); // NOI18N

javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);

panel.setLayout(panelLayout);

panelLayout.setHorizontalGroup(

panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(panelLayout.createSequentialGroup()

.addContainerGap()

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(panelLayout.createSequentialGroup()

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(lbAlas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(lbTinggi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(lbLuas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(48, 48, 48)

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(panelLayout.createSequentialGroup()

.addGap(8, 8, 8)

.addComponent(tmbHitung, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(tmbKosongkan, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))

.addComponent(txtAlas, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)

.addComponent(txtTinggi, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)

.addComponent(txtLuas, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))

.addContainerGap())

.addGroup(panelLayout.createSequentialGroup()

.addComponent(lbJudul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(61, Short.MAX_VALUE))))

);

panelLayout.setVerticalGroup(

panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()

.addComponent(lbJudul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(lbAlas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtAlas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(txtTinggi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(lbTinggi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(lbLuas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtLuas, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(tmbKosongkan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(tmbHitung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(23, Short.MAX_VALUE))

);

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

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

pack();

}// </editor-fold>

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

// TODO add your handling code here:

txtAlas.setText(“”);

txtTinggi.setText(“”);

txtLuas.setText(“”);

}

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

// TODO add your handling code here:

int alas, tinggi, luas; // deklarasi

try{

// menentukan nilai

alas = Integer.parseInt(txtAlas.getText());

tinggi = Integer.parseInt(txtTinggi.getText());

// menghitung luas

luas = (alas * tinggi) / 2;

txtLuas.setText(luas + “”);

}catch(Exception ex){}

}

// method main

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new mainForm().setVisible(true);

}

});

}

// Variables declaration – do not modify

private usu.widget.Label lbAlas;

private usu.widget.Label lbJudul;

private usu.widget.Label lbLuas;

private usu.widget.Label lbTinggi;

private usu.widget.glass.PanelGlassStyle panel;

private usu.widget.ButtonGlass tmbHitung;

private usu.widget.ButtonGlass tmbKosongkan;

private usu.widget.glass.TextBoxGlass txtAlas;

private usu.widget.glass.TextBoxGlass txtLuas;

private usu.widget.glass.TextBoxGlass txtTinggi;

// End of variables declaration

}

Download program. Klik disini

2 thoughts on “Program Sederhana (Luas segitiga) dengan JAVA 6 SE

    Thomas said:
    12 April 2010 at 12:22 pm

    Cool…berbagi membuat diri semakin kaya.
    salam

    good said:
    16 July 2010 at 1:42 pm

    mantab………kren mas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s