import
javax.swing.*;
import
java.awt.*;
import
java.awt.event.*;
import
java.io.*;
public
class Input {
private int jawab;
public static void main(String[] args) {
final JFrame frame = new
JFrame("Input Data Teks");
JLabel lNama = new JLabel("Nama
Mata Kuliah");
JLabel lSKS = new JLabel("Jumlah
SKS");
JLabel lNilai1 = new JLabel("Nilai
I");
JLabel lNilai2 = new JLabel("Nilai
2");
JLabel lRata = new
JLabel("Rata-Rata");
final JTextField Fieldnama = new
JTextField(10);
final JTextField FieldSKS = new
JTextField(2);
final JTextField Fieldnilai_1 = new
JTextField(2);
final JTextField Fieldnilai_2 = new
JTextField(2);
final JTextField Fieldrata = new
JTextField(3);
JButton tombolproses = new
JButton("Proses");
tombolproses.setMnemonic('p');
tombolproses.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent
e){
int jwb1 =
Integer.parseInt(Fieldnilai_1.getText());
int jwb2 =
Integer.parseInt(Fieldnilai_2.getText());
int rata = (jwb1+jwb2)/2;
Fieldrata.setText(Integer.toString(rata));
{
int Rata =
Integer.parseInt(Fieldrata.getText());
if (Rata>6)
JOptionPane.showMessageDialog
(null, "Lulus");
else
JOptionPane.showMessageDialog
(null, "Mengulang");
}
}
}
);
JButton tombolbersih = new
JButton("Bersih");
tombolbersih.setMnemonic('b');
tombolbersih.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent
e){
Fieldnama.setText("");
FieldSKS.setText("");
Fieldnilai_1.setText("");
Fieldnilai_2.setText("");
Fieldrata.setText("");
}
});
Container
konten;
konten
= frame.getContentPane();
konten.setLayout(new
GridBagLayout());
GridBagConstraints
pos = new GridBagConstraints();
pos.anchor=GridBagConstraints.WEST;
pos.gridx
= 5;
pos.gridy
= 5;
konten.add(lNama,pos);
pos.gridx++;
konten.add(Fieldnama,pos);
pos.gridy++;
pos.gridx
= 5;
konten.add(lSKS,pos);
pos.gridx++;
konten.add(FieldSKS,pos);
pos.gridy++;
pos.gridx
= 5;
konten.add(lNilai1,pos);
pos.gridx++;
konten.add(Fieldnilai_1,pos);
pos.gridy++;
pos.gridx
= 5;
konten.add(lNilai2,pos);
pos.gridx++;
konten.add(Fieldnilai_2,pos);
pos.gridy++;
pos.gridx
= 5;
konten.add(lRata,pos);
pos.gridx++;
konten.add(Fieldrata,pos);
pos.gridy++;
pos.gridx
= 5;
konten.add(tombolproses,pos);
pos.gridx++;
konten.add(tombolbersih,pos);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Tidak ada komentar:
Posting Komentar