Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 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. import java.awt.Image;
  10. import javax.swing.ImageIcon;  
  11. //////////////////////////////////
  12. //   3nriched Games Presents:   //
  13. //      MIPS The Mouse!!        //
  14. //////////////////////////////////          
  15.  
  16.  
  17. class BGPanel extends JPanel
  18. {
  19.    private Image img;
  20.  
  21.    BGPanel(BufferedImage i)
  22.    {
  23.       img = i;
  24.       setPreferredSize(new Dimension(img.getWidth(this), img.getHeight(this)));
  25.    }
  26.    
  27.    @Override
  28.    public void paintComponent(Graphics g)
  29.    {
  30.       super.paintComponent(g);
  31.       g.drawImage(img, 0, 0, this);
  32.    }
  33. }
  34.  
  35. public class mipsMouseGUI extends JFrame implements ActionListener
  36. {
  37.     JPasswordField pass;
  38.  
  39.     public mipsMouseGUI()
  40.     {
  41.        
  42.        
  43.       ImageIcon image1 = new ImageIcon("/mousepics/backgroundspacepic.jpeg");
  44.       ImageIcon image2 = new ImageIcon("/mousepics/mousepic.png");
  45.      
  46.      
  47.       BGPanel panel = new BGPanel(image1);
  48.      
  49.         add(panel);
  50.  
  51.         this.setIconImage(image2.getImage());
  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