Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Jaune Pendragons QUestions....

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Jaune Pendragons QUestions....

    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.
    Last edited by Jaune Pendragon; June 12th, 2019 at 11:31 PM. Reason: Want to add something to it.

  2. #2
    Junior Member
    Join Date
    Jun 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Jaune Pendragons Java Questions

    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.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jaune Pendragons QUestions....

    Duplicate code merged.

    --- Update ---

    Mixing a GUI with keyboard input is really a bad idea. All interactions should be in the same place either keyboard or a GUI.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Jaune Pendragons QUestions....

    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.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Jaune Pendragons QUestions....

    Do you have any specific java programming questions?

    Just posting your assignment is not going to get anyone to write the code for you.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. little questions
    By bpe in forum Java Theory & Questions
    Replies: 3
    Last Post: September 19th, 2013, 03:52 AM
  2. questions
    By fahid in forum Java Theory & Questions
    Replies: 1
    Last Post: December 5th, 2012, 04:42 AM
  3. List of my Java3D Questions, and Proguard questions
    By Zachary1234 in forum Java SE APIs
    Replies: 0
    Last Post: November 16th, 2012, 09:40 PM
  4. Need help with some questions!
    By goha14 in forum Java Theory & Questions
    Replies: 6
    Last Post: March 27th, 2012, 08:01 PM
  5. [SOLVED] Some serious questions,
    By Time in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 17th, 2010, 02:52 AM

Tags for this Thread