Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
100
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/backgroundspacepic.jpeg").getImage());
  39.             setIconImage(image);  
  40.         //sets icon  picture                                                   
  41.         setTitle("Mips The Mouse Login");
  42.                            
  43.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.            
  45.        
  46.         pass = new JPasswordField(5);  //sets password length to 5         
  47.         pass.setEchoChar('@');   //hide characters as @ symbol
  48.         pass.addActionListener(this);    //adds action listener
  49.            
  50.         add(panel);  //adds panel to frame
  51.         btnEnter = new JButton("Enter"); //creates a button    
  52.         btnEnter.addActionListener(this);// Register the action listener.
  53.            
  54.         lblpdub = new JLabel("       Your Password: "); // label that says enter password
  55.            
  56.         panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  57.         panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  58.         panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  59.         pack(); // packs controls and
  60.            
  61.         setLocationRelativeTo(null);    // Implicit "this" if inside JFrame constructor.
  62.  
  63.         setVisible(true);// makes them visible (duh)
  64.            
  65.     }
  66.  
  67.     public void actionPerformed(ActionEvent a)
  68.     {
  69.                
  70.         Object source = a.getSource();
  71.         //char array that holds password
  72.         char[] passy = pass.getPassword();
  73.         //characters array to string
  74.         String p = new String(passy);
  75.            
  76.         //determines if user entered correct password
  77.         if(p.equals(ThePDub))
  78.         {
  79.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  80.         }
  81.         else
  82.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  83.     }
  84.            
  85.     class ImagePanel extends JPanel
  86.     {
  87.         private Image img;
  88.  
  89.         public ImagePanel(String img)
  90.         {
  91.             this(new ImageIcon(img).getImage());
  92.         }
  93.  
  94.         public ImagePanel(Image img)
  95.         {
  96.             this.img = img;
  97.             Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
  98.            
  99.         }
  100.  
  101.         public void paintComponent(Graphics g)
  102.         {
  103.             g.drawImage(img, 0, 0, null);
  104.         }
  105.  
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement