0% found this document useful (0 votes)
8 views2 pages

2 Simple Program S

Program
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)
8 views2 pages

2 Simple Program S

Program
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/ 2

Write a program to draw any basic shape in java using applet .

Rectangle -

import java.applet.Applet;
import java.awt.Graphics;

public class DrawShapeApplet extends Applet {


public void paint(Graphics g) {
g.drawRect(50, 50, 200, 100); // (x, y, width, height)
}
}

Circle -

import java.applet.Applet;
import java.awt.Graphics;

public class CircleApplet extends Applet {


public void paint(Graphics g) {
g.drawOval(50, 50, 150, 150); // (x, y, width, height)
}
}

Write a program for a simple student registration form with login register gui buttons.

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class StudentRegistrationApplet extends Applet implements ActionListener {


Label lblName, lblRollNo;
TextField txtName, txtRollNo;
Button btnLogin, btnRegister;

public void init() {


setLayout(null); // Using manual layout

// Create and add components


lblName = new Label("Name:");
lblName.setBounds(50, 50, 80, 20);
add(lblName);

txtName = new TextField();


txtName.setBounds(150, 50, 150, 20);
add(txtName);

lblRollNo = new Label("Roll No:");


lblRollNo.setBounds(50, 90, 80, 20);
add(lblRollNo);

txtRollNo = new TextField();


txtRollNo.setBounds(150, 90, 150, 20);
add(txtRollNo);

btnLogin = new Button("Login");


btnLogin.setBounds(50, 140, 80, 30);
btnLogin.addActionListener(this);
add(btnLogin);

btnRegister = new Button("Register");


btnRegister.setBounds(150, 140, 80, 30);
btnRegister.addActionListener(this);
add(btnRegister);
}

public void actionPerformed(ActionEvent e) {


if (e.getSource() == btnLogin) {
showStatus("Login clicked: Name = " + txtName.getText() + ", Roll No = " +
txtRollNo.getText());
} else if (e.getSource() == btnRegister) {
showStatus("Register clicked: Name = " + txtName.getText() + ", Roll No = " +
txtRollNo.getText());
}
}
}

You might also like