import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Login extends JFrame{ //public JFrame frame; //Extends JFrame already so 'this' IS a frame public JPasswordField passwordField; public JTextField textField; public JButton blogin; public JButton btnNewUser; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Login window = new Login(); window.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Login() { initialize(); } /** * Initialize the contents of the frame. */ public void initialize() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //DO NOT forget this, the instance will continue to run if not. setLayout(null); setSize(350,300); // only added so I didn't have to expand window as often passwordField = new JPasswordField(); passwordField.setBounds(90, 114, 105, 22); add(passwordField); textField = new JTextField(); textField.setBounds(90, 79, 105, 22); add(textField); textField.setColumns(10); JLabel lblUsername = new JLabel("Username"); lblUsername.setBounds(220, 82, 76, 16); add(lblUsername); JLabel lblPassword = new JLabel("Password"); lblPassword.setBounds(220, 117, 66, 16); add(lblPassword); JButton blogin = new JButton("Login"); blogin.setBounds(144, 158, 97, 25); blogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae){ actionlogin(); } }); add(blogin); JButton btnNewUser = new JButton("New User ?"); btnNewUser.setBounds(144, 196, 110, 30); add(btnNewUser); add(blogin); add(passwordField); add(textField); } //Logincode lc = new Logincode(); public void actionlogin(){ //Scanner sc; not used Scanner scan=null; try { //sc = new Scanner(new File("Logincode.txt")); not used scan = new Scanner(new File("Change to the path where your file is located ofcourse")); //make sure to add your path } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //Scanner keyboard = new Scanner (System.in); //String inpUser = keyboard.nextLine(); String inpUser; inpUser = textField.getText(); //String inpPass = keyboard.nextLine(); String inpPass; inpPass = passwordField.getText();// gets input from user String user=""; if(scan.hasNextLine()) //added to check if there is another line to read user = scan.nextLine(); String pass=""; if(scan.hasNextLine()) pass = scan.nextLine(); // looks at selected file in scan if (inpUser.equals(user)&& inpPass.equals(pass)){ System.out.print("your login message"); }else { JOptionPane.showMessageDialog(null,"Wrong Password / Username"); } } }
How do I put a Icon in the background? Can anyone please help?
Also, can someone split this into two windows? A login window and a new User window.
The Login window would be the main one while the NEw user window would pop up after clicking on New User?
--- Update ---
ALso
Suppose the weekly hours for all employees are stored in a two dimensional array. Each row
records an employee’s seven day working hours with seven columns. Ask user how many
employees’ record they want to enter. Write a program using method concept that displays the
following:-
a. Calculate total working hours per week for each employee.
b. Calculate the average working hours for each employee.
c. Find and display the maximum and minimum working hours per week for each
employee.
d. Identify and display the maximum and minimum working hour per day among the
employee.
e. Calculate total working hours per day.
Your program also should prompt the user to enter the input again if it is invalid (0 or negative
numbers). Apply exception handling concept in your code.