Random angka dan huruf biasa digunakan untuk generate password.
- Tampilan GUI Generate/Random Huruf dan Angka
dibuat dengan tool Netbeans 7.3
2. Koding Generate/Random Huruf dan Angka
package view;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Random;
import javax.swing.JOptionPane;
/**
*
* @author PC01Admin
*/
public class Password extends javax.swing.JFrame {
String out;
String h = "nama dan email harus diisi";
Random ran = new Random();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
////////////////////////////////////////
public Password() {
initComponents();
kosong();
setLocation(d.height / 2 - getHeight() / 3, d.width / 4 - getWidth() / 3);
txtpass.setEditable(false);
}
/////////////////////////////////////////////////////
private void btngenActionPerformed(java.awt.event.ActionEvent evt) {
char[] values1 = {'w','e','l','c','s','p','a','m','S','M','A','H','E','V'};
char[] values3 = {'1','2','3','4','5','6','7','8','9','0'};
String out1="";
String out2="";
String out3="";
if((txtnama.getText().equals(""))&&(txtemail.getText().equals(""))){
JOptionPane.showMessageDialog
(null,h, "Perhatian", JOptionPane.INFORMATION_MESSAGE);
}else{
for (int i=0;i<6 data-blogger-escaped-br="" data-blogger-escaped-i="">
{
int idx=ran.nextInt(values1.length);
out1+= values1[idx];
}
for (int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i="">
{
int idx=ran.nextInt(values3.length);
out2+= values3[idx];
}
out= out1.concat(out3).concat(out2);
txtpass.setText(out);
return;
}
}
////////////////////////////////////////////////////////////
private void btnclearActionPerformed(java.awt.event.ActionEvent evt) {
kosong();// TODO add your handling code here:
}
///////////////////////////////////////////////////////////
private void btnexitActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
///////////////////////////////////////////////////////////////////////////////
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info
: javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Password.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Password.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Password.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Password.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Password().setVisible(true);
}
});
}
////////////////////////////////////////////////////////////////////////
public void kosong(){
txtpass.setText("");
txtnama.setText("");
txtemail.setText("");
}
}