0% found this document useful (0 votes)
38 views3 pages

Java 1 Prac 1

The document describes a Java program that displays a form with fields for username, email, phone number and checkboxes to select courses. It uses AWT components like Frame, Label, TextField, Checkbox and Button. On submit, it displays the entered details and selected courses.

Uploaded by

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

Java 1 Prac 1

The document describes a Java program that displays a form with fields for username, email, phone number and checkboxes to select courses. It uses AWT components like Frame, Label, TextField, Checkbox and Button. On submit, it displays the entered details and selected courses.

Uploaded by

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

username.

setBounds(30,30,80,30);
Program :
tf1.setBounds(150,30,200,30);
import java.awt.*;

import java.awt.event.ItemEvent;
email.setBounds(30,90,80,30);
import java.awt.event.ItemListener;
tf2.setBounds(150,90,200,30);
import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;
phoneNumber.setBounds(30,150,100,30);
import java.util.ArrayList;
tf3.setBounds(150,150,200,30);

public class DisplayFormDetails extends Frame


implements ActionListener{ javaScript.setBounds(30,210,100,20);

javaScript.addItemListener(new ItemListener(){

private Label public void itemStateChanged(ItemEvent e){


username,email,phoneNumber,displayUsername,displ
ayEmail,displayPhoneNo,displayCourses; updateSelectedCourse("JavaScript",e);

private TextField tf1,tf2,tf3; }

private Button submit; });

private Checkbox javaScript,html,css;

private Frame f; html.setBounds(30,240,100,20);

private ArrayList<String> selectedCourses; html.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent e){

DisplayFormDetails(){ updateSelectedCourse("HTML",e);

selectedCourses = new ArrayList<String>(); });

username = new Label("Username:");

email = new Label("Email:"); css.setBounds(30,270,100,20);

phoneNumber = new Label("Phone Number:"); css.addItemListener(new ItemListener(){

javaScript = new Checkbox("JavaScript"); public void itemStateChanged(ItemEvent e){

html = new Checkbox("HTML"); updateSelectedCourse("CSS",e);

css = new Checkbox("CSS"); }

f = new Frame("Form"); });

tf1 = new TextField(); submit.setBounds(30,300,100,30);

tf2 = new TextField(); submit.addActionListener(this);

tf3 = new TextField();


f.add(username);

submit = new Button("Submit"); f.add(email);

f.add(phoneNumber);

Practical 1
f.add(tf1);

f.add(tf2); displayPhoneNo.setText(phoneNumber.getText()
+ tf3.getText());
f.add(tf3);
displayPhoneNo.setBounds(30,420,400,20);
f.add(javaScript);

f.add(html);
displayCourses.setText("Selected Courses: " +
f.add(css); selectedCourses.toString());
f.add(submit); displayCourses.setBounds(30,450,400,20);

f.setSize(800,800); f.add(displayUsername);
f.setLayout(null); f.add(displayEmail);
f.setVisible(true); f.add(displayPhoneNo);
} f.add(displayCourses);

private void updateSelectedCourse(String }


course,ItemEvent e){

int state = e.getStateChange();


public static void main(String args[]){
if(state == 1){
new DisplayFormDetails();
selectedCourses.add(course);
}
}
}
else if(state == 0){

selectedCourses.remove(course);

public void actionPerformed(ActionEvent e){

displayUsername = new Label();

displayEmail = new Label();

displayPhoneNo = new Label();

displayCourses = new Label();

displayUsername.setText(username.getText() +
tf1.getText());

displayUsername.setBounds(30,360,400,20);

displayEmail.setText(email.getText() +
tf2.getText());

displayEmail.setBounds(30,390,400,20);

Practical 1
Output :

Conclusion :
In this Practical we successfully learnt about various
controls in AWT class.
K S P A T

You might also like