coding Form Penilaian Mata Kuliah read more
coding Form Penilaian Mata Kuliahimport java.sql.*;
import javax.swing.*;
import javax.swing.border.*; //untuk border
import javax.swing.table.*; //untuk tabel
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.Date; //untuk tanggal
class Aplikasi_Penilaian_Mhs extends JFrame
{
JPanel panel = new JPanel ();
JPanel panel2 = new JPanel ();
JPanel panel3 = new JPanel ();
JLabel judul = new JLabel ("FORM PENILAIAN MATA KULIAH");
JLabel judul2 = new JLabel ("POLITEKNIK ACEH");
JLabel logo = new JLabel (new ImageIcon("gambar/logo.png"));
JLabel kampus = new JLabel (new ImageIcon("gambar/kampus.png"));
JLabel wall = new JLabel(new ImageIcon("gambar/template.jpg"));
JLabel Lnama = new JLabel("Nama");
JTextField txnama = new JTextField(20);
JLabel Lnim = new JLabel("NIM ");
JTextField txnim = new JTextField(20);
JLabel Lkelas = new JLabel("Kelas ");
JRadioButton kelasA = new JRadioButton("A");
JRadioButton kelasB = new JRadioButton("B");
JRadioButton kelasC = new JRadioButton("C");
ButtonGroup grupkelas=new ButtonGroup();
JLabel Lkul = new JLabel("Mata Kuliah");
String[] kuliah = {" ","Teori Java Visual","Praktek Java Visual","Teori Algoritma","Praktek Algoritma"};
JComboBox cbkul= new JComboBox(kuliah);
JLabel Ltugas1 = new JLabel("Nilai Tugas1");
JTextField txtugas1 = new JTextField("0");
JLabel Ltugas2 = new JLabel("Nilai Tugas2");
JTextField txtugas2=new JTextField("0");
JLabel Ltugas3 = new JLabel("Nilai Tugas3");
JTextField txtugas3 = new JTextField("0");
JLabel Ltugas4 = new JLabel("Nilai Tugas4");
JTextField txtugas4=new JTextField("0");
JLabel Ltugas5 = new JLabel("Nilai Tugas5");
JTextField txtugas5 = new JTextField("0");
JLabel Luts = new JLabel("Nilai UTS");
JTextField txuts = new JTextField("0");
JLabel Luas = new JLabel("Nilai UAS");
JTextField txuas = new JTextField("0");
JLabel Lakhir = new JLabel("Nilai Akhir");
JTextField txakhir = new JTextField();
JLabel Lhuruf = new JLabel("Nilai Huruf");
JTextField txhuruf = new JTextField();
JButton tblcari = new JButton(new ImageIcon("gambar/cari.png"));
JButton tblprint = new JButton("Print");
JButton tblsimpan = new JButton("Save");
JButton tblupdate = new JButton("Update");
JButton tblkeluar = new JButton("Exit");
JButton tblhapus = new JButton ("Clear");
JButton tbldelete = new JButton ("Delete");
JButton tblcetak = new JButton ("Cetak Laporan");
String header [] ={"NIM","Nama","Kelas","Mata Kuliah","Tugas1","Tugas2","Tugas3","Tugas4","Tugas5","UTS","UAS","Total","Huruf"};
DefaultTableModel model = new DefaultTableModel(null,header);
JTable tabel = new JTable(model);
JScrollPane pane = new JScrollPane(tabel);
Dimension dimensi = new Dimension(15,2); //untuk perataan isi tabel (x,y)
Date tanggal = new Date();
JLabel Ltgl = new JLabel("Tanggal : ");
JLabel Ltgl2 = new JLabel(tanggal.getDate() +" - "+(tanggal.getMonth()+1)+" - "+(tanggal.getYear()+1900),10);
JLabel Ljam = new JLabel("Jam : ");
JLabel Ljam2 = new JLabel(String.format("%1$tH : %1$tM : %1$tS",tanggal)); //untuk jam
Aplikasi_Penilaian_Mhs()
{
setTitle("Lembar Penilaian");
setLocation(0,0);
setSize(1020,570);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void komponenVisual()
{
getContentPane().setLayout(null);
getContentPane().add(judul);
judul.setBounds(250,10,500,40);
judul.setFont(new Font("Arial",Font.BOLD,20));
judul.setHorizontalAlignment(SwingConstants.CENTER);
getContentPane().add(judul2);
judul2.setBounds(350,40,300,40);
judul2.setFont(new Font("Arial",Font.BOLD,18));
judul2.setHorizontalAlignment(SwingConstants.CENTER);
getContentPane().add(logo);
logo.setBounds(10,0,100,100);
getContentPane().add(kampus);
kampus.setBounds(700,0,100,100);
//=========================== panel 1 ===================================//
getContentPane().add(panel);
panel.setLayout(null);
panel.setBounds(0,100,300,340);
panel.setBorder (new TitledBorder (new LineBorder(Color.pink, 5), "Data Nilai Mahasiswa"));
panel.setOpaque(false);
panel.add(Lnim);
Lnim.setBounds(10,25,70,20);
panel.add(txnim);
txnim.setBounds(100,25,150,20);
txnim.setOpaque(false);
panel.add(tblcari);
tblcari.setBounds(255,25,32,32);
panel.add(Lnama);
Lnama.setBounds(10,50,70,20);
panel.add(txnama);
txnama.setBounds(100,50,150,20);
panel.add(Lkelas);
Lkelas.setBounds(10,75,100,20);
panel.add(kelasA);
kelasA.setBounds(100,75,50,20);
kelasA.setOpaque(false);
panel.add(kelasB);
kelasB.setBounds(155,75,50,20);
kelasB.setOpaque(false);
panel.add(kelasC);
kelasC.setBounds(210,75,50,20);
kelasC.setOpaque(false);
grupkelas.add(kelasA);
grupkelas.add(kelasB);
grupkelas.add(kelasC);
panel.add(Lkul);
Lkul.setBounds(10,100,100,20);
panel.add(cbkul);
cbkul.setBounds(100,100,150,20);
panel.add(Ltugas1);
Ltugas1.setBounds(10,130,100,20);
panel.add(txtugas1);
txtugas1.setBounds(100,130,100,20);
panel.add(Ltugas2);
Ltugas2.setBounds(10,150,100,20);
panel.add(txtugas2);
txtugas2.setBounds(100,150,100,20);
panel.add(Ltugas3);
Ltugas3.setBounds(10,170,100,20);
panel.add(txtugas3);
txtugas3.setBounds(100,170,100,20);
panel.add(Ltugas4);
Ltugas4.setBounds(10,190,100,20);
panel.add(txtugas4);
txtugas4.setBounds(100,190,100,20);
panel.add(Ltugas5);
Ltugas5.setBounds(10,210,100,20);
panel.add(txtugas5);
txtugas5.setBounds(100,210,100,20);
panel.add(Luts);
Luts.setBounds(10,230,100,20);
panel.add(txuts);
txuts.setBounds(100,230,100,20);
panel.add(Luas);
Luas.setBounds(10,250,100,20);
panel.add(txuas);
txuas.setBounds(100,250,100,20);
panel.add(Lakhir);
Lakhir.setBounds(10,275,100,20);
panel.add(txakhir);
txakhir.setBounds(100,275,100,20);
txakhir.setEditable(false);
panel.add(Lhuruf);
Lhuruf.setBounds(10,300,100,20);
panel.add(txhuruf);
txhuruf.setBounds(100,300,100,20);
txhuruf.setEditable(false);
//======================================================================//
//============================= panel 2 ===============================//
getContentPane().add(panel2);
panel2.setLayout(null);
panel2.setBounds(0,440,1000,90);
panel2.setBorder (new TitledBorder (new LineBorder(Color.pink, 5), "Tombol Aksi"));
panel2.setOpaque(false); //untuk transparan
panel2.add(tblprint);
tblprint.setBounds(15,25,120,50);
tblprint.setToolTipText("Print Kartu Nilai Siswa");
tblprint.setIcon(new ImageIcon("gambar/print.png"));
panel2.add(tblsimpan);
tblsimpan.setBounds(145,25,120,50);
tblsimpan.setToolTipText("Simpan Data Ke database");
tblsimpan.setIcon(new ImageIcon("gambar/save.png"));
panel2.add(tblupdate);
tblupdate.setBounds(275,25,130,50);
tblupdate.setToolTipText("Update Data di Database");
tblupdate.setIcon(new ImageIcon("gambar/edit.png"));
panel2.add(tblhapus);
tblhapus.setBounds(415,25,120,50);
tblhapus.setToolTipText("Hapus Data di Layar");
tblhapus.setIcon(new ImageIcon("gambar/clear.png"));
panel2.add(tbldelete);
tbldelete.setBounds(545,25,130,50);
tbldelete.setToolTipText("Hapus Data di Database");
tbldelete.setIcon(new ImageIcon("gambar/delete.png"));
panel2.add(tblkeluar);
tblkeluar.setBounds(685,25,130,50);
tblkeluar.setToolTipText("Keluar dari Program");
tblkeluar.setIcon(new ImageIcon("gambar/exit.png"));
panel2.add(Ltgl);
Ltgl.setBounds(840,25,60,20);
panel2.add(Ltgl2);
Ltgl2.setBounds(900,25,100,20);
panel2.add(Ljam);
Ljam.setBounds(860,55,60,20);
panel2.add(Ljam2);
Ljam2.setBounds(900,55,100,20);
//================================================================//
//============================= panel 3 ===============================//
getContentPane().add(panel3);
panel3.setLayout(null);
panel3.setBounds(310,100,690,340);
panel3.setBorder (new TitledBorder (new LineBorder(Color.pink, 5), "Tabel DataBase"));
panel3.setOpaque(false);
panel3.setForeground(Color.white);
panel3.add(pane);
pane.setBounds(10,20,670,255);
pane.setOpaque(false); //untuk tranparan tabel
pane.getViewport().setOpaque(false); //untuk tranparan tabel
tabel.setShowGrid(true); //untuk menampilkan garis horizontal
tabel.setShowVerticalLines(true); //untuk menampilkan garis vertikal
tabel.setIntercellSpacing(new Dimension(dimensi)); //untuk spasing
tabel.setGridColor(Color.GREEN); //Memberi warna garis tabel
panel3.add(tblcetak);
tblcetak.setBounds(10,280,670,50);
tblcetak.setIcon(new ImageIcon ("gambar/cetak.png"));
//==========================================================//
getContentPane().add(wall);
wall.setBounds(0,0,1020,560);
setVisible(true);
tampilTabel(); //panggil data di void tampilTabel
}
//====================================== Aksi Reaksi ======================================//
void AksiReaksi()
{
//=========================== simpan data ===========================//
tblsimpan.addActionListener(new ActionListener() //untuk simpan data
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource()==tblsimpan)
{
try
{
Class.forName("com.mysql.jdbc.Driver"); //untuk mendeteksi driver database
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/DataMahasiswa","root","root");
String sql="insert into DataNilai values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pr = koneksi.prepareStatement(sql);
//untuk ambil data yang mau disimpan
pr.setString(1,txnim.getText());
pr.setString(2,txnama.getText());
if(kelasA.isSelected()==true) {
pr.setString(3,kelasA.getText());
}
else if(kelasB.isSelected()==true) {
pr.setString(3,kelasB.getText());
}
else {
pr.setString(3,kelasC.getText());
}
pr.setString(4,(String) cbkul.getSelectedItem());
pr.setString(5,txtugas1.getText());
pr.setString(6,txtugas2.getText());
pr.setString(7,txtugas3.getText());
pr.setString(8,txtugas4.getText());
pr.setString(9,txtugas5.getText());
pr.setString(10,txuts.getText());
pr.setString(11,txuas.getText());
hitungNilai(); // ambil data di void hitungNilai()
konversiHuruf(); // ambil data di void konversiHuruf()
pr.setString(12,txakhir.getText());
pr.setString(13,txhuruf.getText());
pr.executeUpdate(); //untuk melanjutkan proses penyimpanan
pr.close(); // untuk menutup proses penyimpanan
koneksi.close(); //untuk menutup koneksi
JOptionPane.showMessageDialog(null, "Data Telah Masuk", "Konfirmasi", JOptionPane.INFORMATION_MESSAGE);
resetData (); //untuk hapus data
tampilTabel(); //panggil data di void tampilTabel
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "data telah ada didalam database","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
} } } } );
//=========================== Cari data ===========================//
tblcari.addActionListener(new ActionListener() //untuk mencari data
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==tblcari)
{
try
{
String nim=txnim.getText();
Class.forName("com.mysql.jdbc.Driver"); //untuk mendeteksi driver database
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/DataMahasiswa","root","root");
Statement st = koneksi.createStatement();
String sql="select * from datanilai where nim like '"+nim+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
txnim.setText(rs.getString(1));
txnama.setText(rs.getString(2));
String kelas=rs.getString(3);
if(kelas.equals("A"))
{
kelasA.setSelected(true);
}
else if(kelas.equals("B"))
{
kelasB.setSelected(true);
}
else
{
kelasC.setSelected(true);
}
cbkul.setSelectedItem(rs.getString(4));
txtugas1.setText(rs.getString(5));
txtugas2.setText(rs.getString(6));
txtugas3.setText(rs.getString(7));
txtugas4.setText(rs.getString(8));
txtugas5.setText(rs.getString(9));
txuts.setText(rs.getString(10));
txuas.setText(rs.getString(11));
txakhir.setText(rs.getString(12));
txhuruf.setText(rs.getString(13));
}
else
{
JOptionPane.showMessageDialog(null, "Nim yang anda cari tidak ada","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
}
st.close();
koneksi.close();
}
catch(Exception ex)
{
System.out.println("Error :"+ex);
} } } } );
//=========================== Update data ===========================//
tblupdate.addActionListener(new ActionListener() //untuk update data
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource()==tblupdate)
{
try
{
Class.forName("com.mysql.jdbc.Driver"); //untuk mendeteksi driver database
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/DataMahasiswa","root","root");
String sql="update DataNilai set nama =? , kelas =? , mata_kuliah =? , tugas1 =? , tugas2 =? , tugas3 =? , tugas4 =? , tugas5 =? , uts = ?, uas = ?, Nilai_Angka = ?, Nilai_Huruf = ? WHERE NIM = ?";
PreparedStatement pr = koneksi.prepareStatement(sql);
pr.setString(1,txnama.getText());
if(kelasA.isSelected()==true) {
pr.setString(2,kelasA.getText());
}
else if(kelasB.isSelected()==true) {
pr.setString(2,kelasB.getText());
}
else {
pr.setString(2,kelasC.getText());
}
pr.setString(3,(String)cbkul.getSelectedItem());
pr.setString(4,txtugas1.getText());
pr.setString(5,txtugas2.getText());
pr.setString(6,txtugas3.getText());
pr.setString(7,txtugas4.getText());
pr.setString(8,txtugas5.getText());
pr.setString(9,txuts.getText());
pr.setString(10,txuas.getText());
hitungNilai(); // ambil data di void hitungNilai
konversiHuruf(); // ambil data di void konversiHuruf
pr.setString(11,txakhir.getText());
pr.setString(12,txhuruf.getText());
pr.setInt(13,Integer.parseInt(txnim.getText()));
pr.executeUpdate();
pr.close();
koneksi.close();
resetData (); //panggil data di void resetData
tampilTabel(); //panggil data di void tampilTabel
JOptionPane.showMessageDialog(null, "Data Sudah TerUpdate","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
System.out.println("Error :"+e);
} } } } );
//=========================== hapus layar ===========================//
tblhapus.addActionListener(new ActionListener() //untuk bersihkan data dilayar
{
public void actionPerformed(ActionEvent e)
{
resetData ();
} } );
//=========================== Hapus database ===========================//
tbldelete.addActionListener(new ActionListener() //untuk hapus data dari database
{
public void actionPerformed(ActionEvent e)
{
String nim=txnim.getText();
int tanya = JOptionPane.showConfirmDialog(null,"Apakah Anda ingin Menghapus Data NIM "+nim+" ?","Konfirmasi",JOptionPane.YES_NO_OPTION);
if (tanya==0)
{
try
{
Class.forName("com.mysql.jdbc.Driver"); //untuk mendeteksi driver database
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/DataMahasiswa","root","root");
String sql="DELETE FROM DataNilai WHERE nim=?";
PreparedStatement pr = koneksi.prepareStatement(sql);
pr.setString(1,nim);
pr.executeUpdate();
pr.close();
koneksi.close();
JOptionPane.showMessageDialog(null,"Data telah dihapus");
resetData (); //panggil data di void resetData
tampilTabel(); //panggil data di void tampilTabel
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,"Error :"+ex,"Error",JOptionPane.ERROR_MESSAGE);
} } } } );
//=========================== Keluar ===========================//
tblkeluar.addActionListener(new ActionListener() // untuk keluar
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
} } );
//====================================cetak laporan =======================//
tblcetak.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
int y = 0;
Frame fr = new Frame();
PrintJob print = fr.getToolkit().getPrintJob(fr, "Prinnting", null, null);
if (print != null)
{
Graphics g = print.getGraphics();
if (g != null)
{
//untuk kop (header)
g.setFont(new Font("Dialog", 1, 11));
g.drawString("LAPORAN DATA NILAI MAHASISWA", 150, 40);
//untuk nama kolom tabel
String nim = tabel.getColumnName(0);
String nama = tabel.getColumnName(1);
String kelas = tabel.getColumnName(2);
String kuliah = tabel.getColumnName(3);
String tugas1 = tabel.getColumnName(4);
String tugas2 = tabel.getColumnName(5);
String tugas3 = tabel.getColumnName(6);
String tugas4 = tabel.getColumnName(7);
String tugas5 = tabel.getColumnName(8);
String uts = tabel.getColumnName(9);
String uas = tabel.getColumnName(10);
String akhir = tabel.getColumnName(11);
String huruf = tabel.getColumnName(12);
g.setFont(new Font("Dialog", 1, 8));
g.drawString(nim, 30, 70);
g.drawString(nama, 80, 70);
g.drawString(kelas, 130, 70);
g.drawString(kuliah, 160, 70);
g.drawString(tugas1, 240, 70);
g.drawString(tugas2, 280, 70);
g.drawString(tugas3, 320, 70);
g.drawString(tugas4, 360, 70);
g.drawString(tugas5, 400, 70);
g.drawString(uts, 440, 70);
g.drawString(uas, 470, 70);
g.drawString(akhir, 500, 70);
g.drawString(huruf, 530, 70);
g.drawLine(30, 73, 570, 73); //untuk garis
//untuk datanya tabel
int n = model.getRowCount();
for (int i = 0; i < n; i++)
{
int k = i + 1;
int j = 10 * k;
y = 73 + j;
g.setFont(new Font("Dialog", 0, 8)); //untuk buat tulisan
String data_nim = model.getValueAt(i, 0).toString();
String data_nama = model.getValueAt(i, 1).toString();
String data_kelas = model.getValueAt(i, 2).toString();
String data_kuliah = model.getValueAt(i, 3).toString();
String data_tugas1 = model.getValueAt(i, 4).toString();
String data_tugas2 = model.getValueAt(i, 5).toString();
String data_tugas3 = model.getValueAt(i, 6).toString();
String data_tugas4 = model.getValueAt(i, 7).toString();
String data_tugas5 = model.getValueAt(i, 8).toString();
String data_uts = model.getValueAt(i, 9).toString();
String data_uas = model.getValueAt(i, 10).toString();
String data_akhir = model.getValueAt(i, 11).toString();
String data_huruf = model.getValueAt(i, 12).toString();
g.drawString(data_nim, 30, y);
g.drawString(data_nama, 80, y);
g.drawString(data_kelas, 130, y);
g.drawString(data_kuliah, 160, y);
g.drawString(data_tugas1, 250, y);
g.drawString(data_tugas2, 290, y);
g.drawString(data_tugas3, 330, y);
g.drawString(data_tugas4, 370, y);
g.drawString(data_tugas5, 410, y);
g.drawString(data_uts, 445, y);
g.drawString(data_uas, 475, y);
g.drawString(data_akhir, 505, y);
g.drawString(data_huruf, 540, y);
}
}
print.end();
print.end();
} } } );
//=============================== cetak kartu ========================//
tblprint.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
int y = 0;
Frame fr = new Frame();
PrintJob print = fr.getToolkit().getPrintJob(fr, "Prinnting", null, null);
if (print != null)
{
Graphics g = print.getGraphics();
if (g != null)
{
//untuk kop (header)
g.drawRect(10,10,200,320); //untuk buat kotak
g.setFont(new Font("Dialog", 1, 11));
g.drawString("KARTU NILAI MAHASISWA", 40, 40);
g.drawLine(10, 50, 210, 50); //untuk garis
g.drawString("NIM", 20,70);
g.drawString(":", 90, 70);
g.drawString(txnim.getText(), 100, 70);
g.drawString("Nama", 20,90);
g.drawString(":", 90, 90);
g.drawString(txnama.getText(), 100, 90);
g.drawString("Kelas", 20,110);
g.drawString(":", 90, 110);
if(kelasA.isSelected()==true) {
g.drawString(kelasA.getText(), 100, 110);
}
else if(kelasB.isSelected()==true) {
g.drawString(kelasB.getText(), 100, 110);
}
else {
g.drawString(kelasC.getText(), 100, 110);
}
g.drawString("Mata Kuliah", 20,130);
g.drawString(":", 90, 130);
g.drawString((String)cbkul.getSelectedItem(), 100, 130);
g.drawString("Tugas 1", 20,150);
g.drawString(":", 90, 150);
g.drawString(txtugas1.getText(), 100, 150);
g.drawString("Tugas 2", 20,170);
g.drawString(":", 90, 170);
g.drawString(txtugas2.getText(), 100, 170);
g.drawString("Tugas 3", 20,190);
g.drawString(":", 90, 190);
g.drawString(txtugas3.getText(), 100, 190);
g.drawString("Tugas 4", 20,210);
g.drawString(":", 90, 210);
g.drawString(txtugas4.getText(), 100, 210);
g.drawString("Tugas 5", 20,230);
g.drawString(":", 90, 230);
g.drawString(txtugas5.getText(), 100, 230);
g.drawString("UTS", 20,250);
g.drawString(":", 90, 250);
g.drawString(txuts.getText(), 100, 250);
g.drawString("UAS", 20,270);
g.drawString(":", 90, 270);
g.drawString(txuas.getText(), 100, 270);
g.drawString("Nilai Akhir", 20,290);
g.drawString(":", 90, 290);
g.drawString(txakhir.getText(), 100, 290);
g.drawString("Nilai Huruf", 20,310);
g.drawString(":", 90, 310);
g.drawString(txhuruf.getText(), 100, 310);
} }
print.end();
print.end();
} } );
//==================================================================//
} //untuk tutup void aksi reaksi
//================================ tampil tabel ===========================//
void tampilTabel()
{
hapusTabel();//ambil data di void hapus tabel()
try
{
Class.forName("com.mysql.jdbc.Driver"); //untuk mendeteksi driver database
Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost/DataMahasiswa","root","root");
Statement state = koneksi.createStatement();
String sql = "select * from DataNilai";
ResultSet rs = state.executeQuery(sql);
while(rs.next())
{
Object obj[] = new Object[13]; //tergantung kolom tabel
obj[0] = rs.getString(1); //nim
obj[1] = rs.getString(2); //nama
obj[2] = rs.getString(3); //kelas
obj[3] = rs.getString(4); //mata kuliah
obj[4] = rs.getString(5); //tugas1
obj[5] = rs.getString(6); //tugas2
obj[6] = rs.getString(7); //tugas3
obj[7] = rs.getString(8); //tugas4
obj[8] = rs.getString(9); //tugas5
obj[9] = rs.getString(10); //uts
obj[10] = rs.getString(11); //uas
obj[11] = rs.getString(12); //nilai akhir
obj[12] = rs.getString(13); //nilai huruf
model.addRow(obj);
} }
catch(Exception ex)
{
System.out.println(ex);
} }
//==========================================================//
//============================== hapus Tabel ================================//
void hapusTabel()
{
int row = model.getRowCount();
for (int i = 0; i < row; i++)
{
model.removeRow(0);
} }
//=================================================================//
//=========================== Reset data ===========================//
void resetData () //untuk hapus data
{
txnim.setText("");
txnama.setText("");
cbkul.setSelectedItem(kuliah[0]);
txtugas1.setText("0");
txtugas2.setText("0");
txtugas3.setText("0");
txtugas4.setText("0");
txtugas5.setText("0");
txuts.setText("0");
txuas.setText("0");
txakhir.setText("");
txhuruf.setText("");
}
//=========================== Hitung Nilai ===========================//
void hitungNilai() // untuk menghitung nilai akhir
{
double ntugas1=Double.parseDouble(txtugas1.getText());
double ntugas2=Double.parseDouble(txtugas2.getText());
double ntugas3=Double.parseDouble(txtugas3.getText());
double ntugas4=Double.parseDouble(txtugas4.getText());
double ntugas5=Double.parseDouble(txtugas5.getText());
String tugas = String.valueOf ((ntugas1 + ntugas2 + ntugas3 + ntugas4 + ntugas5)/5);
double total_tugas = 2*Double.parseDouble(tugas); //nilai tugas * 20%
double nuts = 3*Double.parseDouble(txuts.getText()); //nilai uts * 30%
double nuas=5*Double.parseDouble(txuas.getText()); //nilai uas * 50%
String hasil = String.valueOf (total_tugas + nuts + nuas);
txakhir.setText(hasil.substring(0,2));
}
//=========================== Konversi Huruf ===========================//
void konversiHuruf() // untuk konversi dari angka ke huruf
{
double dataAngka = Double.parseDouble(txakhir.getText());
String NilaiAkhir ="";
if(dataAngka>90 && dataAngka<=100) {
NilaiAkhir="A";
}
else if(dataAngka>81 && dataAngka<=90) {
NilaiAkhir="B+";
}
else if(dataAngka>72 && dataAngka<=81) {
NilaiAkhir="B";
}
else if(dataAngka>63 && dataAngka<=72) {
NilaiAkhir="C+";
}
else if(dataAngka>54 && dataAngka<=63) {
NilaiAkhir="C";
}
else if(dataAngka>40 && dataAngka<=54) {
NilaiAkhir="D";
}
else
{
NilaiAkhir="E";
}
txhuruf.setText(NilaiAkhir);
}
public static void main(String args[])
{
Aplikasi_Penilaian_Mhs ap=new Aplikasi_Penilaian_Mhs();
ap.komponenVisual();
ap.AksiReaksi();
} }