Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.57 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * frmLogin.java
  8.  *
  9.  * Created on May 13, 2011, 4:02:28 PM
  10.  */
  11. package view;
  12.  
  13. import controller.Player;
  14. import javax.swing.JOptionPane;
  15. import view.assets.ImageResources;
  16.  
  17. /**
  18.  *
  19.  * @author u80798860
  20.  */
  21. public class frmLogin extends Window {
  22.  
  23.     private Player player;
  24.    
  25.     public frmLogin(){
  26.         this(null);
  27.     }
  28.    
  29.     /** Creates new form frmLogin */
  30.     public frmLogin(Player player) {
  31.         super("Login");
  32.         this.player = player;
  33.         initComponents();
  34.         setIconImage(ImageResources.get().imgOrange());
  35.     }
  36.  
  37.     /** This method is called from within the constructor to
  38.      * initialize the form.
  39.      * WARNING: Do NOT modify this code. The content of this method is
  40.      * always regenerated by the Form Editor.
  41.      */
  42.     @SuppressWarnings("unchecked")
  43.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  44.     private void initComponents() {
  45.  
  46.         txtPassword = new javax.swing.JPasswordField();
  47.         lbNotRegisteredYet = new javax.swing.JLabel();
  48.         lbLoginTitle = new javax.swing.JLabel();
  49.         jLabel2 = new javax.swing.JLabel();
  50.         lbRegister = new javax.swing.JLabel();
  51.         txtUsername = new javax.swing.JTextField();
  52.         jLabel1 = new javax.swing.JLabel();
  53.         btLogin = new javax.swing.JButton();
  54.  
  55.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  56.  
  57.         lbNotRegisteredYet.setText("Not registered yet?");
  58.  
  59.         lbLoginTitle.setFont(new java.awt.Font("Tahoma", 1, 14));
  60.         lbLoginTitle.setForeground(new java.awt.Color(0, 0, 102));
  61.         lbLoginTitle.setText("Login");
  62.  
  63.         jLabel2.setText("Password");
  64.  
  65.         lbRegister.setForeground(new java.awt.Color(0, 0, 204));
  66.         lbRegister.setText("Register now!");
  67.         lbRegister.setToolTipText("");
  68.         lbRegister.addMouseListener(new java.awt.event.MouseAdapter() {
  69.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  70.                 lbRegisterMouseClicked(evt);
  71.             }
  72.         });
  73.         lbRegister.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
  74.             public void mouseMoved(java.awt.event.MouseEvent evt) {
  75.                 lbRegisterMouseMoved(evt);
  76.             }
  77.         });
  78.  
  79.         jLabel1.setText("Username");
  80.  
  81.         btLogin.setText("Login");
  82.         btLogin.addMouseListener(new java.awt.event.MouseAdapter() {
  83.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  84.                 btLoginMouseClicked(evt);
  85.             }
  86.         });
  87.  
  88.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  89.         getContentPane().setLayout(layout);
  90.         layout.setHorizontalGroup(
  91.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  92.             .addGroup(layout.createSequentialGroup()
  93.                 .addContainerGap()
  94.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95.                     .addComponent(jLabel2)
  96.                     .addComponent(jLabel1)
  97.                     .addGroup(layout.createSequentialGroup()
  98.                         .addGap(79, 79, 79)
  99.                         .addComponent(btLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
  100.                     .addGroup(layout.createSequentialGroup()
  101.                         .addComponent(lbNotRegisteredYet)
  102.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  103.                         .addComponent(lbRegister))
  104.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  105.                         .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING)
  106.                         .addComponent(txtUsername, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
  107.                     .addComponent(lbLoginTitle))
  108.                 .addContainerGap(40, Short.MAX_VALUE))
  109.         );
  110.         layout.setVerticalGroup(
  111.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  112.             .addGroup(layout.createSequentialGroup()
  113.                 .addContainerGap()
  114.                 .addComponent(lbLoginTitle)
  115.                 .addGap(18, 18, 18)
  116.                 .addComponent(jLabel1)
  117.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  118.                 .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  119.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  120.                 .addComponent(jLabel2)
  121.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  122.                 .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  123.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  124.                 .addComponent(btLogin)
  125.                 .addGap(28, 28, 28)
  126.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  127.                     .addComponent(lbNotRegisteredYet)
  128.                     .addComponent(lbRegister))
  129.                 .addContainerGap(30, Short.MAX_VALUE))
  130.         );
  131.  
  132.         pack();
  133.     }// </editor-fold>                        
  134.  
  135.     private void lbRegisterMouseClicked(java.awt.event.MouseEvent evt) {                                        
  136.         new frmRegister().setVisible(true);
  137. }                                      
  138.  
  139.     private void lbRegisterMouseMoved(java.awt.event.MouseEvent evt) {                                      
  140.        
  141. }                                    
  142.  
  143.     private void btLoginMouseClicked(java.awt.event.MouseEvent evt) {                                    
  144.         if(player == null) player = new Player();
  145.         String pw = charrArrToString(txtPassword.getPassword());
  146.         if(player.Login(txtUsername.getText(), pw)){
  147.              System.out.println("getLobbyStuff: " + player.getLobbyStuff());
  148.              System.out.println("SID: " + player.getSid());
  149.              new frmLobby(player).setVisible(true);
  150.              this.dispose();
  151.         } else {
  152.             JOptionPane.showMessageDialog(this, "Your username or password or "
  153.                     + "maybe both of them is incorrect.\nFeel free to try again.",
  154.                     "Tomato", JOptionPane.WARNING_MESSAGE,
  155.                     ImageResources.get().icoTomato());
  156.             txtPassword.setText("");
  157.         }
  158. }                                    
  159.    
  160.     /**
  161.      * @param args the command line arguments
  162.      */
  163.     public static void main(String args[]) {
  164.         java.awt.EventQueue.invokeLater(new Runnable() {
  165.  
  166.             public void run() {
  167.                 new frmLogin().setVisible(true);
  168.             }
  169.         });
  170.     }
  171.     // Variables declaration - do not modify                    
  172.     private javax.swing.JButton btLogin;
  173.     private javax.swing.JLabel jLabel1;
  174.     private javax.swing.JLabel jLabel2;
  175.     private javax.swing.JLabel lbLoginTitle;
  176.     private javax.swing.JLabel lbNotRegisteredYet;
  177.     private javax.swing.JLabel lbRegister;
  178.     private javax.swing.JPasswordField txtPassword;
  179.     private javax.swing.JTextField txtUsername;
  180.     // End of variables declaration                  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement