Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 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.     JPasswordField pass;
  19.     JPanel panel;
  20.     JButton btnEnter;
  21.     JLabel lblpdub;
  22.    
  23.     public mipsMouseGUI()
  24.     {
  25.         BufferedImage image = null;
  26.            
  27.         try
  28.         {
  29.             //attempts to read picture from the folder
  30.                     image = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
  31.             }
  32.         catch (IOException e)
  33.         {  
  34.             //catches exceptions
  35.                     e.printStackTrace();
  36.             }
  37.    
  38.             ImagePanel panel = new ImagePanel(new ImageIcon("/mousepics/neonglowOnwill.png").getImage());
  39.            
  40.            
  41.             setIconImage(image);  
  42.         //sets icon  picture                                                   
  43.         setTitle("Mips The Mouse Login");
  44.                            
  45.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.        
  47.        
  48.         pass = new JPasswordField(5);  //sets password length to 5         
  49.         pass.setEchoChar('@');   //hide characters as @ symbol
  50.         pass.addActionListener(this);    //adds action listener
  51.            
  52.         add(panel);  //adds panel to frame
  53.         btnEnter = new JButton("Enter"); //creates a button    
  54.         btnEnter.addActionListener(this);// Register the action listener.
  55.            
  56.         lblpdub = new JLabel("       Your Password: "); // label that says enter password
  57.            
  58.         panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  59.         panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  60.         panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  61.         pack(); // packs controls and
  62.            
  63.         setLocationRelativeTo(null);    // Implicit "this" if inside JFrame constructor.
  64.  
  65.         setVisible(true);// makes them visible (duh)
  66.            
  67.     }
  68.  
  69.     public void actionPerformed(ActionEvent a)
  70.     {
  71.                
  72.         Object source = a.getSource();
  73.         //char array that holds password
  74.         char[] passy = pass.getPassword();
  75.         //characters array to string
  76.         String p = new String(passy);
  77.            
  78.         //determines if user entered correct password
  79.         if(p.equals(ThePDub))
  80.         {
  81.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  82.         }
  83.         else
  84.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  85.     }
  86.            
  87.     class ImagePanel extends JPanel
  88.     {
  89.         private Image img;
  90.  
  91.         public ImagePanel(String img)
  92.         {
  93.             this(new ImageIcon(img).getImage());
  94.         }
  95.  
  96.         public ImagePanel(Image img)
  97.         {
  98.             this.img = img;
  99.             Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
  100.            
  101.         }
  102.  
  103.         public void paintComponent(Graphics g)
  104.         {
  105.             g.drawImage(img, 0, 0, null);
  106.         }
  107.  
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement