Program Identitas
Nama Anggota:
- Fahmi Imannudin
- Gina Putri van Dian
- Shabrina Habi Syarafah
Kelas: 2IA22
Matkul : Pemrograman Berbasis Objek (PBO)
Jurusan / Fakultas: Teknik Informatika / Teknologi Industri
Program ini dibuat dengan menggunakan bahasa pemrograman java, untuk menampilkan data identitas yang berisi npm, nama, alamat, dan nomor telephone. Program ini dibuat dengan menggunakan dua listing, pertama: BlurButton.java dan listing kedua: frameButton.java.
Berikut adalah rincian listing dan hasil outputnya:
LISTING PROGRAM
Listing pertama: BlurButton.java
import java.awt.image.Kernel;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import javax.swing.JButton;
@SuppressWarnings("serial")
public class BlurButton extends JButton
{
public BlurButton(String txt)
{
super(txt);
}
public void paintComponent(Graphics graph)
{
if(isEnabled())
{
super.paintComponent(graph);
return;
}
BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
super.paintComponent(bi.getGraphics());
float kernel[] = {0.10f,0.10f,0.10f,
0.10f,0.20f,0.10f,
0.10f,0.10f,0.10f
};
ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, kernel));
Image img = cop.filter(bi, null);
graph.drawImage(img,0,0,null);
}
}
Listing kedua: frameButton.java
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.ImageIcon;
import java.awt.Color;
@SuppressWarnings("serial")
public class frameButton extends JFrame
{
private JPanel contentPane;
private JButton btnRefresh;
final JButton btnBlur = new BlurButton("Simpan Blur");
private JTextField txtNPM;
private JTextField txtNama;
private JTextArea textAlamat;
private JTextField txtPhone;
private JLabel lblBg;
private JLabel lblIcon;
public frameButton()
{
super("Program Identitas");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 528, 398);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnRefresh = new JButton("Refresh");
btnRefresh.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent act)
{
btnBlur.setEnabled(isEnabled());
txtNPM.setText("");
txtNama.setText("");
textAlamat.setText("");
txtPhone.setText("");
txtNPM.requestFocus();
}
});
btnRefresh.setBounds(247, 259, 132, 44);
contentPane.add(btnRefresh);
btnBlur.setText("Tampilkan");
btnBlur.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnBlur.setEnabled(!btnBlur.isEnabled());
String npm = txtNPM.getText();
String nama = txtNama.getText();
String alamat = textAlamat.getText();
String phone = txtPhone.getText();
JOptionPane.showMessageDialog(null,"NPM : " + npm + "\n" + "Nama : " + nama + "\n" + "Alamat : " + alamat + "\n" + "Phone : " + phone,"Pesan",JOptionPane.INFORMATION_MESSAGE,new ImageIcon("src/Gambar/Pesan.png"));
}
});
btnBlur.setBounds(64, 259,155,44);
contentPane.add(btnBlur);
JLabel lblNpm = new JLabel("NPM : ");
lblNpm.setForeground(new Color(55, 55, 55));
lblNpm.setBounds(12, 12, 70, 15);
contentPane.add(lblNpm);
JLabel lblNama = new JLabel("Nama : ");
lblNama.setForeground(new Color(55, 55, 55));
lblNama.setBounds(12, 59, 70, 15);
contentPane.add(lblNama);
JLabel lblAlamat = new JLabel("Alamat : ");
lblAlamat.setForeground(new Color(55, 55, 55));
lblAlamat.setBounds(12, 103, 70, 15);
contentPane.add(lblAlamat);
JLabel lblPhone = new JLabel("Phone : ");
lblPhone.setForeground(new Color(55, 55, 55));
lblPhone.setBounds(12, 210, 70, 15);
contentPane.add(lblPhone);
txtNPM = new JTextField();
txtNPM.setBounds(82, 10, 155, 26);
contentPane.add(txtNPM);
txtNPM.setColumns(10);
txtNama = new JTextField();
txtNama.setBounds(82, 57, 269, 26);
contentPane.add(txtNama);
txtNama.setColumns(10);
textAlamat = new JTextArea();
textAlamat.setBounds(82, 103, 269, 95);
contentPane.add(textAlamat);
txtPhone = new JTextField();
txtPhone.setBounds(82, 210, 155, 26);
contentPane.add(txtPhone);
txtPhone.setColumns(10);
lblIcon = new JLabel("");
lblIcon.setBounds(369, 59, 132, 122);
contentPane.add(lblIcon);
lblBg = new JLabel("");
lblBg.setBounds(0, 0, 526, 371);
contentPane.add(lblBg);
setLocationRelativeTo(null);
}
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
frameButton frame = new frameButton();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
}
OUTPUT PROGRAM
Untuk melakukan running, pertama jalankan dulu listing pertama yaitu BlurButton.java, setelah itu baru jalankan listing kedua yaitu frameButton.java, contoh seperti gambar di bawah ini:
Maka akan muncul frame seperti gambar di bawah ini:
Setelah isi semua data, klik tombol Tampilkan. Maka akan muncul frame baru, tampilan seperti gambar dibawah ini:
Terima Kasih.
Mantapa.. izin coba juga dengan source code nya >.<
BalasHapusIya silahkan, makasih sudah membaca :)
BalasHapus