0% found this document useful (0 votes)
33 views3 pages

Untitled Document PDF

This Java program creates a login GUI with username and password fields. It compares the entered values to hardcoded correct credentials. If they match, it opens a new window displaying a background image. It also adds a logout button to return to the login screen.

Uploaded by

Justin Trono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Untitled Document PDF

This Java program creates a login GUI with username and password fields. It compares the entered values to hardcoded correct credentials. If they match, it opens a new window displaying a background image. It also adds a logout button to return to the login screen.

Uploaded by

Justin Trono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.awt.

BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;

public class Calanday_Login extends JFrame {

private JPanel contentPane;


private JTextField Username;
private JTextField Password;
JFrame frame1 = new JFrame("SUCCESS");

public static void main(String[] args) {


Calanday_Login frame = new Calanday_Login();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public Calanday_Login() {

setTitle("SAM LOGIN SYSTEM");


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);

Username = new JTextField();


Username.setHorizontalAlignment(SwingConstants.CENTER);
Username.setBounds(110, 26, 188, 36);
contentPane.add(Username);
Username.setColumns(10);

Password = new JTextField();


Password.setHorizontalAlignment(SwingConstants.CENTER);
Password.setColumns(10);
Password.setBounds(110, 122, 188, 36);
contentPane.add(Password);

JLabel lblNewLabel = new JLabel("Username");


lblNewLabel.setBounds(176, 73, 89, 14);
contentPane.add(lblNewLabel);

JLabel lblPassword = new JLabel("Password");


lblPassword.setBounds(176, 169, 78, 14);
contentPane.add(lblPassword);

JButton btnLogin = new JButton("Login");


btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String userField = Username.getText();
String passField = Password.getText();
String userCorrect = "AWRIBA";
String passCorrect = "SAMtheGREATEST";
boolean truthUser = userCorrect.equalsIgnoreCase(userField);
boolean truthPass = passCorrect.equalsIgnoreCase(passField);
if (truthUser&&truthPass==true) {
dispose();
newFrame();
}
else {
JOptionPane.showMessageDialog(btnLogin, "Incorrect
Input");
Username.setText("");
Password.setText("");
}
}
});
btnLogin.setBounds(302, 227, 89, 23);
contentPane.add(btnLogin);

JButton btnReset = new JButton("Reset");


btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Username.setText("");
Password.setText("");
}
});
btnReset.setBounds(57, 227, 89, 23);
contentPane.add(btnReset);
}
public void newFrame() {
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setBounds(100, 100, 1000, 750);
try {
JLabel background = new JLabel(new ImageIcon(ImageIO.read(new
File("src/SAM1.jpg"))));
background.setBounds(0, 0, frame1.getWidth(),frame1.getHeight());
frame1.getContentPane().add(background, BorderLayout.CENTER);
} catch (IOException e) {
System.out.println("Error loading background image: " + e.getMessage());
}
frame1.setVisible(true);
frame1.setLocationRelativeTo(null);
JButton logout = new JButton("Logout");
frame1.add(logout, BorderLayout.SOUTH);
logout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(logout, "Exiting");
frame1.dispose();
Calanday_Login frame = new Calanday_Login();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

}
});

}
}

You might also like