Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JApplet;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.UIManager;
- public class Applety extends JApplet {
- private JButton jButton1 = new JButton();
- private JLabel lblUsername = new JLabel();
- private JLabel lblPassword = new JLabel();
- private JTextField txtUsername = new JTextField();
- private JPasswordField txtPassword = new JPasswordField();
- private JButton btnLogin = new JButton();
- private JLabel txtStatus = new JLabel();
- public Applety() {
- }
- private void jbInit() throws Exception {
- this.getContentPane().setLayout( null );
- lblUsername.setText("Username: ");
- lblUsername.setBounds(new Rectangle(25, 45, 70, 15));
- this.getContentPane().add(txtStatus, null);
- this.getContentPane().add(btnLogin, null);
- this.getContentPane().add(txtPassword, null);
- this.getContentPane().add(txtUsername, null);
- this.getContentPane().add(lblUsername, null);
- lblPassword.setText("Password: ");
- lblPassword.setBounds(new Rectangle(25, 65, 70, 15));
- lblUsername.setForeground(new Color(155, 50, 0));
- lblPassword.setForeground(new Color(155, 50, 0));
- txtUsername.setBounds(new Rectangle(110, 45, 70, 15));
- txtPassword.setBounds(new Rectangle(110, 65, 70, 15));
- txtPassword.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- txtPassword_actionPerformed(e);
- }
- });
- btnLogin.setText("Login");
- btnLogin.setBounds(new Rectangle(95, 140, 75, 21));
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- btnLogin_actionPerformed(e);
- }
- });
- txtStatus.setText("");
- txtStatus.setBounds(new Rectangle(60, 90, 135, 40));
- txtStatus.setForeground(Color.red);
- this.getContentPane().add(lblPassword, null);
- }
- public void init() {
- try {
- jbInit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- Applety applet = new Applety();
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().add(applet, BorderLayout.CENTER);
- applet.init();
- applet.start();
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- frame.setSize(300, 230);
- frame.setTitle("Login form");
- Dimension frameSize = frame.getSize();
- frame.setLocation((d.width-frameSize.width)/9, (d.height-frameSize.height)/7);
- frame.setVisible(true);
- }
- static {
- try {
- } catch (Exception e) {
- }
- }
- private void btnLogin_actionPerformed(ActionEvent e) {
- if (txtUsername.getText().equals("ahmedsofee") && txtPassword.getText().equals("55199")) {
- txtStatus.setText("wlcome admin!");
- txtStatus.setForeground(new Color(50, 200, 50));
- lblUsername.setVisible(false);
- txtUsername.setVisible(false);
- lblPassword.setVisible(false);
- txtPassword.setVisible(false);
- btnLogin.setVisible(false);
- //txtStatus.setBounds(new Rectangle(170, 1, 135, 40));
- for (int i = 0; i < 50; ++i) {
- txtStatus.setBounds(new Rectangle(130 + i, 1, 135, 40));
- }
- }
- else {
- txtStatus.setForeground(new Color(200, 50, 50));
- if (txtUsername.getText().equals("") || txtPassword.getText().equals("")) {
- txtStatus.setText("Insufficient data!");
- }
- else if (!txtUsername.getText().equals("ahmedsofee")) {
- txtStatus.setText("Username is incorrect!");
- txtPassword.setText("");
- }
- else if (!txtPassword.getText().equals("55199")) {
- txtStatus.setText("Password is incorrect!");
- txtPassword.setText("");
- }
- }
- }
- private void txtPassword_actionPerformed(ActionEvent e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement