//wap to enter name & password and print using echochar
import java.awt.*;
import java.awt.event.*;
class myframe extends Frame implements ActionListener
{
Button b1,b2;
TextField tx1,tx2;
Label l1,l2,l3;
int a;
myframe()
{
setLayout(null);
l1=new Label("Enter the name");
l1.setBounds(50,50,150,20);
l1.setForeground(Color.blue);
add(l1);
tx1=new TextField();
tx1.setBounds(200,50,150,30);
add(tx1);
l2=new Label("Enter the password");
l2.setBounds(50,150,150,30);
l2.setForeground(Color.blue);
add(l2);
tx2=new TextField();
tx2.setEchoChar('*');
tx2.setBounds(200,150,150,30);
add(tx2);
b1=new Button("Display");
b1.addActionListener(this);
b1.setBounds(100,260,90,50);
add(b1);
b2=new Button("Exit");
b2.addActionListener(this);
b2.setBounds(210,260,90,50);
add(b2);
}
public void paint(Graphics g)
{
if(a==1)
{
g.setColor(Color.red);
g.setFont(new Font("Arial",Font.BOLD,25));
g.drawString("Name="+tx1.getText(),250,380);
g.setFont(new Font("Script",Font.BOLD,25));
g.drawString("Password="+tx2.getText(),250,400);
}
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str=="Display")
{
a=1;
}
if(str=="Exit")
{
System.exit(0);
}
repaint();
}
}
class echochar
{
public static void main(String args[])
{
myframe f=new myframe();
f.setVisible(true);
f.setTitle("Calculate the Reverse");
f.setSize(400,400);
}
}
No comments:
Post a Comment