Advertisement
Guest User

Untitled

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