Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- class Mywindow extends Frame implements ActionListener
- {
- Label luser,lpass,lmsg;
- TextField tuser,tpass;
- Button bok,bcancel;
- Mywindow()
- {
- luser=new Label("username");
- lpass=new Label("password");
- lmsg=new Label(" ");
- tuser=new TextField();
- tpass=new TextField();
- bok=new Button("ok");
- bcancel= new Button("cancel");
- luser.setBounds(25,100,70,25);
- lpass.setBounds(120,180,180,25);
- tuser.setBounds(90,310,200,25);
- tpass.setBounds(120,100,180,25);
- lmsg.setBounds(90,310,200,25);
- add(luser);
- add(lpass);
- add(tuser);
- add(tpass);
- add(lmsg);
- bok.setBounds(60,280,80,30);
- bcancel.setBounds(200,280,80,30);
- bok.addActionListener(this);
- bcancel.addActionListener(this);
- add(bok);
- add(bcancel);
- setSize(400,350);
- setLayout(null);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent e)
- {
- String s1=tuser.getText();
- String s2=tpass.getText();
- String command=(( Button) e.getSource()).getActionCommand();
- if(command.equals("ok"))
- {
- if(s1.equals("awt")&&s2.equals("java"))
- {
- luser.setVisible(false);
- lpass.setVisible(false);
- tuser.setVisible(false);
- tpass.setVisible(false);
- bcancel.setBounds(160,175,80,30);
- lmsg.setForeground(Color.green);
- lmsg.setText("succesfull login");
- }
- else
- {
- lmsg.setForeground(Color.red);
- lmsg.setText("invalid user name and password");
- }
- }
- else
- {
- System.exit(0);
- }
- }
- public static void main(String[] args){
- Mywindow mw=new Mywindow();
- }
- }
Add Comment
Please, Sign In to add comment