0% found this document useful (0 votes)
3 views12 pages

Calculator: Import Java - Awt. Import Java - Awt.event.

The document contains multiple Java programs for creating GUI applications, including a calculator, a registration form, and a login form. Each program utilizes AWT or Swing components to collect user input and perform actions like addition, subtraction, and user authentication. The calculator performs basic arithmetic operations, while the registration form checks for strong passwords and the login form verifies user credentials.

Uploaded by

sejaldeshmukh93
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)
3 views12 pages

Calculator: Import Java - Awt. Import Java - Awt.event.

The document contains multiple Java programs for creating GUI applications, including a calculator, a registration form, and a login form. Each program utilizes AWT or Swing components to collect user input and perform actions like addition, subtraction, and user authentication. The calculator performs basic arithmetic operations, while the registration form checks for strong passwords and the login form verifies user credentials.

Uploaded by

sejaldeshmukh93
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/ 12

CALCULATOR

package com.company;
import java.awt.*;
import java.awt.event.*;
class Experiment
{
public static void main(String args[])
{
Frame f=new Frame("EXP");
final Label l1=new Label("Number 1");
l1.setBounds(30,100,80,30);
final TextField TF1 = new TextField();
TF1.setBounds(150,100,80,30);
f.add(l1);
f.add(TF1);
Label l2=new Label("Number 2");
l2.setBounds(30,150,90,40);
final TextField TF2 = new TextField();
TF2.setBounds(150,150,80,30);
f.add(l2);
f.add(TF2);
Label l3=new Label("Answer");
l3.setBounds(30,180,100,70);
final TextField TF3=new TextField();
TF3.setBounds(150,200,80,30);
f.add(l3);
f.add(TF3);
Button b=new Button("ADD");
b.setBounds(100,250,80,30);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int a = Integer.parseInt(TF1.getText());
int b = Integer.parseInt(TF2.getText());
int c = a + b;
TF3.setText(""+c);

//l1.setText("Their sum is = " + String.valueOf(c));


//l1.setBounds()
}
});
f.add(b);
Button b1=new Button("Substraction");
b1.setBounds(200,250,80,30);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int a = Integer.parseInt(TF1.getText());
int b = Integer.parseInt(TF2.getText());
int c = a - b;
TF3.setText(""+c);

}
});
f.add(b1);

Button b2=new Button("MULTIPLY");


b2.setBounds(300,250,80,30);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int a = Integer.parseInt(TF1.getText());
int b = Integer.parseInt(TF2.getText());
int c = a * b;
TF3.setText(""+c);

}
});
f.add(b2);
Button b3=new Button("Division");
b3.setBounds(400,250,80,30);
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int a = Integer.parseInt(TF1.getText());
int b = Integer.parseInt(TF2.getText());
int c = a/b;
TF3.setText(""+c);

}
});
f.add(b3);
f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
}
REGISTRATION FORM
package com.company;

