import javax.swing.* ;
import javax.swing.JOptionPane ;
import java.awt.event.* ;
import java.awt.* ;
import java.net.* ;
import java.io.* ;
import java.awt.Component ;
/* the main client class */
class Client implements ActionListener, MouseMotionListener, MouseListener{
/* the graphical elements all in one */
JFrame wClient = null ;
JLabel lblUser = null ;
JTextField txtUser = null ;
JLabel lblPassword = null ;
JPasswordField txtPassword = null ;
JButton cmdLogin = null ;
JCheckBox chkRemember = null ;
JOptionPane j = new JOptionPane() ;
JLabel lblSignUp = null ;
JLabel lblNoAccount = null ;
public Client(){
wClient = new JFrame("Unicorn Mail Service") ;
wClient.setLayout(null) ;
wClient.setSize(710, 710) ;
wClient.addMouseMotionListener(this) ;
drawLogin() ;
wClient.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
wClient.setVisible(true) ;
}
private void drawLogin(){
lblUser = new JLabel("User Name :") ;
lblUser.setBounds(350, 10, 75, 25 ) ;
txtUser = new JTextField(15) ;
txtUser.setBounds(425, 10, 100, 25) ;
lblPassword = new JLabel("Password :") ;
lblPassword.setBounds(530, 10, 65, 25 ) ;
txtPassword = new JPasswordField(15) ;
txtPassword.setBounds(600, 10, 100, 25 ) ;
cmdLogin = new JButton("Login") ;
cmdLogin.setBounds(605, 40, 70, 25) ;
cmdLogin.addActionListener(this) ;
chkRemember = new JCheckBox("Remember Me ?") ;
chkRemember.setBounds(350, 40, 120, 25) ;
lblNoAccount = new JLabel("Don't Have an Account ??") ;
lblNoAccount.setBounds(350, 80, 150, 25) ;
lblSignUp = new JLabel("Sign up Now !!") ;
lblSignUp.setBounds(500, 80, 150, 25) ;
lblSignUp.addMouseMotionListener(this) ;
lblSignUp.addMouseListener(this) ;
wClient.add(lblUser) ;
wClient.add(lblPassword) ;
wClient.add(txtUser) ;
wClient.add(txtPassword) ;
wClient.add(cmdLogin) ;
wClient.add(chkRemember) ;
wClient.add(lblNoAccount) ;
wClient.add(lblSignUp) ;
}
/* the action listener methods */
public void actionPerformed(ActionEvent e){
if (e.getSource() == cmdLogin){
String user = txtUser.getText() ;
String pass = txtPassword.getText() ;
if (user.equals(""))
j.showMessageDialog(null, "User Name Missing", "Unicorn", j.ERROR_MESSAGE) ;
if (pass.equals(""))
j.showMessageDialog(null, "Password Name Missing", "Unicorn", j.ERROR_MESSAGE) ;
return ;
}
}
/* The mouse motion listener methods */
public void mouseMoved(MouseEvent e){
if (e.getSource() == lblSignUp){
lblSignUp.setFont(new Font("Consolas", Font.ITALIC, 14)) ;
lblSignUp.setForeground(new Color(0, 0, 128)) ;
}else{
lblSignUp.setFont(new Font("Arial", Font.BOLD, 12)) ;
lblSignUp.setForeground(new Color(0, 0, 0)) ;
}
}
public void mouseDragged(MouseEvent e){
}
/* the mouse listener methods */
public void mouseClicked(MouseEvent e){
if (e.getSource() == lblSignUp){
Component [] c = wClient.getComponents() ;
for (int i = 0 ; i < c.length ; i++)
wClient.remove(c[i]) ;
wClient.setVisible(false) ;
wClient.setVisible(true) ;
//wClient.paint(wClient.getGraphics()) ;
//wClient.paint(wClient.getGraphics()) ;
//wClient.validate() ;
//wClient.repaint() ;
//wClient.repaint(1000, 0, 0, 710, 710) ;
}
}
public void mouseExited(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
}
class UnicornClient{
public static void main(String [] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Client() ;
}
}) ;
}
}