Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package LoginMarvin;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class MarvinEins extends JFrame implements ActionListener {
- Icon x = new ImageIcon(getClass().getResource("HalloHallo.png"));
- Container container = getContentPane();
- JLabel alter = new JLabel("Thank you for using my Software.");
- JLabel luser = new JLabel("made by Marvin");
- JLabel userLabel = new JLabel("USERNAME");
- JLabel passwordLabel = new JLabel("PASSWORD");
- JTextField userTextField = new JTextField();
- JPasswordField passwordField = new JPasswordField();
- JButton loginButton = new JButton("LOGIN");
- JButton resetButton = new JButton("RESET");
- JButton hallo = new JButton("", x);
- JCheckBox showPassword = new JCheckBox("Show Password");
- MarvinEins() {
- setLayoutManager();
- setLocationAndSize();
- addComponentsToContainer();
- addActionEvent();
- }
- public void setLayoutManager() {
- container.setLayout(null);
- }
- public void setLocationAndSize() {
- alter.setBounds(1, 1, 500, 100);
- luser.setBounds(1, 30, 500, 100);
- userLabel.setBounds(50, 150, 100, 30);
- passwordLabel.setBounds(50, 220, 100, 30);
- userTextField.setBounds(150, 150, 150, 30);
- passwordField.setBounds(150, 220, 150, 30);
- showPassword.setBounds(150, 250, 150, 30);
- loginButton.setBounds(50, 300, 100, 30);
- resetButton.setBounds(200, 300, 100, 30);
- hallo.setBounds(20, 350, 300, 200);
- }
- public void addComponentsToContainer() {
- container.add(luser);
- container.add(alter);
- container.add(userLabel);
- container.add(passwordLabel);
- container.add(userTextField);
- container.add(passwordField);
- container.add(showPassword);
- container.add(loginButton);
- container.add(resetButton);
- container.add(hallo);
- }
- public void addActionEvent() {
- loginButton.addActionListener(this);
- resetButton.addActionListener(this);
- showPassword.addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- //Coding Part of LOGIN button
- if (e.getSource() == loginButton) {
- String userText;
- String pwdText;
- userText = userTextField.getText();
- pwdText = passwordField.getText();
- if (userText.equalsIgnoreCase("Super") && pwdText.equalsIgnoreCase("Hallo")) {
- JOptionPane.showMessageDialog(this, "Login Successful");
- JFrame meinJFrame = new JFrame();
- meinJFrame.setTitle("Eingabe");
- meinJFrame.setSize(300, 150);
- JPanel panel = new JPanel();
- JLabel label = new JLabel("Eingabe");
- panel.add(label);
- // Textfeld wird erstellt
- // Text und Spaltenanzahl werden dabei direkt gesetzt
- JTextField tfName = new JTextField("", 15);
- // Schriftfarbe wird gesetzt
- tfName.setForeground(Color.black);
- // Hintergrundfarbe wird gesetzt
- tfName.setBackground(Color.white);
- // Textfeld wird unserem Panel hinzugefügt
- panel.add(tfName);
- JButton buttonOK = new JButton("OK");
- panel.add(buttonOK);
- meinJFrame.add(panel);
- meinJFrame.setVisible(true);
- } else {
- JOptionPane.showMessageDialog(this, "Invalid Username or Password");
- }
- }
- //Coding Part of RESET button
- if (e.getSource() == resetButton) {
- userTextField.setText("");
- passwordField.setText("");
- }
- //Coding Part of showPassword JCheckBox
- if (e.getSource() == showPassword) {
- if (showPassword.isSelected()) {
- passwordField.setEchoChar((char) 0);
- } else {
- passwordField.setEchoChar('*');
- }
- }
- }
- }
- package LoginMarvin;
- import java.awt.Color;
- import javax.swing.JFrame;
- public class MarvinZwei {
- public static void main(String[] a) {
- MarvinEins frame = new MarvinEins();
- frame.setTitle("Login");
- frame.setVisible(true);
- frame.setBounds(10, 10, 370, 600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setResizable(false);
- frame.getContentPane().setBackground(Color.green);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement