You are on page 1of 7

LAPORAN

PROJEK-1
Pertemuan Ke – 2

Disusun Oleh :
NAMA : FANI ANGGITA
NIM : 203110026
PRODI : Rekayasa Perangkat Lunak Aplikasi
JENJANG : D3

SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN KOMPUTER


AKAKOM YOGYAKARTA
2020
DESAIN

OUTPUT
SOURCE CODE

import java.awt.Dimension;
import java.awt.Toolkit;
/*
* 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 acer
*/
public class Main extends javax.swing.JFrame {

/**
* Creates new form Main
*/
public Main() {
initComponents();
setPosisiTengah();
}

// set posisi tengah layar


public void setPosisiTengah() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
int width = getWidth();
int height = getHeight();
int w2 = (screenWidth - width) / 2;
int h2 = (screenHeight - height) / 2;
setLocation(w2, h2);
}

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

jScrollPane1 = new javax.swing.JScrollPane();


jTable1 = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
tfNilai = new javax.swing.JTextField();
btnProses = new javax.swing.JButton();
labelNilai = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tfNama = new javax.swing.JTextField();
tfKetNilai = new javax.swing.JTextField();

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N


jLabel1.setText("Nilai");

tfNilai.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N


tfNilai.setForeground(new java.awt.Color(255, 0, 0));
tfNilai.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfNilaiActionPerformed(evt);
}
});

btnProses.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N


btnProses.setText("Proses");
btnProses.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnProsesActionPerformed(evt);
}
});

labelNilai.setBackground(new java.awt.Color(102, 255, 255));


labelNilai.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
labelNilai.setForeground(new java.awt.Color(255, 0, 153));
labelNilai.setText("Nilai Anda adalah");
labelNilai.setBorder(javax.swing.BorderFactory.createEtchedBorder());
labelNilai.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N


jLabel2.setText("Nama");

tfNama.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N


tfNama.setForeground(new java.awt.Color(0, 204, 204));
tfNama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfNamaActionPerformed(evt);
}
});

tfKetNilai.setFont(new java.awt.Font("Tahoma", 0, 48)); // NOI18N


tfKetNilai.setForeground(new java.awt.Color(0, 255, 153));
tfKetNilai.setBorder(new
javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
tfKetNilai.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfKetNilaiActionPerformed(evt);
}
});

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


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tfNama, javax.swing.GroupLayout.PREFERRED_SIZE, 260,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnProses)
.addComponent(tfNilai, javax.swing.GroupLayout.PREFERRED_SIZE, 260,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(labelNilai)
.addGap(18, 18, 18)
.addComponent(tfKetNilai, javax.swing.GroupLayout.PREFERRED_SIZE, 81,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(113, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tfNama, 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.BASELINE)
.addComponent(jLabel1)
.addComponent(tfNilai, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(39, 39, 39)
.addComponent(btnProses)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addComponent(labelNilai)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30,
Short.MAX_VALUE)
.addComponent(tfKetNilai, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(92, 92, 92))))
);

labelNilai.getAccessibleContext().setAccessibleName("");

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

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


// TODO add your handling code here:
}

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


// TODO add your handling code here:
// labelNilai.setText("Hello");
String nama = tfNama.getText();

// mengambil data dari tfNilai, dikonversi ke int


int nilai = Integer.parseInt(tfNilai.getText());
// panggil metode konversiNilai
String nh = konversiNilai(nilai);
//tampilkan hasil konversi (nh) ke labelNilai
labelNilai.setText("Nilai " + nama + " adalah ");
tfKetNilai.setText(nh);
}

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


// TODO add your handling code here:
}

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


// TODO add your handling code here:
}

/**
* @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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Main.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 Main().setVisible(true);
}
});
}

private String konversiNilai(int nilai) {


// deklarasi varibel
String nh;
// konversi nilai bilangan menjadi nilai huruf, simpan dlm 'nh'
if (nilai >= 85) {
nh = "A";
} else if (nilai >= 70) {
nh = "B";
} else if (nilai >= 55) {
nh = "C";
} else if (nilai >= 40) {
nh = "D";
} else {
nh = "E";
}
// hasil konversi menjadi return value (nilai balik)
return nh;
} // akhir metode konversiNilai

// Variables declaration - do not modify


private javax.swing.JButton btnProses;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JLabel labelNilai;
private javax.swing.JTextField tfKetNilai;
private javax.swing.JTextField tfNama;
private javax.swing.JTextField tfNilai;
// End of variables declaration
}

You might also like