Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.util.Scanner;
  4. import java.awt.*;
  5. import javax.imageio.ImageIO;                    
  6. import java.awt.image.BufferedImage;    
  7. import java.io.IOException;  
  8.                 //////////////////////////////////
  9.                 //   3nriched Games Presents:   //
  10.                 //      MIPS The Mouse!!        //
  11.                 //////////////////////////////////          
  12.  
  13.  
  14. public class mipsMouseGUI extends JFrame implements ActionListener
  15.    {
  16.    
  17.     private static String ThePDub = ("mouse"); //the password
  18.     private static String p;
  19.     public static JButton btnEnter;  
  20.     JPasswordField pass;
  21.    
  22.         public mipsMouseGUI()
  23.         {
  24.         BufferedImage image = null;
  25.         try { //attempts to read picture from the folder
  26.             image = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
  27.         } catch (IOException e) {  //catches exceptions
  28.             e.printStackTrace();
  29.         }
  30.         setIconImage(image);  //sets icon picture
  31.        
  32.             setTitle("Mips The Mouse Login");
  33.            
  34.                
  35.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36.            
  37.             JPanel panel = new JPanel(); //creates a panel
  38.                         pass = new JPasswordField(5);  //sets password length to 5         
  39.  
  40.  
  41.             pass.setEchoChar('@');   //hide characters as @ symbol
  42.             pass.addActionListener(this);    //adds action listener
  43.            
  44.            
  45.             add(panel);  //adds panel to frame
  46.             JButton btnEnter = new JButton("Enter"); //creates a button    
  47.             btnEnter.addActionListener(this);// Register the action listener.
  48.            
  49.             JLabel lblpdub = new JLabel("       Your Password: "); // label that says enter password
  50.            
  51.             panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  52.             panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  53.             panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  54.             pack();                                         // packs controls and
  55.             setVisible(true);                               // makes them visible (duh)
  56.            
  57.         }
  58.  
  59.             public void actionPerformed(ActionEvent a)
  60.             {
  61.                        
  62.             //char array that holds password
  63.             char[] passy = pass.getPassword();
  64.             //characters array to string
  65.             String p = new String(passy);
  66.            
  67.             //determines if user entered correct password
  68.             if(p.equals(ThePDub))
  69.             {
  70.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  71.             }
  72.             else
  73.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  74.             }
  75.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement