GUIDASAR-DASAR PEMOGRAMANSource :import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JButton;import...
TugasGUI(){GridLayout gl = new GridLayout(12,2);panelPenjumlahan.setLayout(gl);panelPenjumlahan.add(labelBilangan1);panelP...
double bilangan1 =Double.parseDouble(fieldBilangan1.getText());double bilangan2 =Double.parseDouble(fieldBilangan2.getText...
JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat E ");}else {fieldBilangan1.setText("");fieldBil...
Membuat kalkulator penilaian Sederhana Java
Upcoming SlideShare
Loading in …5
×

Membuat kalkulator penilaian Sederhana Java

334 views

Published on

Published in: Technology, Art & Photos
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
334
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Membuat kalkulator penilaian Sederhana Java

  1. 1. GUIDASAR-DASAR PEMOGRAMANSource :import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JOptionPane;import java.awt.GridLayout;import javax.swing.JFrame;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class TugasGUI implements ActionListener {JLabel labelBilangan1 = new JLabel("Nilai UTS: ");JTextField fieldBilangan1 = new JTextField(10);JLabel labelBilangan2 = new JLabel("Nilai UAS: ");JTextField fieldBilangan2 = new JTextField(10);JLabel labelBilangan3 = new JLabel("Nilai Tugas: ");JTextField fieldBilangan3 = new JTextField(10);JLabel labelBilangan4 = new JLabel("Persentase Nilai UTS:(0.--)");JTextField fieldBilangan4 = new JTextField(10);JLabel labelBilangan5 = new JLabel("Persentase Nilai UAS:(0.--)");JTextField fieldBilangan5 = new JTextField(10);JLabel labelBilangan6 = new JLabel("Persentase NilaiTugas:(0.--)");JTextField fieldBilangan6 = new JTextField(10);JButton buttonTambah = new JButton("Proses");JButton buttonHapus = new JButton("Hapus");JPanel panelPenjumlahan = new JPanel();
  2. 2. TugasGUI(){GridLayout gl = new GridLayout(12,2);panelPenjumlahan.setLayout(gl);panelPenjumlahan.add(labelBilangan1);panelPenjumlahan.add(fieldBilangan1);panelPenjumlahan.add(labelBilangan2);panelPenjumlahan.add(fieldBilangan2);panelPenjumlahan.add(labelBilangan3);panelPenjumlahan.add(fieldBilangan3);panelPenjumlahan.add(labelBilangan4);panelPenjumlahan.add(fieldBilangan4);panelPenjumlahan.add(labelBilangan5);panelPenjumlahan.add(fieldBilangan5);panelPenjumlahan.add(labelBilangan6);panelPenjumlahan.add(fieldBilangan6);panelPenjumlahan.add(buttonTambah);panelPenjumlahan.add(buttonHapus);buttonTambah.addActionListener(this);buttonHapus.addActionListener(this);JFrame jendela = new JFrame("Contoh GUI Java");jendela.setContentPane(panelPenjumlahan);jendela.setSize(400,400);jendela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);jendela.setVisible(true);jendela.setResizable(false);}public static void main(String[] args) {TugasGUI contohGUI = new TugasGUI();}public void actionPerformed(ActionEvent kejadian) {try {if(kejadian.getSource() == buttonTambah) {
  3. 3. double bilangan1 =Double.parseDouble(fieldBilangan1.getText());double bilangan2 =Double.parseDouble(fieldBilangan2.getText());double bilangan3 =Double.parseDouble(fieldBilangan3.getText());double bilangan4 =Double.parseDouble(fieldBilangan4.getText());double bilangan5 =Double.parseDouble(fieldBilangan5.getText());double bilangan6 =Double.parseDouble(fieldBilangan6.getText());double hasil1 = bilangan1 * bilangan4;double hasil2 = bilangan2 * bilangan5;double hasil3 = bilangan3 * bilangan6;double hasil4 = hasil1 + hasil2 + hasil3;if ( hasil4 >= 86 )JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat A ");else if (hasil4 >= 76)JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat B+ ");else if (hasil4 >= 66)JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat B ");else if (hasil4 >= 56)JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat C+ ");else if (hasil4 >= 46)JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat C ");else if (hasil4 >= 36)JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat D ");else
  4. 4. JOptionPane.showMessageDialog(null, "Nilai Anda :"+hasil4+"nnAnda mendapat E ");}else {fieldBilangan1.setText("");fieldBilangan2.setText("");fieldBilangan3.setText("");fieldBilangan4.setText("");fieldBilangan5.setText("");fieldBilangan6.setText("");fieldBilangan1.requestFocus();}}catch(Exception a) {JOptionPane.showMessageDialog(panelPenjumlahan, "Inputyang Anda masukkan salah!"+"" +"nnKetentuan: "+"n-Ganti tanda koma (,) dengantanda titik (.)"+"" +"n-Input hanya berupa angka");}}}Output :

×