Package NISO

Source Code of NISO.LoginPanel$ML

package NISO;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.Timer;

public class LoginPanel extends JPanel implements ActionListener{
  private JTextField HostBox,PortBox,UserBox;
  private JPasswordField Pass;
  private JButton Done, Cancel;
  public String host, user, password; //<---all data input stored here
  public int port;//<---all data input stored here
  private boolean confirmed;
  JFrame frame;
 
  public LoginPanel(final JFrame frame){
    this.frame=frame;
    confirmed=false;
    setFocusable(true);
    addKeyListener(new ML());
   

    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
   
    JPanel myPanel = new JPanel();
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.LINE_AXIS));
   
    JPanel portPanel = new JPanel();
    portPanel.setLayout(new BoxLayout(portPanel, BoxLayout.LINE_AXIS));
    JPanel hostPanel = new JPanel();
    hostPanel.setLayout(new BoxLayout(hostPanel, BoxLayout.LINE_AXIS));
    JPanel userPanel = new JPanel();
    userPanel.setLayout(new BoxLayout(userPanel, BoxLayout.LINE_AXIS));
    JPanel passPanel = new JPanel();
    passPanel.setLayout(new BoxLayout(passPanel, BoxLayout.LINE_AXIS));
    JPanel okPanel = new JPanel();
    okPanel.setLayout(new BoxLayout(okPanel, BoxLayout.LINE_AXIS));
 
    myPanel.add(new JLabel("MySQL"));
    add(myPanel);
    myPanel.setBorder(BorderFactory.createEmptyBorder(6, 7, 5, 5));//creates a space before the ok :)
   
    portPanel.add(new JLabel("    Port Number :       "));
    portPanel.add(PortBox= new JTextField("3306"));
    add(portPanel);
   
    hostPanel.add(new JLabel("    Host :                      "));
    hostPanel.add(HostBox= new JTextField("localhost"));
    add(hostPanel);
   
   
    userPanel.add(new JLabel("    Username :           "));
    userPanel.add(UserBox= new JTextField("root"));
    add(userPanel);
   
    passPanel.add(new JLabel("    Password :           "));
    passPanel.add(Pass=new JPasswordField());
    add(passPanel);
   
   
    okPanel.setBorder(BorderFactory.createEmptyBorder(7, 8, 5, 5));//creates a space before the ok :)
    okPanel.add(Done= new JButton("Ok"));
    okPanel.add(Box.createRigidArea(new Dimension(50, 0)));
    okPanel.add(Cancel= new JButton("Cancel"));
    add(okPanel);
   
    PortBox.addActionListener(
         new ActionListener(){
           
            public void actionPerformed(ActionEvent event){
          //    if(confirmed){
              try{
               String p=PortBox.getText();
               port=Integer.parseInt(p);
               }catch(Exception ex){
                 System.out.print("Invalid input");
            //   }
            }
            }
          }   
    );
   
    HostBox.addActionListener(
         new ActionListener(){
           
            public void actionPerformed(ActionEvent event){
          //    if(confirmed)
                host=HostBox.getText();
            }
          }       
   
    );
 
    UserBox.addActionListener(
       
         new ActionListener(){
           
            public void actionPerformed(ActionEvent event){
          //  if(confirmed)
              user=UserBox.getText();
            }
          }   
       
    );
   
    Pass.addActionListener(
         new ActionListener(){
           
            @SuppressWarnings("deprecation")
            public void actionPerformed(ActionEvent event){
          //    if(confirmed)
                password=Pass.getText()
            }
          }   
       
    );
   
    Done.addActionListener(
        new ActionListener(){
         
          public void actionPerformed(ActionEvent event){
            if(Done.isEnabled())
            confirmed=true;
          }
        }   
       
        );
   
    Cancel.addActionListener(
       
         new ActionListener(){
           
            public void actionPerformed(ActionEvent event){
              if(Cancel.isEnabled())
                frame.dispose();
               
            }
          }   
   
    );
   
    Timer time = new Timer(5, this);
    time.start();
   
  }
 
  @Override
  public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub
  
    repaint();
  }
  public class ML implements MouseListener, KeyListener{

    @Override
    public void keyPressed(KeyEvent e) {
      // TODO Auto-generated method stub
      if(e.getKeyCode() == e.VK_ESCAPE)
       System.exit(0);
      
    }

    @Override
    public void keyReleased(KeyEvent e) {
      // TODO Auto-generated method stub
      
    }

    @Override
    public void keyTyped(KeyEvent e) {
      // TODO Auto-generated method stub
      if(e.getKeyCode() == e.VK_ESCAPE)
         System.exit(0);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
      // TODO Auto-generated method stub
    
    }

    @Override
    public void mouseEntered(MouseEvent e) {
      // TODO Auto-generated method stub
      
     
    }

    @Override
    public void mouseExited(MouseEvent e) {
      // TODO Auto-generated method stub
      
    }

    @Override
    public void mousePressed(MouseEvent e) {
      // TODO Auto-generated method stub
    
     
    }

    @Override
    public void mouseReleased(MouseEvent e) {
      // TODO Auto-generated method stub
     
    }
  }
}
TOP

Related Classes of NISO.LoginPanel$ML

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.