Code:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JPasswordField;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JLabel lblLogin;
private JPasswordField passwordField;
private JButton btnNewButton;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Login() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblUsername = new JLabel("Username: ");
lblUsername.setBounds(12, 17, 70, 14);
contentPane.add(lblUsername);
JLabel lblPasswort = new JLabel("Passwort: ");
lblPasswort.setBounds(12, 45, 62, 14);
contentPane.add(lblPasswort);
textField = new JTextField();
textField.setBounds(84, 14, 212, 20);
contentPane.add(textField);
textField.setColumns(10);
final JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String username = textField.getText();
String passwort = passwordField.getText();
String r_username = null;
String r_passwort = null;
File localefile = new File(username);
try {
Scanner sc = new Scanner(localefile);
r_username = sc.next();
r_passwort = sc.next();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
if(r_username.equals(username) && r_passwort.equals(passwort)){
lblLogin.setText("Login success..");
lblLogin.setToolTipText("Login success");
}else{
lblLogin.setText("Login failed..");
}
}
});
btnLogin.setBounds(84, 73, 95, 23);
contentPane.add(btnLogin);
lblLogin = new JLabel("");
lblLogin.setBounds(139, 107, 105, 19);
contentPane.add(lblLogin);
passwordField = new JPasswordField();
passwordField.setBounds(84, 42, 212, 20);
contentPane.add(passwordField);
btnNewButton = new JButton("Registrieren");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Hier will ich eine andere Klasse öffnen.. Klassen name: Create_account
//Ich habe es so versucht geht aber nicht
Create_account ca = new Create_account(); // <<<<<<------ es geht nicht ! Hilfe
}
});
btnNewButton.setBounds(185, 73, 111, 23);
contentPane.add(btnNewButton);
}
}
Danke im Vorraus
