Tugas Pemrograman visual
Dosen : Nahot Frastian, M.Kom
Nurohman
201343500091
S6A
Universitas Indraprasta
1.a
import javax.swing.*;
import java.awt.event.*;
class Tugas1a extends JFrame implements ActionListener{
JLabel judul=new JLabel("Data Identitas Anda");
JLabel nama=new JLabel("Nama");
JTextField txtnama=new JTextField();
JLabel alamat=new JLabel("Alamat");
JTextField txtalamat=new JTextField();
JLabel jk=new JLabel("Jenis Kelamin");
JRadioButton laki=new JRadioButton("laki");
JRadioButton perempuan=new JRadioButton("Perempuan");
JButton ok=new JButton("OK");
JButton cancel=new JButton("Cancel");
Tugas1a(){
setTitle("Tugas 1a");
judul.setBounds(100,20,200,20);
nama.setBounds(10,70,100,20);
txtnama.setBounds(120,70,200,20);
jk.setBounds(10,100,100,20);
laki.setBounds(120,100,120,20);
perempuan.setBounds(220,100,120,20);
alamat.setBounds(10,130,100,20);
txtalamat.setBounds(120,130,200,20);
ok.setBounds(20,200,100,20);
cancel.setBounds(230,200,100,20);
add(judul);
add(nama);
add(jk);
add(alamat);
add(laki);
add(perempuan);
add(txtnama);
add(txtalamat);
add(ok);
add(cancel);
ok.addActionListener(this);
cancel.addActionListener(this);
setSize(400,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==ok){
if(txtnama.getText().equals("Nurohman")&&
txtalamat.getText().equals("Condet")){
javax.swing.JOptionPane.showMessageDialog(null,"Nurohman\nLaki-laki\nCondet","Message",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
else{
javax.swing.JOptionPane.showMessageDialog(null,"User Tidak dikenali","Kesalahan Sistem",
javax.swing.JOptionPane.ERROR_MESSAGE);
txtnama.setText("");
txtnama.requestFocus();
}
}
else if(e.getSource()==cancel)
{
System.exit(0);
}
}
public static void main (String [] Nurohman_201343500091){
Tugas1a f3=new Tugas1a();
}
}
output :
1.b
import javax.swing.*;
import java.awt.event.*;
class Tugas1b extends JFrame implements ActionListener{
JLabel judul=new JLabel("Data Identitas Anda");
JLabel nama=new JLabel("Nama");
JTextField txtnama=new JTextField();
JLabel jk=new JLabel("Jenis Kelamin");
JRadioButton laki=new JRadioButton("laki");
JRadioButton perempuan=new JRadioButton("Perempuan");
JLabel alamat=new JLabel("Alamat");
JTextField txtalamat=new JTextField();
JLabel matakuliah=new JLabel("Mata kuliah");
JTextField txtmatakuliah=new JTextField();
JLabel namadosen=new JLabel("Nama Dosen");
JTextField txtnamadosen=new JTextField();
JLabel programstudi=new JLabel("Program Studi");
JTextField txtprogramstudi=new JTextField();
JLabel universitas=new JLabel("Universitas");
JTextField txtuniversitas=new JTextField();
JButton ok=new JButton("OK");
JButton cancel=new JButton("Cancel");
Tugas1b(){
setTitle("Tugas 1a");
judul.setBounds(100,20,200,20);
nama.setBounds(10,70,100,20);
txtnama.setBounds(120,70,200,20);
jk.setBounds(10,100,100,20);
laki.setBounds(120,100,120,20);
perempuan.setBounds(220,100,120,20);
alamat.setBounds(10,130,100,20);
txtalamat.setBounds(120,130,200,20);
matakuliah.setBounds(10,160,100,20);
txtmatakuliah.setBounds(120,160,200,20);
namadosen.setBounds(10,190,100,20);
txtnamadosen.setBounds(120,190,200,20);
programstudi.setBounds(10,220,100,20);
txtprogramstudi.setBounds(120,220,200,20);
universitas.setBounds(10,250,100,20);
txtuniversitas.setBounds(120,250,200,20);
ok.setBounds(20,300,100,20);
cancel.setBounds(230,300,100,20);
add(judul);
add(nama); add(alamat);
add(jk); add(matakuliah);
add(alamat); add(namadosen);
add(laki); add(programstudi);
add(perempuan); add(universitas);
add(ok); add(cancel);
add(txtnama);
add(jk); add(txtmatakuliah);
add(txtalamat); add(txtnamadosen);
add(laki); add(txtprogramstudi);
add(perempuan); add(txtuniversitas);
ok.addActionListener(this);
cancel.addActionListener(this);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==ok){
javax.swing.JOptionPane.showMessageDialog
(null,"Nurohman\nLaki-laki\nCondet\nPemrograman Visual\nNahot Frastian, M.Kom\nTeknik Informatika\nIndraprasta PGRI","Message",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
else if (e.getSource()==cancel)
{
System.exit(0);
}
}
public static void main (String [] Nurohman_201343500091_S6A){
Tugas1b f3=new Tugas1b();
}
}
output:
2.
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Tugas2 extends JFrame implements ActionListener {
double rupiah,dolar,ringgit,hasil;
String konversi,konversi2;
public Tugas2() {
setSize(430, 420);
setVisible(true);
setLayout(null);
lbljudul.setBounds(130,20,200,20);
lblrupiah.setBounds(30,50,100,20);
txtrupiah.setBounds (240,50,150,20);
txtdolar.setBounds (240,110,150,20);
txtringgit.setBounds (240,140,150,20);
txtyen.setBounds (240,170,150,20);
txtriyal.setBounds (240,200,150,20);
txtyuan.setBounds (240,230,150,20);
txtsingapura.setBounds (240,260,150,20);
txthongkong.setBounds (240,290,150,20);
btndolar.setBounds (20,110,150,20);
btnringgit.setBounds (20,140,150,20);
btnyen.setBounds (20,170,150,20);
btnriyal.setBounds (20,200,150,20);
btnyuan.setBounds (20,230,150,20);
btnsingapura.setBounds (20,260,150,20);
btnhongkong.setBounds (20,290,150,20);
btnbersih.setBounds (165,350,80,20);
setTitle("Konversi Mata Uang");
add(lbljudul); add(lblrupiah);
add(txtdolar); add(txtrupiah);
add(txtringgit); add(txtyen);
add(txtriyal); add(btndolar);
add(btnringgit); add(btnbersih);
add(btnyen); add(btnriyal);
add(btnyuan); add(txtyuan);
add(btnsingapura); add(txtsingapura);
add(btnhongkong); add(txthongkong);
btnringgit.addActionListener(this);
btndolar.addActionListener(this);
btnyen.addActionListener(this);
btnriyal.addActionListener(this);
btnyuan.addActionListener(this);
btnsingapura.addActionListener(this);
btnhongkong.addActionListener(this);
btnbersih.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource() == btndolar)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/13000;
konversi=String.valueOf(hasil);
txtdolar.setText(konversi);
}
{ if(e.getSource() == btnringgit)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/3300;
konversi=String.valueOf(hasil);
txtringgit.setText(konversi);
}
{ if(e.getSource() == btnyen)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/120;
konversi=String.valueOf(hasil);
txtyen.setText(konversi);
}
{ if(e.getSource() == btnriyal)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/3000;
konversi=String.valueOf(hasil);
txtriyal.setText(konversi);
}
{ if(e.getSource() == btnyuan)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/1900;
konversi=String.valueOf(hasil);
txtyuan.setText(konversi);
}
{ if(e.getSource() == btnsingapura)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/9000;
konversi=String.valueOf(hasil);
txtsingapura.setText(konversi);
}
{ if(e.getSource() == btnhongkong)
{ rupiah=Double.valueOf(txtrupiah.getText());
hasil=rupiah/1600;
konversi=String.valueOf(hasil);
txthongkong.setText(konversi);
}
}
}
}}
{ if(e.getSource() == btnbersih)
{ txtrupiah.setText("");
txtdolar.setText("");
txtringgit.setText("");
txtyen.setText("");
txtriyal.setText("");
txtyuan.setText("");
txtsingapura.setText("");
txthongkong.setText("");
}
}}
}}
public static void main(String[] Nurohman_201343500091_S6A)
{
new Tugas2();
}
JLabel lbljudul = new JLabel ("KONVERSI MATA UANG");
JLabel lblrupiah = new JLabel ("Jumlah rupiah");
JTextField txtrupiah = new JTextField();
JTextField txtdolar = new JTextField();
JTextField txtringgit = new JTextField();
JTextField txtyen = new JTextField();
JTextField txtriyal = new JTextField();
JTextField txtyuan = new JTextField();
JTextField txtsingapura = new JTextField();
JTextField txthongkong = new JTextField();
JButton btndolar = new JButton("US Dollar");
JButton btnringgit = new JButton(" Malaysia Ringgit");
JButton btnyen = new JButton("Japan Yen");
JButton btnriyal = new JButton("Saudi Real");
JButton btnyuan = new JButton("Cina Yuan");
JButton btnsingapura = new JButton("Singapura Dollar");
JButton btnhongkong = new JButton("Hongkong Dollar");
JButton btnbersih = new JButton("Clear");
}
output :
0 Comments