/* File Name: LoginDialog.java */ package explorer.client.gui; import javax.swing.JFrame; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.BorderLayout; import javax.swing.JPanel; import java.awt.GridLayout; import javax.swing.JLabel; import javax.swing.SwingConstants; import java.awt.Font; import java.awt.Rectangle; import java.awt.Color; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; /** * GUI for Remote System authentication from the client system * Contains fields for Username and Password * */ public class LoginDialog extends JDialog { BorderLayout borderLayout1 = new BorderLayout(); JPanel loginPanel = new JPanel(); GridLayout gridLayout1 = new GridLayout(); JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); JTextField txtusername = new JTextField(); JLabel jLabel2 = new JLabel(); JPasswordField txtpassword = new JPasswordField(); JButton cmdok = new JButton(); JButton cmdcancel = new JButton(); JPanel jPanel2 = new JPanel(); static boolean authendicated; ClientOpenFrame gui; String IPAddress; public LoginDialog(ClientOpenFrame parent,String IP) { super(parent); gui=parent; IPAddress=IP; this.setTitle("The Cross Platform Explorer- Login To:"+ IP ); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { authendicated=false; this.getContentPane().setLayout(borderLayout1); this.setSize(400,200); Dimension Size=Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((int)Size.getWidth()/2-200 ,(int)Size.getHeight()/2 -150); this.setResizable(false); loginPanel.setLayout(null); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { windowCloseAction(e); } }); gridLayout1.setRows(2); gridLayout1.setColumns(1); jPanel2.setLayout(gridLayout1); jPanel1.setSize(400, 250); jPanel1.setLayout(null); jPanel1.setBorder(BorderFactory.createTitledBorder("Login Information")); jLabel1.setText("User Name"); jLabel1.setBounds(new Rectangle(35, 30, 75, 30)); txtusername.setBounds(new Rectangle(120, 30, 180, 25)); txtusername.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Login_action(e); } }); jLabel2.setText("Password"); jLabel2.setBounds(new Rectangle(35, 75, 70, 30)); txtpassword.setBounds(new Rectangle(120, 75, 180, 25)); txtpassword.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Login_action(e); } }); cmdok.setText("OK"); cmdok.setBounds(new Rectangle(100, 125, 95, 25)); cmdok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Login_action(e); } }); cmdcancel.setText("Cancel"); cmdcancel.setBounds(new Rectangle(210, 125, 105, 25)); cmdcancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelAction(e); } }); jPanel1.add(cmdcancel, null); jPanel1.add(cmdok, null); jPanel1.add(txtpassword, null); jPanel1.add(jLabel2, null); jPanel1.add(txtusername, null); jPanel1.add(jLabel1, null); loginPanel.add(jPanel1, null); this.getContentPane().add(loginPanel, BorderLayout.CENTER); this.getContentPane().add(jPanel2, BorderLayout.NORTH); } void Login_action(ActionEvent e) { if(gui.getClient().checkAuthenticate(txtusername.getText(), txtpassword.getText(), IPAddress)) authendicated=true; else { authendicated=false; JOptionPane.showMessageDialog(this,"Username and password is not valid"); } this.setVisible(false); } void cancelAction(ActionEvent e) { authendicated=false; this.setVisible(false); } void windowCloseAction(WindowEvent e) { authendicated=false; this.setVisible(false); } }