Anda di halaman 1dari 2

Rubah nama variable dalam form registrasi.

Text field nik dan nama beri nama variable:


NIK = txtNik
Nama Lengkap = txtNama

Button foto rubah menjadi = btnFoto

Kemudian tuliskan Source code dibawah ini:


if (txtNik.getText().equals("") || txtNama.getText().equals("")) {
JOptionPane.showMessageDialog(null, "NIK dan Nama tidak boleh kosong!!");
}else{
try {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
ImageIcon icon = new ImageIcon(f.toString());
Image img = icon.getImage().getScaledInstance(lblfoto.getWidth(),
lblfoto.getHeight(),
Image.SCALE_DEFAULT);
ImageIcon ic = new ImageIcon(img);
lblfoto.setIcon(ic);
this.filename = f.getAbsolutePath();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
Button Daftar rubah variable menjadi btnDaftar
Tuliskan Source code dibawah ini:
try {
String newpath = "src/upload";
File directory = new File(newpath);
if (!directory.exists()) {
directory.mkdirs();
}
File fileawal = null;
File fileakhir = null;
String ext = this.filename.substring(filename.lastIndexOf('.')+1);
fileawal = new File(filename);
fileakhir = new File(newpath+"/"+txtNik.getText()+"."+ext);
System.out.println(fileakhir);

user u = new user(txtNik.getText(), txtNama.getText(), fileakhir.toString());


db.saveDataUser(u);
JOptionPane.showMessageDialog(null, "Akun sudah terdaftar, silahkan
kembali login");
Files.copy(fileawal.toPath(), fileakhir.toPath());
login l = new login();
l.setVisible(true);
this.setVisible(false);

} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}

Anda mungkin juga menyukai