import java.io.BufferedWriter;
import java.io.FileWriter;
import javax.swing.JOptionPane;
/*
* 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.
*/
/**
*
* @author a s u s
*/
public class tugaspemogrman extends javax.swing.JFrame {
String namalengkap,npm, grade, hasil;
double uts,tm,uas,rata;
/**
* Creates new form tugaspemogrman
*/
public tugaspemogrman() {
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() {
jPanel1 = new javax.swing.JPanel();
lblnpm = new javax.swing.JLabel();
lblnamalengkap = new javax.swing.JLabel();
txtnpm = new javax.swing.JTextField();
txtnamalengkap = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
lbluts = new javax.swing.JLabel();
lbltm = new javax.swing.JLabel();
lbluas = new javax.swing.JLabel();
txtuts = new javax.swing.JTextField();
txttm = new javax.swing.JTextField();
txtuas = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
lblnama = new javax.swing.JLabel();
lblnilairatarata = new javax.swing.JLabel();
lblgrade = new javax.swing.JLabel();
lblhasil = new javax.swing.JLabel();
txtnama = new javax.swing.JTextField();
txtnilairatarata = new javax.swing.JTextField();
txtgrade = new javax.swing.JTextField();
txthasil = new javax.swing.JTextField();
jPanel4 = new javax.swing.JPanel();
btnhitung = new javax.swing.JButton();
btnhapus = new javax.swing.JButton();
btnsimpan = new javax.swing.JButton();
btnkeluar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(102, 102, 102));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Mahasiswa"));
lblnpm.setText("NPM");
lblnamalengkap.setText("Nama Lengkap ");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblnamalengkap)
.addComponent(lblnpm))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtnpm, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
.addComponent(txtnamalengkap))
.addContainerGap(276, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblnpm)
.addComponent(txtnpm))
.addGap(18, 24, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblnamalengkap)
.addComponent(txtnamalengkap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(48, 48, 48))
);
jPanel2.setBackground(new java.awt.Color(153, 153, 153));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Nilai"));
lbluts.setText("UTS");
lbltm.setText("TM");
lbluas.setText("UAS");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbluts)
.addComponent(lbltm)
.addComponent(lbluas))
.addGap(29, 29, 29)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtuts)
.addComponent(txttm)
.addComponent(txtuas, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
.addGap(0, 27, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbluts)
.addComponent(txtuts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbltm)
.addComponent(txttm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbluas)
.addComponent(txtuas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3.setBackground(new java.awt.Color(102, 102, 102));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Hasil"));
lblnama.setText("NAMA :");
lblnilairatarata.setText("NILAI Rata-Rata");
lblgrade.setText("GRADE");
lblhasil.setText("HASIL");
txtnama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtnamaActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(lblnilairatarata)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtnilairatarata))
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblgrade)
.addGap(53, 53, 53)
.addComponent(txtgrade))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(0, 13, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(lblnama)
.addGap(49, 49, 49)
.addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(lblhasil)
.addGap(54, 54, 54)
.addComponent(txthasil, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGap(33, 33, 33))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblnama)
.addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblnilairatarata)
.addComponent(txtnilairatarata, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblgrade)
.addComponent(txtgrade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblhasil)
.addComponent(txthasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(13, Short.MAX_VALUE))
);
jPanel4.setBackground(new java.awt.Color(153, 153, 153));
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Hasil Akhir"));
btnhitung.setText("Hitung");
btnhitung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhitungActionPerformed(evt);
}
});
btnhapus.setText("Hapus");
btnhapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnhapusActionPerformed(evt);
}
});
btnsimpan.setText("Simpan");
btnsimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsimpanActionPerformed(evt);
}
});
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(btnhitung, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnhapus, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addComponent(btnsimpan, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(btnkeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnhitung)
.addComponent(btnhapus)
.addComponent(btnsimpan)
.addComponent(btnkeluar))
.addContainerGap(45, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jPanel4, 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();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void btnhitungActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnhitungActionPerformed
npm = String.valueOf(txtnpm.getText());
namalengkap = String.valueOf(txtnamalengkap.getText());
uts = Double.parseDouble(txtuts.getText());
uas = Double.parseDouble(txtuas.getText());
tm = Double.parseDouble(txttm.getText());
rata = (uts + tm + uas) /3;
if(rata >=90){
grade = "A";
hasil = "Lulus";
} else if(rata >=80){
grade = "B";
hasil = "Lulus dengan nilai B";
} else if(rata >=70){
grade = "C";
hasil = "Lulus dengan nilai C";
} else if(rata >=60){
grade = "D";
hasil = "Lulus Bersyarat";
} else {
grade = "E";
hasil = "Tidak Lulus";}
txtnama.setText(""+namalengkap);
txtnilairatarata.setText(""+rata);
txtgrade.setText(""+grade);
txthasil.setText(""+hasil);
}//GEN-LAST:event_btnhitungActionPerformed
private void txtnamaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnamaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtnamaActionPerformed
private void btnsimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsimpanActionPerformed
String nama = txtnama.getText();
String rata = txtnilairatarata.getText();
String grade = txtgrade.getText();
String hasil = txthasil.getText();
try{
FileWriter writer = new FileWriter("rata.txt", true);
writer.write(nama);
writer.write(System.getProperty("line.separator"));
writer.write(rata);
writer.write(System.getProperty("line.separator"));
writer.write(grade);
writer.write(System.getProperty("line.separator"));
writer.write(hasil);
writer.write(System.getProperty("line.separator"));
writer.close();
JOptionPane.showMessageDialog(null, "Berhasil Di Simpan Filenya");
}catch (Exception e) {
System.err.println("Error"+e.getMessage()) ;
}
}//GEN-LAST:event_btnsimpanActionPerformed
private void btnhapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnhapusActionPerformed
txtnamalengkap.setText(null);
txtnpm.setText(null);
txtuts.setText(null);
txttm.setText(null);
txtuas.setText(null);
txtnama.setText(null);
txtnilairatarata.setText(null);
txthasil.setText(null);
txtgrade.setText(null);
txtnamalengkap.requestFocus();
// TODO add your handling code here:
}//GEN-LAST:event_btnhapusActionPerformed
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnkeluarActionPerformed
System.exit(0);
}//GEN-LAST:event_btnkeluarActionPerformed
/**
* @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(tugaspemogrman.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(tugaspemogrman.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(tugaspemogrman.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(tugaspemogrman.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 tugaspemogrman().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnhapus;
private javax.swing.JButton btnhitung;
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnsimpan;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JLabel lblgrade;
private javax.swing.JLabel lblhasil;
private javax.swing.JLabel lblnama;
private javax.swing.JLabel lblnamalengkap;
private javax.swing.JLabel lblnilairatarata;
private javax.swing.JLabel lblnpm;
private javax.swing.JLabel lbltm;
private javax.swing.JLabel lbluas;
private javax.swing.JLabel lbluts;
private javax.swing.JTextField txtgrade;
private javax.swing.JTextField txthasil;
private javax.swing.JTextField txtnama;
private javax.swing.JTextField txtnamalengkap;
private javax.swing.JTextField txtnilairatarata;
private javax.swing.JTextField txtnpm;
private javax.swing.JTextField txttm;
private javax.swing.JTextField txtuas;
private javax.swing.JTextField txtuts;
// End of variables declaration//GEN-END:variables
}
0 Comments
Silahkan berkomentar
EmoticonEmoticon