Advertisement
Guest User

Untitled

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