Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 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.     JPanel panel;
  22.     JButton btnEnter;
  23.     JLabel lblpdub;
  24.    
  25.         public mipsMouseGUI()
  26.         {
  27.         BufferedImage image = null;
  28.         try { //attempts to read picture from the folder
  29.             image = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
  30.         } catch (IOException e) {  //catches exceptions
  31.             e.printStackTrace();
  32.         }
  33.         setIconImage(image);  //sets icon picture
  34.        
  35.             setTitle("Mips The Mouse Login");
  36.                            
  37.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  38.            
  39.             panel = new JPanel(); //creates a panel
  40.                         pass = new JPasswordField(5);  //sets password length to 5         
  41.  
  42.  
  43.             pass.setEchoChar('@');   //hide characters as @ symbol
  44.             pass.addActionListener(this);    //adds action listener
  45.            
  46.            
  47.             add(panel);  //adds panel to frame
  48.             btnEnter = new JButton("Enter"); //creates a button    
  49.             btnEnter.addActionListener(this);// Register the action listener.
  50.            
  51.             lblpdub = new JLabel("       Your Password: "); // label that says enter password
  52.            
  53.             panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  54.             panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  55.             panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  56.             pack();                                         // packs controls and
  57.             setVisible(true);                               // makes them visible (duh)
  58.            
  59.         }
  60.  
  61.             public void actionPerformed(ActionEvent a)
  62.             {
  63.                
  64.                 Object source = a.getSource();
  65.             //char array that holds password
  66.             char[] passy = pass.getPassword();
  67.             //characters array to string
  68.             String p = new String(passy);
  69.            
  70.             //determines if user entered correct password
  71.             if(p.equals(ThePDub))
  72.             {
  73.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  74.             }
  75.             else
  76.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  77.             }
  78.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement