Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 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.         BufferedImage image1 = null;
  42.        
  43.        
  44.         try {
  45.          image1 = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
  46.          
  47.       }
  48.         catch (IOException e) {
  49.          e.printStackTrace();
  50.       }
  51.      
  52.       ImageIcon image2 = new ImageIcon("/mousepics/backgroundspacepic.jpeg");
  53.       BGPanel panel = new BGPanel(image1);
  54.      
  55.         add(panel);
  56.  
  57.         setIconImage(image2);
  58.         setTitle("Mips The Mouse Login");
  59.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  60.        
  61.       pass = new JPasswordField(5);  //sets password length to 5           
  62.         pass.setEchoChar('@');   //hide characters as @ symbol
  63.         pass.addActionListener(this);    //adds action listener
  64.  
  65.         JButton btnEnter = new JButton("Enter"); //creates a button    
  66.         btnEnter.addActionListener(this);// Register the action listener.
  67.  
  68.         JLabel lblpdub = new JLabel("       Your Password: ");
  69.  
  70.         panel.add(lblpdub, BorderLayout.CENTER);//  adds label and inputbox
  71.         panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  72.         panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  73.  
  74.         pack(); // packs controls and
  75.  
  76.         setLocationRelativeTo(null);    // Implicit "this" if inside JFrame constructor.
  77.  
  78.         setVisible(true);
  79.     }
  80.  
  81.     public void actionPerformed(ActionEvent a)
  82.     {
  83.         Object source = a.getSource();
  84.         char[] passy = pass.getPassword();
  85.         String p = new String(passy);
  86.  
  87.         //determines if user entered correct password
  88.         if (p.equals("mouse"))
  89.         {
  90.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  91.         }
  92.         else
  93.       {
  94.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  95.       }
  96.     }
  97.  
  98.    
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement