Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kerul.net;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class LoginUI extends JFrame
- implements ActionListener{
- private JTextField username;
- private JPasswordField password;
- private JButton btnlogin, btnreset;
- //private Container pane;
- public LoginUI(){
- username=new JTextField("Username",
- 10);
- password=new JPasswordField("Password",
- 10);
- btnlogin=new JButton ("Login");
- btnlogin.addActionListener(this);
- btnreset=new JButton ("Reset");
- btnreset.addActionListener(this);
- //draw UIs
- Container pane = getContentPane();
- pane.setBackground(Color.BLUE);
- pane.setLayout(new GridLayout(2,2));
- pane.add(username);
- pane.add(password);
- pane.add(btnlogin);
- pane.add(btnreset);
- }//end constructor
- public void actionPerformed(ActionEvent e){
- Object obj = e.getSource();
- if (obj==btnlogin){
- //capture data username
- String u, p,msg;
- u=username.getText().toString();
- p=password.getText().toString();
- msg="Hello "+u;
- //default title and icon dialog box
- JOptionPane.showMessageDialog(this,
- msg);
- }
- else if(obj==btnreset){
- password.setText("");
- username.setText("Your username here");
- //username.setF
- }
- }//end actionPerformed
- public static void main(String[] args) {
- LoginUI frame = new LoginUI();
- frame.setDefaultCloseOperation(
- JFrame.EXIT_ON_CLOSE);
- frame.setTitle("LoginUI");
- frame.setSize(300, 300);
- frame.setVisible(true);
- }//end main
- }//end LoginUI
Advertisement
Add Comment
Please, Sign In to add comment