Java GUI – Menghitung Nilai Mahasiswa

Malam blogger, akhir-akhir ini semakin banyak tugas yang saya dapatkan dari dosen. Sehingga sedikit waktu saya untuk mengurus blog. Apalagi UTS sudah sangat dekat. Saya hanya berusaha memberikan posting artikel setiap harinya agar lebih banyak bahan yang bisa dibaca pengunjung. Nah, kali ini saya akan membagikan sebuah program yang berhubungan dengan mahasiswa.  Program ini adalah untuk menghitung nilai mahasiswa, yang terdiri dari nilai UAS, UTS dan nilai harian.

langkah pertama adalah membuat form, seperti gambar berikut :  :)



Listing Program :

import javax.swing.JOptionPane;

/**
 *
 * @author Ade
 */
public class ProgramGUI extends javax.swing.JFrame {

/** Creates new form ProgramGUI */
 public ProgramGUI() {
 super("PROGRAM NILAI MAHASISWA");
 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() {

jTextField1 = new javax.swing.JTextField();
 jButton1 = new javax.swing.JButton();
 jButton3 = new javax.swing.JButton();
 jPanel2 = new javax.swing.JPanel();
 jPanel1 = new javax.swing.JPanel();
 jLabel1 = new javax.swing.JLabel();
 jTextField2 = new javax.swing.JTextField();
 jLabel2 = new javax.swing.JLabel();
 jLabel3 = new javax.swing.JLabel();
 jTextField3 = new javax.swing.JTextField();
 jTextField4 = new javax.swing.JTextField();
 jLabel4 = new javax.swing.JLabel();
 jLabel5 = new javax.swing.JLabel();
 jLabel6 = new javax.swing.JLabel();
 jTextField5 = new javax.swing.JTextField();
 jTextField6 = new javax.swing.JTextField();
 jButton2 = new javax.swing.JButton();
 jLabel7 = new javax.swing.JLabel();
 jTextField7 = new javax.swing.JTextField();
 jTextField8 = new javax.swing.JTextField();
 jTextField9 = new javax.swing.JTextField();
 jLabel8 = new javax.swing.JLabel();
 jLabel9 = new javax.swing.JLabel();
 jLabel10 = new javax.swing.JLabel();
 jLabel11 = new javax.swing.JLabel();
 jButton4 = new javax.swing.JButton();
 jButton5 = new javax.swing.JButton();

jTextField1.setText("jTextField1");

jButton1.setText("jButton1");

jButton3.setText("jButton3");

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
 jPanel2.setLayout(jPanel2Layout);
 jPanel2Layout.setHorizontalGroup(
 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGap(0, 100, Short.MAX_VALUE)
 );
 jPanel2Layout.setVerticalGroup(
 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGap(0, 100, Short.MAX_VALUE)
 );

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12)); // NOI18N
 jLabel1.setText("Nama Mahasiswa");

jLabel2.setText("jLabel2");

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 jLabel3.setText("Input Nilai :");

jTextField3.setText("jTextField3");

jTextField4.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jTextField4ActionPerformed(evt);
 }
 });

jLabel4.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
 jLabel4.setText("Nilai UTS");

jLabel5.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
 jLabel5.setText("Nilai UAS");

jLabel6.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
 jLabel6.setText("Nilai Harian");

jButton2.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
 jButton2.setText("Proses");
 jButton2.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton2ActionPerformed(evt);
 }
 });

jLabel7.setFont(new java.awt.Font("Rockwell Extra Bold", 1, 14)); // NOI18N
 jLabel7.setText("PROGRAM APLIKASI NILAI MAHASISWA");

jTextField7.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jTextField7ActionPerformed(evt);
 }
 });

jLabel8.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12)); // NOI18N
 jLabel8.setText("Nama Mahasiswa");

jLabel9.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
 jLabel9.setText("Nilai Rata-rata");

jLabel10.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
 jLabel10.setText("Grade");

jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 jLabel11.setText("Output :");

jButton4.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
 jButton4.setText("Keluar");
 jButton4.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton4ActionPerformed(evt);
 }
 });