import java.awt.*;
import java.awt.event.*;
class Form1 {
public static void main(String args[]) {
Frame f = new Frame("REGISTRATION FORM");
f.setSize(500, 500);
f.setLayout(null);
f.setVisible(true);
final Label u_name = new Label("Enter USERNAME:- ");
u_name.setBounds(30, 100, 120, 30);
final TextField user = new TextField();
user.setBounds(200, 100, 130, 30);
f.add(u_name);
f.add(user);
Label pass = new Label("Enter PASSWORD:- ");
pass.setBounds(30, 130, 140, 50);
final TextField password = new TextField();
password.setBounds(200, 150, 130, 30);
f.add(pass);
f.add(password);
final TextField msg = new TextField();
msg.setBounds(120, 310, 200, 50);
f.add(msg);
Button login = new Button("LOGIN");
login.setBounds(100, 220, 80, 30);
login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String a = user.getText();
String b = password.getText();
char ch;
boolean capitalFlag = false;
boolean lowerCaseFlag = false;
boolean numberFlag = false;
for (int j = 1; j <= 3; j++) {
for (int i = 0; i < b.length(); i++) {
ch = b.charAt(i);
if (Character.isDigit(ch)) {
numberFlag = true;
} else if (Character.isUpperCase(ch)) {
capitalFlag = true;
} else if (Character.isLowerCase(ch)) {
lowerCaseFlag = true;
}
if (numberFlag && capitalFlag && lowerCaseFlag &&
b.length() >= 8) {
String mg = "REGISTRATION DONE";
msg.setText(mg);
} else {
String mg = "TYPE A STRONG PASSWORD";
msg.setText(mg);
}
}
}
}
});
f.add(login);
Button cancel = new Button("CANCEL");
cancel.setBounds(200, 220, 80, 30);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
user.setText("");
password.setText("");
String mg = "CANCELED";
msg.setText(mg);
}
});
f.add(cancel);
}
}
FORM
package com.company;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
class Form1 extends JFrame implements ActionListener
{
JLabel name,surname,gender,city,comment;
JTextField name1,surname1,city1;
JRadioButton male,female;
JButton submit ,cancel;
TextArea comment1;
FileWriter file;

Form1()
{
setTitle("Register Form");
setSize(700,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);

// For labels
name = new JLabel("Name");
name.setBounds(20,50,100,30);
surname = new JLabel("Surname");
surname.setBounds(20,100,100,30);
gender = new JLabel("Gender");
gender.setBounds(20,150,100,30);
city = new JLabel("City");
city.setBounds(20,200,100,30);
comment = new JLabel("Comment");
comment.setBounds(20,250,100,30);
//For Textfield
name1 = new JTextField();
name1.setBounds(200,50,200,30);
surname1 = new JTextField();
surname1.setBounds(200,100,200,30);
city1 = new JTextField();
city1.setBounds(200,200,200,30);
comment1 = new TextArea("Write something about our website");
comment1.setBounds(200,250,200,100);

//for radiobuttons
male = new JRadioButton("male");
male.setBounds(200,150,100,30);
female = new JRadioButton("female");
female.setBounds(300,150,100,30);

submit = new JButton("submit");


submit.setBounds(150,400,100,30);
submit.addActionListener(this);
submit.add(Box.createHorizontalGlue());
cancel = new JButton("cancel");
cancel.setBounds(300,400,100,30);

add(name);
add(surname);
add(gender);
add(city);
add(comment);

add(name1);
add(surname1);
add(city1);
add(comment1);

add(male);
add(female);

ButtonGroup gen = new ButtonGroup();


gen.add(male);
gen.add(female);

add(submit);
add(cancel);

setLayout(null);
setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e)
{
String name = name1.getText();
String city = city1.getText();
String surname = surname1.getText();
String comment = comment1.getText();
String gender = "male";
if(female.isSelected()){
gender = "female";
}

if(e.getActionCommand() == submit.getActionCommand())
{
try{
file = new FileWriter("sejal.txt",true);
file.write(System.getProperty( "line.separator" ));
file.write("Name:- " + name);
file.write(System.getProperty( "line.separator" ));
file.write("Surname:- " + surname);
file.write(System.getProperty( "line.separator" ));
file.write("City:- " + city);
file.write(System.getProperty( "line.separator" ));
file.write("Gender:- " + gender);
file.write(System.getProperty( "line.separator" ));
file.write("Comment:- " + comment);
file.write(System.getProperty( "line.separator" ));
file.write("****************************************");

file.close();

}
catch(Exception ae){
JOptionPane.showMessageDialog(null, ""+ae);
}

}
if(e.getActionCommand() == cancel.getActionCommand())
{
name1.setText(null);
city1.setText("");
surname1.setText("");
comment1.setText("");
male.setSelected(false);
female.setSelected(false);

}
}
public static void main(String[] args) {
Form1 form = new Form1();
}

}
import java.awt.*;

import java.awt.event.*;

public class Form1 { public static void main(String args[]) {

Frame f=new Frame("LOGIN FORM");

f.setSize(500,500)

; f.setLayout(null);

f.setVisible(true);

final Label u_name=new Label("Enter USERNAME:- ");

u_name.setBounds(30,100,110,30);

final TextField user = new TextField();

user.setBounds(150,100,130,30);

f.add(u_name); f.add(user);

Label pass=new Label("Enter PASSWORD:- ");

pass.setBounds(30,130,120,50);
final TextField password = new TextField();

password.setBounds(150,150,130,30);

f.add(pass);

f.add(password);

final TextField msg=new TextField();

msg.setBounds(120,310,200,50);

f.add(msg);

Button login=new Button("LOGIN"); l

ogin.setBounds(100,220,80,30);

login.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

String a = user.getText();

String b = password.getText();

if(a.equals("USERNAME") && b.equals("PASS1234")) {

String mg="Login successfull"; msg.setText(mg);

else { String mg="Incorrect!!!!"; msg.setText(mg);

);

f.add(login);

Button cancel=new Button("CANCEL");

cancel.setBounds(200,220,80,30);

cancel.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

user.setText("");

password.setText("");

String mg="CANCELED";
msg.setText(mg);

);

f.add(cancel);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy