Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.util.Scanner;
  4. import java.awt.Color;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.FlowLayout;
  8. import java.awt.Graphics;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.GridBagLayout;
  11. import java.awt.Image;
  12. import java.awt.Insets;
  13. import java.io.File;
  14. import javax.imageio.ImageIO;                    
  15. import java.awt.image.BufferedImage;    
  16. import java.io.IOException;  
  17. import javax.swing.border.LineBorder;
  18.  
  19.                 //////////////////////////////////
  20.                 //   3nriched Games Presents:   //
  21.                 //      MIPS The Mouse!!        //
  22.                 //////////////////////////////////          
  23.  
  24.  
  25.   public class mipsMouseGUI extends JFrame implements ActionListener
  26. {
  27.    
  28.     Container con = null;
  29.     private static String ThePDub = ("mouse"); //the password
  30.     JPasswordField pass;
  31.     JButton btnEnter;
  32.     JPanel panel;
  33.     JLabel lblpdub;
  34.    
  35.     public mipsMouseGUI()
  36.     {
  37.         BufferedImage image = null;
  38.            
  39.         try
  40.         {
  41.             //attempts to read picture from the folder
  42.                     image = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
  43.             }
  44.         catch (IOException e)
  45.         {  
  46.             //catches exceptions
  47.                     e.printStackTrace();
  48.             }
  49.             setTitle("Mips The Mouse Login");
  50.             panel = new JPanel();
  51.            
  52.            
  53.             setIconImage(image);  
  54.         //sets icon  picture   
  55.              con = getContentPane();
  56.              con.setLayout(null);
  57.               ImageIcon imh = new ImageIcon("image.jpg");
  58.         setSize(imh.getIconWidth(), imh.getIconHeight());
  59.                    
  60.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  61.        
  62.        
  63.         pass = new JPasswordField(5);  //sets password length to 5         
  64.         pass.setEchoChar('@');   //hide characters as @ symbol
  65.         pass.addActionListener(this);    //adds action listener
  66.            
  67.         add(panel);  //adds panel to frame
  68.                
  69.         btnEnter.addActionListener(this);// Register the action listener.
  70.            
  71.        
  72.         panel.add(pass, BorderLayout.CENTER);   // to panel and sets location
  73.         panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
  74.          
  75.        
  76.         pack(); // packs controls and
  77.            
  78.         setLocationRelativeTo(null);    // Implicit "this" if inside JFrame constructor.
  79.        
  80.         setVisible(true);// makes them visible (duh)
  81.            
  82.              con.add(panel);
  83.         panel.setBounds(0, 0, imh.getIconWidth(), imh.getIconHeight());
  84.            
  85.             GridBagLayout layout = new GridBagLayout();
  86.        
  87.         JPanel panelContent = new JPanel(layout);
  88.         GridBagConstraints gc = new GridBagConstraints();
  89.  
  90.         gc.insets = new Insets(3, 3, 3, 3);
  91.         gc.gridx = 1;
  92.         gc.gridy = 1;
  93.        
  94.         lblpdub = new JLabel("       Your Password: "); // label that says enter password                      
  95.         panelContent.add(lblpdub, gc);
  96.        
  97.        
  98.         gc.gridx = 2;
  99.         gc.gridy = 1;
  100.        
  101.         JTextField txtName = new JTextField(10);
  102.         panelContent.add(txtName, gc);
  103.        
  104.         gc.insets = new Insets(3, 3, 3, 3);
  105.         gc.gridx = 1;
  106.         gc.gridy = 2;
  107.         gc.gridwidth = 2;
  108.  
  109.         JButton btn = new JButton("Login");
  110.         panelContent.add(btnEnter, gc);
  111.         panelContent.setBackground(Color.GRAY);
  112.         panelContent.setBorder(new LineBorder(Color.WHITE));
  113.        
  114.         panel.add(panelContent);
  115.        
  116.         panel.setLayout(new FlowLayout(FlowLayout.CENTER, 150, 200));
  117.        
  118.         setResizable(false);
  119.     }
  120.  
  121.     public void actionPerformed(ActionEvent a)
  122.     {
  123.                
  124.         Object source = a.getSource();
  125.         //char array that holds password
  126.         char[] passy = pass.getPassword();
  127.         //characters array to string
  128.         String p = new String(passy);
  129.            
  130.         //determines if user entered correct password
  131.         if(p.equals(ThePDub))
  132.         {
  133.             JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
  134.         }
  135.         else
  136.             JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
  137.     }
  138.            
  139.    
  140.  
  141.         public void paintComponent(Graphics g)
  142.         {
  143.            
  144.              Image img = new ImageIcon("backgroundspacepic.jpeg").getImage();
  145.                 Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
  146.                 setPreferredSize(size);
  147.                 setMinimumSize(size);
  148.                 setMaximumSize(size);
  149.                 setSize(size);
  150.                 setLayout(null);
  151.             g.drawImage(img, 0, 0, null);
  152.         }
  153.  
  154.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement