Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.*;
- import java.util.Scanner;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Image;
- import java.awt.Insets;
- import java.io.File;
- import javax.imageio.ImageIO;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import javax.swing.border.LineBorder;
- //////////////////////////////////
- // 3nriched Games Presents: //
- // MIPS The Mouse!! //
- //////////////////////////////////
- public class mipsMouseGUI extends JFrame implements ActionListener
- {
- Container con = null;
- private static String ThePDub = ("mouse"); //the password
- JPasswordField pass;
- JButton btnEnter;
- JPanel panel;
- JLabel lblpdub;
- public mipsMouseGUI()
- {
- BufferedImage image = null;
- try
- {
- //attempts to read picture from the folder
- image = ImageIO.read(getClass().getResource("/mousepics/mousepic.png"));
- }
- catch (IOException e)
- {
- //catches exceptions
- e.printStackTrace();
- }
- setTitle("Mips The Mouse Login");
- panel = new JPanel();
- setIconImage(image);
- //sets icon picture
- con = getContentPane();
- con.setLayout(null);
- ImageIcon imh = new ImageIcon("image.jpg");
- setSize(imh.getIconWidth(), imh.getIconHeight());
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- pass = new JPasswordField(5); //sets password length to 5
- pass.setEchoChar('@'); //hide characters as @ symbol
- pass.addActionListener(this); //adds action listener
- add(panel); //adds panel to frame
- btnEnter.addActionListener(this);// Register the action listener.
- panel.add(pass, BorderLayout.CENTER); // to panel and sets location
- panel.add(btnEnter, BorderLayout.CENTER); //adds button to panel
- pack(); // packs controls and
- setLocationRelativeTo(null); // Implicit "this" if inside JFrame constructor.
- setVisible(true);// makes them visible (duh)
- con.add(panel);
- panel.setBounds(0, 0, imh.getIconWidth(), imh.getIconHeight());
- GridBagLayout layout = new GridBagLayout();
- JPanel panelContent = new JPanel(layout);
- GridBagConstraints gc = new GridBagConstraints();
- gc.insets = new Insets(3, 3, 3, 3);
- gc.gridx = 1;
- gc.gridy = 1;
- lblpdub = new JLabel(" Your Password: "); // label that says enter password
- panelContent.add(lblpdub, gc);
- gc.gridx = 2;
- gc.gridy = 1;
- JTextField txtName = new JTextField(10);
- panelContent.add(txtName, gc);
- gc.insets = new Insets(3, 3, 3, 3);
- gc.gridx = 1;
- gc.gridy = 2;
- gc.gridwidth = 2;
- JButton btn = new JButton("Login");
- panelContent.add(btnEnter, gc);
- panelContent.setBackground(Color.GRAY);
- panelContent.setBorder(new LineBorder(Color.WHITE));
- panel.add(panelContent);
- panel.setLayout(new FlowLayout(FlowLayout.CENTER, 150, 200));
- setResizable(false);
- }
- public void actionPerformed(ActionEvent a)
- {
- Object source = a.getSource();
- //char array that holds password
- char[] passy = pass.getPassword();
- //characters array to string
- String p = new String(passy);
- //determines if user entered correct password
- if(p.equals(ThePDub))
- {
- JOptionPane.showMessageDialog(null, "Welcome beta user: USERNAME.");
- }
- else
- JOptionPane.showMessageDialog(null, "You have enter an incorrect password. Please try again.");
- }
- public void paintComponent(Graphics g)
- {
- Image img = new ImageIcon("backgroundspacepic.jpeg").getImage();
- Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
- setPreferredSize(size);
- setMinimumSize(size);
- setMaximumSize(size);
- setSize(size);
- setLayout(null);
- g.drawImage(img, 0, 0, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement