Sunday, September 25, 2016

LoginFrame

Step For Creating LoginFrame
To Create Two Class e.g.LoginFrame & Splashscreen
1. For LoginFrame

/* LoginFrame */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class LoginFrame implements ActionListener {

JFrame frame;
private  JPanel panel1;
private  JPanel panel2;
private  JPanel panel3;
private JButton loginBtn;
private JButton exitBtn;
private JLabel nameLbl;
private JLabel userLbl;
private JLabel passwordLbl;
private  JTextField userTxt;
private  JPasswordField passwordTxt;

 public String loginname;
public String loginpass;

// class Veriables
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();


public LoginFrame()
{


panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
nameLbl = new JLabel("WELCOME");

panel2 = new JPanel();
panel2.setLayout(new GridLayout(2,2));
userLbl = new JLabel("Username :");
userTxt = new JTextField(20);

passwordLbl = new JLabel("Password :");

passwordTxt = new JPasswordField(20);

panel3 = new JPanel();
panel3.setLayout(new FlowLayout());

loginBtn = new JButton("Login", new ImageIcon(LoginFrame.class.getResource("images/Key.gif")));

loginBtn.addActionListener(this);
exitBtn = new JButton("Exit", new ImageIcon(LoginFrame.class.getResource("images/Keys.gif")));

exitBtn.addActionListener(this);
panel1.add(nameLbl);
panel2.add(userLbl);
panel2.add(userTxt);
panel2.add(passwordLbl);
panel2.add(passwordTxt);
panel3.add(loginBtn);
panel3.add(exitBtn);
frame = new JFrame("Login Frame...");
frame.setSize(300,200);

Container pane = frame.getContentPane();   


pane.setLayout(new GridLayout(3,1));
pane.add(panel1);
pane.add(panel2);
pane.add(panel3);

 frame.setIconImage(new ImageIcon("images/Business.png").getImage());
frame.setResizable(false);
frame.setLocation((screen.width - 500)/2,((screen.height-350)/2));
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
            }

public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if(source.equals(loginBtn))
{
login();

else if(source.equals(exitBtn))
{
System.exit(0);
}
}

public void login()
{
loginname = userTxt.getText().trim();
loginpass = passwordTxt.getText().trim();

//write sql query
}


public static void main(String[] args)
{

 SplashScreen FormSplash = new SplashScreen();
  Thread ThFormSplash = new Thread(FormSplash);
ThFormSplash.start();
    while(!FormSplash.isShowing())
    {
      try
      {
        //Display the FormSplash for 2 seconds
        Thread.sleep(2000);
      }
      catch(InterruptedException e)
      {
      }
    }
 FormSplash.dispose();

LoginFrame frame1 = new LoginFrame();

// MainMenu menu = new MainMenu(loginname,currentdate);


}
}

 2. For SplashScreen 

   /* SplashScreen */
import javax.swing.*;
import java.awt.*;
import javax.swing.border.LineBorder;

public class SplashScreen extends JWindow implements Runnable
{
public void run()
{
JLabel SplashScreenLabel = new JLabel(new ImageIcon("pharmacy_rx.png"));
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Color cl = new Color (255,200, 120);
SplashScreenLabel.setBorder (new LineBorder (cl, 10));

getContentPane().add(SplashScreenLabel,BorderLayout.CENTER);

setSize(395,310);
setLocation((screen.width-500)/2,(screen.height-500)/2);
show();
}
}

Note
/*To add  two icon e.g.- Login & Exit Button Icon*/
/*Also to add  SplashScreen(Time) Image.*/

OUTPUT SCREEN














No comments:

Post a Comment