[go: up one dir, main page]

0% found this document useful (0 votes)
4 views4 pages

Practical No 12

The document contains Java code examples demonstrating the use of JPasswordField and applets for user authentication and simple addition. It includes a JFrame application for password input and an applet for adding two numbers with event handling. The code showcases the creation of GUI components and their interaction in a Java environment.

Uploaded by

patilshubhamww
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Practical No 12

The document contains Java code examples demonstrating the use of JPasswordField and applets for user authentication and simple addition. It includes a JFrame application for password input and an applet for adding two numbers with event handling. The code showcases the creation of GUI components and their interaction in a Java environment.

Uploaded by

patilshubhamww
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No:12

Batch:T3
Roll No: 3243
Code:
import javax.swing.*;
import java.awt.*;
public class Pword1
{
public static void main(String[] args)
{
JFrame f=new JFrame("JPasswordField Ex.");
JPasswordField jp= new JPasswordField();
JLabel l1=new JLabel("Password:");
l1.setBounds(40,120,100,50);
l1.setFont(new Font ("Serif", Font.BOLD,18));
jp.setBounds(120,120,120,50);
jp.setEchoChar('#');
f.add(jp);
f.add(l1);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
}
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="userauthen" height=300 width=300>
</applet>*/
public class extends JApplet implements ActionListener
{
JTextField t1;
JPasswordField jp1;
JButton b1;
JLabel l2;
public void init()
{
jp1=new JPasswordField(20);
jp1.setBounds(20,100,200,50);
t1=new JTextField(20);
t1.setBounds(20,50,200,50);
b1=new JButton("OK");
b1.setBounds(20,150,80,30);
l2=new JLabel();
add(t1);
add(jp1);
add(b1);
add(l2);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s1=t1.getText();
String s2=jp1.getText();
l2.setText("Name- "+s1+" "+"Password- "+s2);
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="AddNum.class" height=300 width=300></applet>*/
public class AddNum extends Applet implements ActionListener
{
TextField t1,t2,t3;
Label l1,l2,l3;
Button b1;
public void init()
{
l1=new Label("Enter 1st no.");
t1=new TextField();
l2=new Label("Enter 2nd no.");
t2=new TextField();
b1=new Button("ADDITION");
l3=new Label("Result");
t3=new TextField();
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(l3);
add(t3);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a+b;
String s1=""+c;
t3.setText(s1);
}
}
Output:

You might also like