jButton5.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
 jButton5.setText("Bersihkan");
 jButton5.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton5ActionPerformed(evt);
 }
 });

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
 jPanel1.setLayout(jPanel1Layout);
 jPanel1Layout.setHorizontalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addGap(19, 19, 19)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 .addComponent(jLabel10)
 .addComponent(jLabel9)
 .addComponent(jLabel4)
 .addComponent(jLabel1)
 .addComponent(jLabel5)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addComponent(jLabel11)
 .addGap(18, 18, 18)
 .addComponent(jLabel6))
 .addComponent(jLabel8))
 .addComponent(jLabel3))
 .addGap(18, 18, 18)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addGap(18, 18, 18)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
 .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
 .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jLabel7)))
 .addGap(39, 39, 39))
 );
 jPanel1Layout.setVerticalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jLabel7)
 .addGap(23, 23, 23)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel1)
 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addGap(18, 18, 18)
 .addComponent(jLabel3))
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addGap(32, 32, 32)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel4)
 .addComponent(jButton2))))
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel5)
 .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jButton5))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel6)
 .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addComponent(jButton4))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE))
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jLabel11)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel8))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel9))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel10))
 .addContainerGap())
 );

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()
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addContainerGap(14, Short.MAX_VALUE))
 );
 layout.setVerticalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addContainerGap(17, Short.MAX_VALUE))
 );

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

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
 int UTS = Integer.parseInt(jTextField4.getText());
 int UAS = Integer.parseInt(jTextField5.getText());
 int NH = Integer.parseInt(jTextField6.getText());
 int hasil = (UTS + UAS + NH) / 3;
 jTextField7.setText(jTextField2.getText());
 jTextField8.setText(String.valueOf(hasil));
 jTextField9.setText(null);
 if (hasil > 81 && hasil < 100) {
 jTextField9.setText("A");
 } else if (hasil > 70) {
 jTextField9.setText("B");
 } else if (hasil > 60) {
 jTextField9.setText("C");
 } else if (hasil > 50) {
 jTextField9.setText("D");
 }

}

private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
 int mesage = JOptionPane.showConfirmDialog(null, "Apakah Yakin Keluar");
 if (mesage == JOptionPane.OK_OPTION) {
 System.exit(1);
 }

}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
 jTextField2.setText(null);
 jTextField4.setText(null);
 jTextField5.setText(null);
 jTextField6.setText(null);
 jTextField7.setText(null);
 jTextField8.setText(null);
 jTextField9.setText(null);
}

/**
 * @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(ProgramGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (InstantiationException ex) {
 java.util.logging.Logger.getLogger(ProgramGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (IllegalAccessException ex) {
 java.util.logging.Logger.getLogger(ProgramGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
 java.util.logging.Logger.getLogger(ProgramGUI.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 ProgramGUI().setVisible(true);
 }
 });
 }
 // Variables declaration - do not modify
 private javax.swing.JButton jButton1;
 private javax.swing.JButton jButton2;
 private javax.swing.JButton jButton3;
 private javax.swing.JButton jButton4;
 private javax.swing.JButton jButton5;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel10;
 private javax.swing.JLabel jLabel11;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JLabel jLabel7;
 private javax.swing.JLabel jLabel8;
 private javax.swing.JLabel jLabel9;
 private javax.swing.JPanel jPanel1;
 private javax.swing.JPanel jPanel2;
 private javax.swing.JTextField jTextField1;
 private javax.swing.JTextField jTextField2;
 private javax.swing.JTextField jTextField3;
 private javax.swing.JTextField jTextField4;
 private javax.swing.JTextField jTextField5;
 private javax.swing.JTextField jTextField6;
 private javax.swing.JTextField jTextField7;
 private javax.swing.JTextField jTextField8;
 private javax.swing.JTextField jTextField9;
 // End of variables declaration
}

Output Progam :

Tampilan program ketiaja di run

About Ade Akbar

Hidup, Berarti dan Mati

Posted on Desember 8, 2011, in Program Java. Bookmark the permalink. Tinggalkan komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: