import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 17.11.2007
* @author
*/
public class PWgen extends JFrame {
// Anfang Variablen
char[] abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0',' ' };
int az=0;
private JLabel jLabel1 = new JLabel();
private JTextField zeichen = new JTextField();
private JButton gen = new JButton();
private JScrollPane jScrollPaneausgabe = new JScrollPane();
private JTextArea ausgabe = new JTextArea("");
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
// Ende Variablen
public PWgen(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); }
});
int frameWidth = 289;
int frameHeight = 272;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
jLabel1.setBounds(88, 72, 94, 16);
jLabel1.setText("Anzahl Zeichen:");
jLabel1.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel1);
zeichen.setBounds(16, 104, 249, 24);
zeichen.setText("");
cp.add(zeichen);
gen.setBounds(40, 136, 203, 25);
gen.setText("Gief passw0rd!");
cp.add(gen);
gen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
genActionPerformed(evt);
}
});
jScrollPaneausgabe.setBounds(16, 176, 249, 41);
ausgabe.setText("");
jScrollPaneausgabe.setViewportView(ausgabe);
cp.add(jScrollPaneausgabe);
jLabel2.setBounds(88, 8, 128, 29);
jLabel2.setText("M.K.H.P.G.");
jLabel2.setFont (new Font("MS Sans Serif", Font.BOLD, 21));
cp.add(jLabel2);
jLabel3.setBounds(16, 40, 248, 13);
jLabel3.setText("Mein kleiner handlicher Passwort Generator");
jLabel3.setFont (new Font("MS Sans Serif", Font.BOLD, 11));
cp.add(jLabel3);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
// Anfang Ereignisprozeduren
public void genActionPerformed(ActionEvent evt) {
try{
az=Integer.parseInt(zeichen.getText());
char[] wort=new char[az];
for(int i=0;i<az;i++){
wort[i]=abc[(int)(Math.random()*62)];
}
ausgabe.setText("");
for(int j=0;j<az;j++){
ausgabe.append(""+wort[j]);
}
}
catch(Exception e){
if(az<0){
JOptionPane.showMessageDialog(this, "Nur positive Zahlen!", "Fehler!", JOptionPane.ERROR_MESSAGE);
}
}
}
public void error1ShowMessageDialog() {
JOptionPane.showMessageDialog(this, "Nur positive Zahlen!", "Fehler!", JOptionPane.ERROR_MESSAGE);
}
// Ende Ereignisprozeduren
public static void main(String[] args) {
new PWgen("M.K.H.P.G.");
}
}