Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 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
  15.    {
  16.    
  17.     private static String ThePDub = ("mouse"); //the password
  18.     private static String p;
  19.     public static JButton btnEnter;  
  20.  
  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.            
  39.             JPasswordField pass = new JPasswordField(5);  //sets password length to 5
  40.             pass.setEchoChar('@');   //hide characters as @ symbol
  41.             pass.addActionListener(new EntButtonListener());    //adds action listener
  42.            
  43.            
  44.             add(panel);  //adds panel to frame
  45.             JButton btnEnter = new JButton("Enter"); //creates a button    
  46.             btnEnter.addActionListener(new EntButtonListener());// Register the action listener.
  47.            
  48.             JLabel lblpdub = new JLabel("       Your Password: "); // label that says enter password
  49.            
  50.             panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  51.             panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  52.             panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  53.             pack();                                         // packs controls and
  54.             setVisible(true);                               // makes them visible (duh)
  55.            
  56.         }
  57.        
  58.         public static class EntButtonListener implements ActionListener
  59.         {
  60.        
  61.             public void actionPerformed(ActionEvent a)
  62.             {
  63.            
  64.             JPasswordField input = (JPasswordField) a.getSource();
  65.             //char array that holds password
  66.             char[] passy = input.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.         }
  79.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement