Advertisement
Guest User

Untitled

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