LISTING PROGRAM
Pertama kita membuat Empty Class yang bernama "Mahasiswa"
package tugasjava;
import javax.swing.*;
public class Mahasiswa extends TugasJava1{
public int getNim()
{ return nim; }
public void setTekMhs(){
if (nim==12115155)
{ nmmhs="Bayu Sugara"; }
else if (nim==12117196)
{ nmmhs="Muhammad Umar Fauzi"; }
else if (nim==12114602)
{ nmmhs="Aris Joko Purnomo"; }
else if (nim==12117616)
{ nmmhs="Barkah Nugraha"; }
else if (nim==12112769)
{ nmmhs="Hendra Septian"; }
else if (nim==12115444)
{ nmmhs="Mochammad Idrus Asna"; }
else { nmmhs="SALAH KODE!"; }}
public String getNm()
{ return nmmhs; }
}
Kedua, membuat Empty Class dengan nama "Matkul"
package tugasjava;
import javax.swing.*;
public class Matkul extends TugasJava1{
public void setTekMatkul()
{ if(kdmatkul==525)
{ matkul="Pemrograman Berbasis Objek I";
nmdosen="Dony Oscar, S.Kom";
sks=4;}
else if(kdmatkul==635)
{ matkul="Pemodelan Sistem Berbasis Objek";
nmdosen="Agustina Merdekawati, S.Kom";
sks=4;}
else if(kdmatkul==803)
{ matkul="Jaringan Komputer";
nmdosen="Martini, S.Kom";
sks=4;}
else
{ matkul="-";
nmdosen="-";
sks=0;}}
public int getKdmatkul()
{ return kdmatkul; }
public String getMatkul()
{ return matkul; }
public int getSks()
{ return sks; }
public String getDosen()
{ return nmdosen; }
}
Ketiga, membuat Empty Class dengan nama "Nilai"
package tugasjava;
import javax.swing.*;
public class Nilai extends TugasJava1{
public void setTekNilai()
{ if (nilai>100)
{ grade=" ";
ket=" ";}
else if (nilai <= 100 &&nilai >= 80 )
{ grade="A";
ket="Lulus";}
else if (nilai < 80 && nilai >=70 )
{ grade="B";
ket="Lulus";}
else if (nilai < 70 && nilai >=60 )
{ grade="C";
ket="Lulus";}
else if (nilai < 60 && nilai >=50 )
{ grade="D";
ket="Tidak Lulus";}
else { grade="E";
ket="Tidak Lulus";} }
public int getNilai()
{ return nilai; }
public String getGrade()
{ return grade; }
public String getKet()
{ return ket; }
}
Keempat, membuat Empty Class. Disini dinamain "TugasJava1"
package tugasjava;
public class TugasJava1{
public int nim,nilai,kdmatkul,sks;
public String nmmhs,grade,ket,nmdosen,matkul;
public void setNim( Integer val)
{ nim=val;}
public void setNm( String val)
{ nmmhs=val; }
public void setKdmatkul( Integer val)
{ kdmatkul=val; }
public void setSks( Integer val)
{ sks=val; }
public void setDosen( String val)
{ nmdosen=val; }
public void setNilai ( Integer val )
{ nilai = val; }
public void setGrade( String val)
{ grade = val;}
public void setket( String val)
{ grade = val;}
public void setTekMhs()
{ return; }
public void setTekNilai()
{ return; }
public void setTekMatkul()
{ return; }
}
Dan, yang terakhir membuat Main Class dengan Nama "TugasTugas"
package tugasjava;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class TugasTugas extends JFrame implements ActionListener{
private JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8,jLabel9;
private JTextField tnim,tkdmatkul, tnmhs,tmatkul,tsks,tnmdosen,tnilai,tgrade,tket;
private JButton bcekmhs,bcekmt,bceknl, bbersih, bkeluar;
Mahasiswa mhs = new Mahasiswa();
Matkul mt = new Matkul();
Nilai nl = new Nilai();
TugasJava1 tj = new TugasJava1();
public TugasTugas (){
setTitle("FORM PERHITUNGAN NILAI");
setSize(500,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
jLabel1 = new JLabel("NIM");
jLabel2 = new JLabel("Nama Mahasiswa");
jLabel3 = new JLabel("Kode Mata Kuliah");
jLabel4 = new JLabel("Mata kuliah");
jLabel5 = new JLabel("SKS");
jLabel6 = new JLabel("Nama Dosen");
jLabel7 = new JLabel("Nilai");
jLabel8 = new JLabel("Grade");
jLabel9 = new JLabel("Keterangan");
tkdmatkul = new JTextField("");
tnim = new JTextField("");
tnmhs = new JTextField("");
tnmhs.setEditable(false);
tmatkul = new JTextField("");
tmatkul.setEditable(false);
tsks = new JTextField("");
tsks.setEditable(false);
tnmdosen = new JTextField("");
tnmdosen.setEditable(false);
tnilai = new JTextField("");
tgrade = new JTextField("");
tgrade.setEditable(false);
tket = new JTextField("");
tket.setEditable(false);
bcekmhs = new JButton("CEK NIM");
bcekmt = new JButton("CEK MATKUL");
bceknl = new JButton("LIHAT");
bbersih = new JButton("BERSIH");
bkeluar = new JButton("KELUAR");
add(jLabel1);
add(jLabel2);
add(jLabel3);
add(jLabel4);
add(jLabel5);
add(jLabel6);
add(jLabel7);
add(jLabel8);
add(jLabel9);
add(tnim);
add(tnmhs);
add(tkdmatkul);
add(tmatkul);
add(tsks);
add(tnmdosen);
add(tnilai);
add(tgrade);
add(tket);
add(bbersih);
add(bceknl);
add(bkeluar);
add(bcekmhs);
add(bcekmt);
jLabel1.setBounds(30,70,80,25);
jLabel2.setBounds(30,100,120,25);
jLabel3.setBounds(30,130,80,25);
jLabel4.setBounds(30,160,80,25);
jLabel5.setBounds(30,190,80,25);
jLabel6.setBounds(30,220,80,25);
jLabel7.setBounds(30,250,80,25);
jLabel8.setBounds(30,280,80,25);
jLabel9.setBounds(30,310,80,25);
tnim.setBounds(150,70,80,20);
tnmhs.setBounds(150,100,140,20);
tkdmatkul.setBounds(150,130,80,20);
tmatkul.setBounds(150,160,180,20);
tsks.setBounds(150,190,80,20);
tnmdosen.setBounds(150,220,150,20);
tnilai.setBounds(150,250,40,20);
tgrade.setBounds(150,280,40,20);
tket.setBounds(150,310,80,20);
bcekmt.setBounds(235,130,110,20);
bceknl.setBounds(200,250,100,20);
bcekmhs.setBounds(235,70,90,20);
bbersih.setBounds(350,200,100,40);
bkeluar.setBounds(350,250,100,40);
bcekmhs.addActionListener(this);
bcekmt.addActionListener(this);
bceknl.addActionListener(this);
bbersih.addActionListener(this);
bkeluar.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object tombol = e.getSource();
if (tombol==bceknl)
{ nl.setNilai(Integer.parseInt(tnilai.getText()));
nl.setTekNilai();
tgrade.setText(nl.getGrade());
tket.setText(nl.getKet());
tkdmatkul.requestFocus();}
else if (tombol==bcekmhs)
{ mhs.setNim(Integer.parseInt(tnim.getText()));
mhs.setTekMhs();
tnmhs.setText(mhs.getNm()); }
else if (tombol==bcekmt)
{ mt.setKdmatkul(Integer.parseInt(tkdmatkul.getText()));
mt.setTekMatkul();
tmatkul.setText(mt.getMatkul());
tsks.setText(Integer.toString(mt.getSks()));
tnmdosen.setText(mt.getDosen());}
else if(tombol==bbersih)
{ tnim.setText("");
tkdmatkul.setText("");
tnmhs.setText("");
tmatkul.setText("");
tsks.setText("");
tnmdosen.setText("");
tnilai.setText("");
tgrade.setText("");
tket.setText(""); }
else if(tombol==bkeluar)
{ int x;
x=JOptionPane.showConfirmDialog(null,"Yakin Mau Keluar?","Konfirmasi",JOptionPane.YES_NO_OPTION);
if (x==JOptionPane.YES_OPTION)
dispose();
else return; }}
public static void main (String args[]){
TugasTugas mn = new TugasTugas ();
mn.setVisible(true);
}
}
Untuk Running silahkan tekan Shift+F6 pada class "TugasTugas" ( Class terakhir )
SELAMAT MENCOBA...!!!
Tidak ada komentar:
Posting Komentar