source Code Program Konversi Suhu dengan GUI java

kali membahas tentang tutorial cara membuat program konversi suhu berbasis java GUI, langkah pertama software netBeans sudah terinstall di komputer anda, selanjutnya

buat projek baru dengan cara :

  • Klik file pilih new project
  • Muncul kotak dialog pilih categori java dan pada project pilih Java Application dan next
  • ketikan nama projek dengan KonversiSuhu dan finish

Untuk  lebih mudah silahkan simak video tutorial nya :

maaf video tutorial nya masih di upload…

Berikut Source Code untuk membuat program konversi suhu dengan GUI Java

package konversisuhu;import javax.swing.JOptionPane;/**

*

* @author anas

*/

public class FrameKonversiSuhu extends javax.swing.JFrame {

public FrameKonversiSuhu() {

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() {

lCelcius = new javax.swing.JLabel();

lReamur = new javax.swing.JLabel();

tfCelcius = new javax.swing.JTextField();

tfReamur = new javax.swing.JTextField();

bKonversi = new javax.swing.JButton();

jLabel3 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle(“Konversi Suhu”);

setAlwaysOnTop(true);

setBackground(new java.awt.Color(204, 204, 204));

setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

lCelcius.setText(“Celcius”);

lReamur.setText(“Reamur”);

bKonversi.setText(“Konversi”);

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

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

bKonversiActionPerformed(evt);

}

});

jLabel3.setFont(new java.awt.Font(“Times New Roman”, 1, 18)); // NOI18N

jLabel3.setForeground(new java.awt.Color(0, 51, 204));

jLabel3.setText(“Program Konversi Suhu”);

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

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

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

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

.addGap(0, 0, Short.MAX_VALUE)

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

.addComponent(lCelcius)

.addComponent(lReamur))

.addGap(40, 40, 40)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(tfCelcius, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)

.addComponent(tfReamur))

.addGap(22, 22, 22))

.addGroup(layout.createSequentialGroup()

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

.addGroup(layout.createSequentialGroup()

.addGap(21, 21, 21)

.addComponent(jLabel3))

.addGroup(layout.createSequentialGroup()

.addGap(68, 68, 68)

.addComponent(bKonversi)))

.addContainerGap())

);

layout.setVerticalGroup(

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

.addGroup(layout.createSequentialGroup()

.addGap(20, 20, 20)

.addComponent(jLabel3)

.addGap(18, 18, 18)

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

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

.addComponent(lCelcius))

.addGap(21, 21, 21)

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

.addComponent(lReamur)

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

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)

.addComponent(bKonversi)

.addContainerGap())

);

pack();

}// </editor-fold>

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

int celcius=0;

try{

// mengambil nilai celcius

celcius = Integer.parseInt(tfCelcius.getText());

}catch(NumberFormatException e){

JOptionPane.showMessageDialog(this,”Muncul Kesalahan pada Inputan”);

return;

}

// menkonversi nilai celcius menjadi reamur

int reamur = (int)(0.8*celcius);

// memasukkan nilai reamur ke dalam tfreamur

tfReamur.setText(“”+reamur);

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

/*

* Set the Nimbus look and feel

*/

//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>

/*

* If Nimbus (introduced in Java SE 6) is not available, stay with the

* default look and feel. For details see

* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

if (“Nimbus”.equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

}

}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(FrameKonversiSuhu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FrameKonversiSuhu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FrameKonversiSuhu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FrameKonversiSuhu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

}

//</editor-fold>

/*

* Create and display the form

*/

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

public void run() {

new FrameKonversiSuhu().setVisible(true);

}

});

}

// Variables declaration – do not modify

private javax.swing.JButton bKonversi;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel lCelcius;

private javax.swing.JLabel lReamur;

private javax.swing.JTextField tfCelcius;

private javax.swing.JTextField tfReamur;

// End of variables declaration

}

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