Seiring dengan perkembangan ilmu pengetahuan dan teknologi, saat ini tidak sedikit penyedia jasa yang menawarkan layanan kursus programming. Namun bagi yang ingin belajar sendiri, telah banyak tutorial belajar pemrograman (programming) di internet, salah satunya dalam artikel ini.
Tutorial Belajar Pemrograman Java NetBeans Pemula
Berikut ini ialah video tutorial membuat GUI application Java NetBeans untuk program converter suhu sederhana.
Sementara untuk source code program yang dapat digunakan sebagai berikut.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package AppPackage;
/**
*
* @author El
*/
public class celsiusConverter extends javax.swing.JFrame {
double celsius, fahrenheit,rheamur, kelvin;
/**
* Creates new form celsiusConverter
*/
public celsiusConverter() {
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">//GEN-BEGIN:initComponents
private void initComponents() {
cTextField = new javax.swing.JTextField();
fTextField = new javax.swing.JTextField();
rTextField = new javax.swing.JTextField();
kTextField = new javax.swing.JTextField();
convertButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Celsius Converter");
cTextField.setText("0");
fTextField.setEnabled(false);
rTextField.setEnabled(false);
kTextField.setEnabled(false);
convertButton.setText("Convert");
convertButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
convertButtonActionPerformed(evt);
}
});
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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(kTextField)
.addComponent(rTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(convertButton)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(convertButton))
.addGap(7, 7, 7)
.addComponent(fTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(kTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
String inputC;
inputC = cTextField.getText();
celsius = Double.parseDouble(inputC);
fahrenheit = celsius * 1.8 + 32;
rheamur = celsius * 0.8;
kelvin = celsius + 273;
String cTemp = Double.toString(celsius);
String fTemp = Double.toString(fahrenheit);
String rTemp = Double.toString(rheamur);
String kTemp = Double.toString(kelvin);
cTextField.setText(cTemp);
fTextField.setText(fTemp + " F");
rTextField.setText(rTemp + " R");
kTextField.setText(kTemp + " K");// TODO add your handling code here:
}//GEN-LAST:event_convertButtonActionPerformed
/**
* @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(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.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 celsiusConverter().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField cTextField;
private javax.swing.JButton convertButton;
private javax.swing.JTextField fTextField;
private javax.swing.JTextField kTextField;
private javax.swing.JTextField rTextField;
// End of variables declaration//GEN-END:variables
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package AppPackage;
/**
*
* @author El
*/
public class celsiusConverter extends javax.swing.JFrame {
double celsius, fahrenheit,rheamur, kelvin;
/**
* Creates new form celsiusConverter
*/
public celsiusConverter() {
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">//GEN-BEGIN:initComponents
private void initComponents() {
cTextField = new javax.swing.JTextField();
fTextField = new javax.swing.JTextField();
rTextField = new javax.swing.JTextField();
kTextField = new javax.swing.JTextField();
convertButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Celsius Converter");
cTextField.setText("0");
fTextField.setEnabled(false);
rTextField.setEnabled(false);
kTextField.setEnabled(false);
convertButton.setText("Convert");
convertButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
convertButtonActionPerformed(evt);
}
});
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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(kTextField)
.addComponent(rTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(convertButton)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(convertButton))
.addGap(7, 7, 7)
.addComponent(fTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(kTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
String inputC;
inputC = cTextField.getText();
celsius = Double.parseDouble(inputC);
fahrenheit = celsius * 1.8 + 32;
rheamur = celsius * 0.8;
kelvin = celsius + 273;
String cTemp = Double.toString(celsius);
String fTemp = Double.toString(fahrenheit);
String rTemp = Double.toString(rheamur);
String kTemp = Double.toString(kelvin);
cTextField.setText(cTemp);
fTextField.setText(fTemp + " F");
rTextField.setText(rTemp + " R");
kTextField.setText(kTemp + " K");// TODO add your handling code here:
}//GEN-LAST:event_convertButtonActionPerformed
/**
* @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(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(celsiusConverter.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 celsiusConverter().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField cTextField;
private javax.swing.JButton convertButton;
private javax.swing.JTextField fTextField;
private javax.swing.JTextField kTextField;
private javax.swing.JTextField rTextField;
// End of variables declaration//GEN-END:variables
}
Data input suhu dalam skala celsius akan diolah menjadi output skala fahrenheit, rheamur, dan kelvin. Untuk tampilan GUI ini sendiri tampak pada gambar berikut.
Sedangkan untuk component yang digunakan ialah sebagai berikut.
Berikut adalah link untuk download source code dan juga program Java NetBeans converter suhu sederhana.