You are on page 1of 6

Q1.

Write a java program to design a following GUI (Use Swing) [Marks 30]

Ans

import java.awt.*; import javax.swing.*;

class Slip8 extends JFrame

JLabel l1,l2,l3,l4,l5,l6; JTextField t1,t2,t3; JTextArea t;

JPanel p,p1,p2,p3; ButtonGroup bg; JRadioButton m,f; JCheckBox c1,c2,c3;

JButton b1,b2; Slip8()

p =new JPanel(); p1=new JPanel();

l1=new JLabel("First Name "); l2=new JLabel("last Name "); l3=new JLabel("Address "); l4=new
JLabel("mobile No ");

t1=new JTextField(10); t2=new JTextField(10); t3=new JTextField(10); t=new JTextArea(2,10); p.add(l1);


p.add(t1); p.add(l2); p.add(t2); p.add(l3); p.add(t); p.add(l4); p.add(t3);

p.setLayout(new GridLayout(4,2)); add(p);

l5=new JLabel("Gender ");

m = new JRadioButton("male"); f = new JRadioButton("female");

bg = new ButtonGroup(); bg.add(m);

bg.add(f);

p1.add(l5);

p1.add(m);

p1.add(f);

p1.setLayout(new GridLayout(1,3));

p2=new JPanel();
l6=new JLabel("Your Interests "); c1=new JCheckBox("Computer"); c2=new JCheckBox("Sports"); c3=new
JCheckBox("Music");

p2.add(l6);

p2.add(c1);

p2.add(c2);

p2.add(c3);

p2.setLayout(new GridLayout(1,4));

p3=new JPanel();

b1=new JButton("submit"); b2=new JButton("clear"); p3.add(b1);

p3.add(b2);

add(p);

add(p1);

add(p2);

add(p3);

setSize(300,400);

setLayout(new FlowLayout(FlowLayout.LEFT)); setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public static void main(String a[])

new Slip8();

}
Q2. Write a JavaScript program to design student registration form and perform following
validation:

- Check all fields should not contain a null value

- Check name field contains only alphabets

- Mobile No. field should be of 10 digits.s

- Pin code field should be of 06 digits.

Ans

<html>

<head>

<title> Javascript Validation </title>

<script>

function validate()

sname=document.getElementById("nm").value;

smobile=document.getElementById("mb").value;

saddress=document.getElementById("add").value;

scity=document.getElementById("ct").value;

sstate=document.getElementById("st").value;

spin=document.getElementById("pin").value;

if(sname==""||smobile==""||saddress==""||scity==""||sstate==""||spin=="")

alert("Fields should not be empty");

return false;
}

else if(!sname.match(/^[A-Za-z]+$/))

alert("Name should contain only characters")

return false;

else if(!smobile.match(/^\d{10}$/))

alert("Mobile number Not valid")

return false;

else if(!spin.match(/^\d{6}$/))

alert("Pin number Not valid")

return false;

alert("Valid");

return false;

</script>

<body>

<form name="frmStudent">

<table align="center" width=300>

<tr><th colspan=2>Student Registration Form</th></tr>

<tr><td>Name of Student</td><td><input type=text name=txtSname id=nm size=30></td>


<tr><td>Mobile No</td><td><input type=text name=txtSmobile id=mb size=30></td>

<tr><td>Address Line</td><td><input type=text name=txtSaddress id=add size=30></td>

<tr><td>City</td><td><input type=text name=txtScity id=ct size=30></td>

<tr><td>State</td><td><input type=text name=txtSstate id=st size=30></td>

<tr><td>Pincode</td><td><input type=text name=txtSpin id=pin size=30></td>

<tr><td><input type=submit value="Submit" onClick="return validate()"></td><td><input type=reset


value="Reset"></td></tr>

</table>

</form>

</body>

</html>

Q3. Write a Vb.net program to accept number from user into the TextBox. Calculate the square root of
that number also convert the entered number into binary number and display result into the Message
Box [Marks 20]

Ans

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click

Dim n As Integer

Dim sqr As Double

Dim rm As Integer

Dim str1 As String

n = CInt(TextBox1.Text)

sqr = Math.Sqrt(n)

While n
rm = n Mod 2

str1 = str1 & rm

n=n\2

End While

MessageBox.Show("Square Roor :" & sqr & " Binary Number : " & str1)

StrReverse(str1)

End Sub

End Class

You might also like