Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

done #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Answers/GUI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions Answers/GUI/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Answers/GUI/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Answers/GUI/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Answers/GUI/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>GUI</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>
</dependencies>

</project>
Binary file added Answers/GUI/src/main/java/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Answers/GUI/src/main/java/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Answers/GUI/src/main/java/img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions Answers/GUI/src/main/java/org/example/Login.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.example;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

public class Login implements ActionListener {

JFrame frame;
JLabel lblUsername;
JLabel lblPassword;
JTextField txtUsername;
JPasswordField txtPassword;
JButton btnLogin;
ArrayList<String> myFile = new ArrayList<>();

public Login() {
// Initialize the frame
frame = new JFrame("Login");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(500, 300);
frame.setLayout(new GridBagLayout());
frame.getContentPane().setBackground(new Color(150, 100, 200));

// Initialize components
lblUsername = new JLabel("Username:");
lblPassword = new JLabel("Password:");

txtUsername = new JTextField(20);
txtPassword = new JPasswordField(20);

btnLogin = new JButton("Login");
btnLogin.addActionListener(this);

// Layout constraints
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;

// Add Username label and text field
gbc.gridx = 0;
gbc.gridy = 0;
frame.add(lblUsername, gbc);

gbc.gridx = 1;
gbc.gridy = 0;
frame.add(txtUsername, gbc);

// Add Password label and text field
gbc.gridx = 0;
gbc.gridy = 1;
frame.add(lblPassword, gbc);

gbc.gridx = 1;
gbc.gridy = 1;
frame.add(txtPassword, gbc);

// Add Login button
gbc.gridx = 1;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.CENTER;
frame.add(btnLogin, gbc);

// Make the frame visible
frame.setVisible(true);
}
void saveInArraylist(String Username, String Password){
try{
File file = new File("store.txt");
Scanner scan = new Scanner(file);

while (scan.hasNextLine()){
myFile.add(scan.nextLine());
}
if(myFile.contains(Username)){
if(myFile.contains(Password)){
JOptionPane.showMessageDialog(null, "You Logged in successfully", "Error", JOptionPane.INFORMATION_MESSAGE);


}else {
JOptionPane.showMessageDialog(null, "Invalid Password", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}else {
JOptionPane.showMessageDialog(null, "Invalid Email", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}catch (Exception e){
System.out.println(e);
}
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnLogin){
String username = txtUsername.getText();
String password = txtPassword.getText();
saveInArraylist(username, password);
}
}
}
75 changes: 75 additions & 0 deletions Answers/GUI/src/main/java/org/example/LoginGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.example;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginGUI extends JFrame implements ActionListener {

JFrame frame = new JFrame();

JButton signInButton = new JButton("Sign in");
JButton LogInButton = new JButton("Login");

JLabel label;
ImageIcon logoimage;

LoginGUI(){

//------------sigh in in button------------

signInButton.setBounds(70, 350, 300, 100);
signInButton.setFocusable(false);
signInButton.addActionListener(this);
signInButton.setFont(new Font(("PT serif"), Font.BOLD, 30));
signInButton.setForeground(new Color(250, 150, 200));

//------------sigh in in button------------

//------------log in in button------------
LogInButton.setBounds(400, 350, 300, 100);
LogInButton.setFocusable(false);
LogInButton.addActionListener(this);
LogInButton.setFont(new Font(("PT serif"), Font.BOLD, 30));
LogInButton.setForeground(new Color(250, 150, 200));

//------------log in in button------------

// ----------frame-----------


frame.getContentPane().setBackground(new Color(123,50,100));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Graphical-Login-Page");
frame.setSize(750, 500);
frame.setLayout(null);
frame.setVisible(true);
frame.add(signInButton);
frame.add(LogInButton);
frame.add(label);

ImageIcon icon = new ImageIcon("img.png");
frame.setIconImage(icon.getImage());
// -----------frame------------



logoimage = new ImageIcon("/Users/mohammad/IdeaProjects/GUI/src/main/java/img_1.png");
label = new JLabel(logoimage);




}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == signInButton){
SignIn signIn = new SignIn();
}
if(e.getSource() == LogInButton){
Login login = new Login();
}
}
}
12 changes: 12 additions & 0 deletions Answers/GUI/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;

import java.util.Scanner;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main{
public static void main(String[] args) {
LoginGUI loginGUI = new LoginGUI();

}
}
Loading