Wednesday, December 11, 2024
Android lab cycle program
1. Radio Button
Aim: Write a Program to select gender using radio button
activity_main.xml
MainActivity.java
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
Button but;
RadioGroup rgroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but=(Button) findViewById(R.id.button);
rgroup=(RadioGroup) findViewById(R.id.radiogrp);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selected=rgroup.getCheckedRadioButtonId();
RadioButton radio=(RadioButton) findViewById(selected);
Toast.makeText(MainActivity.this,"You selected : "+radio.getText(),Toast.LENGTH_LONG).show();
}
});
}
}
Output
2. Addition of two Numbers
Aim: Write a program to add two numbers
activity_main.xml
MainActivity.java
package com.example.myapplication;
import android.widget.EditText;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
EditText firstnum,secondnum;
TextView r;
Button bt;
double a,b,c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstnum=(EditText) findViewById(R.id.first);
secondnum=(EditText) findViewById(R.id.second);
bt=(Button) findViewById(R.id.buttonadd);
r=(TextView) findViewById(R.id.result);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a=Double.parseDouble(firstnum.getText().toString());
b=Double.parseDouble(secondnum.getText().toString());
c=a+b;
r.setText("Sum="+c);
}
});
}
Output
3. Alert Box
Aim: Write a program to Display an alert box with OK and Cancel
activity_main.xml
MainActivity.java
package com.example.myapplication;
import android.content.DialogInterface;
import android.widget.EditText;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but=(Button) findViewById(R.id.button);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder b= new AlertDialog.Builder(MainActivity.this);
b.setTitle("Alert");
b.setMessage("Are you sure ?");
b.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this, "You Clicked OK",
Toast.LENGTH_SHORT).show();
}
});
b.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this, "You Clicked Cancel",
Toast.LENGTH_SHORT).show();
}
});
AlertDialog d = b.create();
d.show();
}
});
}
}
4. Multiplication table
Aim: Write a program to display multiplication table of a given number
activity_main.xml
MainActivity.java
package com.example.myapplication43;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android . os . Bundle ;
import android . view . View ;
import android . widget . Button ;
import android . widget . EditText ;
import android . widget . TextView ;
public class MainActivity extends AppCompatActivity {
TextView txtres ;
Button but ;
EditText edtnum ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
setContentView ( R . layout . activity_main ) ;
txtres = findViewById ( R . id . textViewResult ) ;
edtnum = findViewById ( R . id . editTextNumber ) ;
but = findViewById ( R . id . button ) ;
but . setOnClickListener ( new View . OnClickListener () {
@Override
public void onClick ( View v ) {
int num = Integer . parseInt ( edtnum . getText () . toString () ) ;
txtres . setText ( " " ) ;
for ( int i =1; i <11; i ++) {
txtres . append ( i + " * " + num + " = " + i* num + " \n" ) ;
}
}
}) ;
}
}
Output
5. Change the Background Color
Aim: Write a program to Change the Background colour of the Activity
activity_main.xml
MainActivity.java
package com.example.myapplicationbgcolor;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
Button but , butc;
RelativeLayout rel;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super.onCreate ( savedInstanceState );
setContentView (R.layout.activity_main );
but = findViewById (R.id.button);
butc = findViewById (R.id.butclear);
rel = findViewById (R.id.rel);
but.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick ( View v ) {
rel.setBackgroundColor (Color.MAGENTA);
}
}) ;
butc.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick ( View v ) {
rel.setBackgroundColor(Color.WHITE);
}
});
}
Output
6. Spinner
Aim: Write a Program to spin the six items
activity_main.xml
MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Spinner spin ;
String[] items = {"asp.net ","java" ,"rdbms","android","android lab "};
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate (savedInstanceState) ;
setContentView (R.layout.activity_main) ;
spin=findViewById(R.id.spinner) ;
spin.setOnItemSelectedListener (new AdapterView. OnItemSelectedListener()
{
@Override
public void onItemSelected ( AdapterView parent , View view , int
position , long id ) {
Toast . makeText ( MainActivity . this , " Selected Item "+ items [
position ] , Toast . LENGTH_SHORT ) . show () ;
}
@Override
public void onNothingSelected ( AdapterView parent ) {
Toast . makeText ( MainActivity . this , " No item selected " , Toast .
LENGTH_SHORT ) . show () ;
}
}) ;
ArrayAdapter < String > adt = new ArrayAdapter < String >( this ,
android . R . layout . simple_list_item_1 , items ) ;
spin . setAdapter ( adt ) ;
}
}
Output
7. Fetch data
Aim: Fetch data from an Edit Text and display it in a Text View
activity_main.xml
MainActivity.java
package com.example.myapplicationfetchdata;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText ;
import android.widget.TextView ;
public class MainActivity extends AppCompatActivity {
EditText edt;
Button but;
TextView txt;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super.onCreate (savedInstanceState ) ;
setContentView (R.layout.activity_main ) ;
edt = findViewById ( R.id.editText ) ;
but = findViewById ( R.id.button );
txt = findViewById ( R.id.text_display ) ;
but.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick ( View v ) {
txt.setText ( edt.getText().toString());
}
}) ;
}
}
Output
8. Change the background Image
Aim: Write a program to Change the Background image
activity_main.xml
MainActivity.java
com.example.myapplicationchangebgimage;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android . graphics . Color ;
import android . os . Bundle ;
import android . view . View ;
import android . widget . Button ;
import android . widget . RelativeLayout ;
public class MainActivity extends AppCompatActivity {
Button but;
RelativeLayout rel;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState ) ;
setContentView ( R.layout.activity_main);
but = findViewById (R.id.button);
rel = findViewById (R.id.rel) ;
but.setOnClickListener ( new View.OnClickListener() {
@Override
public void onClick ( View v ) {
rel.setBackgroundResource (R.drawable.sujeercolor ) ;
}
}) ;
}
}
Output
9. Get current time and date
Aim: Write a program to get current time and date
activity_main.xml
MainActivity.java
package com.example.myapplicationdateandtime;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView=findViewById(R.id.date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
String currentDateandTime = sdf.format(new Date());
textView.setText(currentDateandTime);
}
}
Output
10. Marquee Text
Aim: Write a program to make a marquee text
activity_main.xml
MainActivity.java
package com.example.myapplicationmarquee;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txt = findViewById(R.id.text);
txt.setSelected(true);
}
}
Output
Sunday, January 29, 2023
project2023
project2023: Submit the following details in the comment column
1.Register Number
2. Name of the student
3. Class
Tuesday, March 10, 2020
iibscitjavalabcycleprograms
7.Fibonacci
Series
Aim: Write a Java program to generate fibonacci series
import java.io.*;
import java.util.*;
class fib
{
public static void
main(String args[])
{
int n,f,f1,f2,i;
Scanner s = new
Scanner(System.in);
System.out.print("Enter the number:");
n =
s.nextInt();
f1=0;
f2=1;
System.out.println("
"+f1);
System.out.println("
"+f2);
for(i=3;i<=n;i++)
{
f=f1+f2;
System.out.println("
"+f);
f1=f2;
f2=f;
|}
}
}
D:\javac fib.java
D:\java fib
Result
Enter the number 10
0
1
1
2
3
5
8
13
21
34
8.Multi level Inheritance
Aim: To write a JAVA program to implement multi-level Inheritance
class A
{
A()
{
System.out.println("Inside A's Constructor");
}
}
class B extends A
{
B()
{
System.out.println("Inside B's Constructor");
}
}
class C extends B
{
C()
{
System.out.println("Inside C's Constructor");
}
}
class multi
{public static void main(String args[])
{
C c1=new C();
}
}
D:\>javac multi.java
D:\>java multi
Output:
Inside A's Constructor
Inside B's Constructor
Inside C's Constructor
interface AOutput:
Inside A's Constructor
Inside B's Constructor
Inside C's Constructor
9. Interface
Aim: To write a JAVA program to implement
Interface.
{
void display();}
class B implements A{
public void display(){
System.out.println("B's method");}
}class C extends B
{public void callme()
{System.out.println("C's method");
}}
class inter{
public static void main(String args[]){
C c1=new C();c1.display();
c1.callme();}
}
D:\java inter.javaD:\java inter
Output:
B's method
B's method
C's method
10.String operation
class stringoperation
{
public static void main(String args[])
{
String s1 ="Hello";
String s2 ="world";
System.out.println("the strings are "+s1+"and "+s2);
int len1=s1.length();
int len2=s2.length();
System.out.println("the length of "+s1+"is "+len1);
System.out.println("the length of "+s2+"is "+len2);
System.out.println("the concatenation of strings "+s1.concat(s2));
System.out.println("First character of" + s1+"is="+s1.charAt(0));
System.out.println("The upper case of " + s1+"is="+s1.toUpperCase());
System.out.println("The Lower case of " + s2+"is="+s2.toLowerCase());
}
}
d:\>javac stringoperation.java
d:\>java stringoperation
OUTPUT
the strings are Hello and world
the length of Hello is 5
the length of world is 5
the concatenation of strings Helloworld
First character ofHello is=H
The upper case of Hello is=HELLO
The Lower case of world is=world
1.Sum of Digits
Aim : Calculate the sum of individual digits of a given number
import java.util.*;
public class sum
{
public static void main(String args[])
{
int m, n, sum = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number:");
m = s.nextInt();
while(m > 0)
{
n = m % 10;
sum = sum + n;
m = m / 10;
}
System.out.println("Sum of Digits:"+sum);
}
}
d:\>javac sum.java
d:\>java sum
2.Exception
Aim : Java program to divide two numbers and catch the exception, if divisor is 0
import java.util.*;
class exec
{
public static void main(String args[])
{int n1,n2,m;
Scanner s = new Scanner(System.in);
System.out.println("emter the number 1");
n1=s.nextInt();
System.out.println("enter the number 2");
n2=s.nextInt();
try{
m=n1/n2;
System.out.println ("Result: "+m);
}
catch(ArithmeticException e){
System.out.println ("You Shouldn't divide a number by zero");
}
}
}
d:\>javac exec.java
d:\>java exec
3.Thread
Aim: Creating three threads using the class Thread and then running them concurrently
class B extends Thread {
public void run() {
System.out.println();
for (int i = 1; i <= 5; i++) {
System.out.println(" Thread name = "+ Thread.currentThread().getName());
}
}
public static void main(String[] args) {
B t1 = new B();
t1.start();
B t2 = new B();
t2.start();
B t3 = new B();
t3.start();
}
}
3.Thread
Aim: Creating three threads using the class Thread and then running them concurrently
class B extends Thread {
public void run() {
System.out.println();
for (int i = 1; i <= 5; i++) {
System.out.println(" Thread name = "+ Thread.currentThread().getName());
}
}
public static void main(String[] args) {
B t1 = new B();
t1.start();
B t2 = new B();
t2.start();
B t3 = new B();
t3.start();
}
}
d:\>javac B.java
d:\>java B.java
4. Inheritance
Aim: Write a Java program to find addition of two numbers using single inheritance
class A
{int a=2, b=3;
void methodA()
{
System.out.println("Base class method");
System.out.println("a="+a);
System.out.println("b="+b);
}
}
class add extends A
{
void methodB()
{ int c = a + b;
System.out.println("Child class method c= "+c );
}
public static void main(String args[])
{
add obj = new add();
obj.methodA();
obj.methodB();
}
}
d:\>javac add.java
4. Inheritance
Aim: Write a Java program to find addition of two numbers using single inheritance
class A
{int a=2, b=3;
void methodA()
{
System.out.println("Base class method");
System.out.println("a="+a);
System.out.println("b="+b);
}
}
class add extends A
{
void methodB()
{ int c = a + b;
System.out.println("Child class method c= "+c );
}
public static void main(String args[])
{
add obj = new add();
obj.methodA();
obj.methodB();
}
}
d:\>javac add.java
d:\>java add
5. Factorial
Aim: write a Java program to compute the factorial of a given number
import java.util.*;
public class factorial
5. Factorial
Aim: write a Java program to compute the factorial of a given number
import java.util.*;
public class factorial
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("emter the number");
int num = s.nextInt();
int f = 1;
for(int i = 1; i <= num; ++i)
{
f = f * i;
}
System.out.println("Factorial="+f);
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("emter the number");
int num = s.nextInt();
int f = 1;
for(int i = 1; i <= num; ++i)
{
f = f * i;
}
System.out.println("Factorial="+f);
}
}
d:\>javac factorial.java
d:\>java factorial
6.Applet
Aim: Write a java applet program to draw a rounded rectangle
import java.applet.*;
import java.awt.*;
public class myapplet extends Applet
{
public void Paint(Graphics g)
{
g.drawRoundRect(10,30,120,120,2,3);
}
}
D:\>javac myapplet.java
D:\>java myapplet
D:\>notepad t1.html
<html>
<body>
<applet code=”myapplet.class” height=300 width=200>
</applet>
</body>
</html>
D:\>appletviewer t1.html
Tuesday, January 7, 2020
project2020
Submit the following details in the comment column
1.Register Number
2. Name of the student
3. Class
Saturday, February 23, 2019
Vb.net lab cycle
1.Write a Vb.net program to find factorial of
a given number
Module Factorial
Sub main()
Dim n, i, f As Integer
Console.Write("Enter a Number: ")
n = CInt(Console.ReadLine())
f = 1
For i = 1 To n
f = f * i
Next
Console.WriteLine("Factorial of
" + n.ToString() + " is " + f.ToString())
End Sub
End Module
2.Check whether the given
number is Armstrong Number or not
Module ArmstrongNumber
Sub Main()
Dim n, r, sum, m As Integer
Console.Write("Enter a number= ")
n = CInt(Console.ReadLine())
sum = 0
m = n
While n <> 0
r = n Mod 10
sum =sum + Math.Pow(r, 3)
n = n \ 10
End While
If sum = m Then
Console.WriteLine(t.ToString + " is a Armstrong Number")
Else
Console.WriteLine(t.ToString + " is NOT an
Armstrong Number")
End If
End Sub
End Module
3.Calculate Sum of the
digits of a given number
Module sumofdigits
Sub Main()
Dim n, sum, r As Integer
Console.Write("Enter a Number: ")
n = CInt(Console.ReadLine())
sum
= 0
While n <> 0
r = n Mod 10
sum = sum + r
n = n \ 10
End While
Console.WriteLine("Sum of Digits=" + sum.ToString())
Console.ReadLine()
End Sub
End Module
4.Check whether the number
is a Perfect Number or not
Module PerfectNum
Sub Main()
Dim n, p, r, sum As Integer
Console.Write("Enter a number: ")
n = CInt(Console.ReadLine())
p = 1
sum
= 0
While p <= n \ 2
r = n Mod p
If r = 0 Then
sum = num + p
End If
p = p + 1
End While
If sum = n Then
Console.WriteLine(n.ToString + " is a Perfect Number")
Else
Console.WriteLine(n.ToString + " is NOT a Perfect Number")
End If
End Sub
End Module
5.Fibonacci Sequence
Module Fibonacci
Sub Main()
Dim n, f1, f2, f3 As Integer
Console.Write("Enter Your Term:")
n = CInt(Console.ReadLine())
f1 = 0
f2 = 1
f3 = 0
While n <> 0
Console.Write(f3 & " ")
f1 = f2
f2 = f3
f3 = f1 + f2
n = n - 1
End While
End Sub
End Module
6. Write a program in VB.Net to perform String Operations.
Module Module1
Sub Main()
Dim s1 As String = "welcome to vb.net"
Dim s2 As String = "programming"Dim s3 As String
s3 = s1 & s2
Console.WriteLine("after cancat" & s3)
s3 = LCase(s1)
Console.WriteLine("LowerCase:" & s3)
s3 = s1.ToUpper()
Console.WriteLine("uppercase " & s3)
s3 = s1.Substring(0, 7)
Console.WriteLine("sub string" & s3)
s3 = s1.Replace("vb.net", "java")
Console.WriteLine("after replace" & s3)
s3 = s1.Remove(0, 11)
Console.WriteLine("after removing" & s3)
Console.WriteLine("length of str1 string" & s1.Length())
Console.WriteLine("length of str2 string" & s2.Length())
Console.ReadLine()
End Sub
End Module
7. Exception Handling
Module Module1
Sub Main()
Dim a, b, c As Integer
Console.WriteLine("enter two number")
Try
a = CInt(Console.ReadLine())
b = CInt(Console.ReadLine())
c = a / b
Console.WriteLine("quotient " & c)
Catch e As OverflowException
Console.WriteLine("cannot divide by zero")
Finally
Console.WriteLine("this is always excuted")
End Try
End Sub
End Module
WINDOWS APPLICATION
8.Zoom In/Zoom Out
WINDOWS APPLICATION
8.Zoom In/Zoom Out
Image- localsource>import
Sizemode>striceimage
Button1-text>zoom
in
Button2-text>zomm
out
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Width
= PictureBox1.Width + 20
PictureBox1.Height
= PictureBox1.Height + 20
End Sub
PrivateSub Button2_Click(sender AsObject, e AsEventArgs) Handles Button2.Click
PictureBox1.Width
= PictureBox1.Width - 20
PictureBox1.Height
= PictureBox1.Height - 20
End Sub
End Class
9.Quiz
Properties
Groupbox1
>text>what is remove text function
Radiobutton1
>text>string.remove
Radiobutton2
>text>string.insert
Radiobutton3
>text>string.substring
Groupbox2
>text>what is replace function?
Radiobutton4
>text>strcomp
Radiobutton5
>text>string.copy
Radiobutton6>text>string.replace
Groupbox3
> text >what is search string function?
Radiobutton7>text>Lcase
Radiobutton8>text
>string.indexof
Radiobutton9
>text> both
Button1>Text
> submit
Program
Public Class
Form1
Private c AsInteger
PrivateSub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
c = c + 1
Else
MsgBox("wrong answer")
End If
If RadioButton6.Checked Then
c = c + 1
Else
MsgBox("wrong answer")
End If
If RadioButton8.Checked Then
c = c + 1
Else
MsgBox("wrong answer")
End If
MsgBox("your score is"&
c)
End Sub
End Class
10.Text Formatting Using Checkbox
Properties
Button1>text
>fill
Button2> text
>get select the items
Public Class Form1
PrivateSub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 1 To 10
CheckedListBox1.Items.Add("item:"&i, True)
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim str As String = ""
For Each x As String In CheckedListBox1.CheckedItems
str
= str& x &","
Next
MsgBox("the channel items are:"&str)
End Sub
End
Class
11.Free Hand Drawing
Public
Class Form1
Privatepx, py As Integer
Private drag As Boolean
Private
Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Drag = True
px
= e.X
py
= e.Y
End
Sub
Private
Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If Drag Then
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(Pens.Blue, px, py, e.X, e.Y)
px
= e.X
py
= e.Y
End
If
End
Sub
PrivateSub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
Drag = False
End
Sub
End
Class
Public Class Form1
PictureBox1.Height = PictureBox1.Height + 20
End Sub
PictureBox1.Height = PictureBox1.Height - 20
End Sub
End Class
11.Free Hand Drawing
Public
Class Form1
Privatepx, py As Integer
Private drag As Boolean
Private
Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Drag = True
px
= e.X
py
= e.Y
End
Sub
Private
Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If Drag Then
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(Pens.Blue, px, py, e.X, e.Y)
px
= e.X
py
= e.Y
End
If
End
Sub
PrivateSub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
Drag = False
End
Sub
End
Class
12.Convert Text into Bold, Italic and
underline using check box
public class Form1
Private Sub Checkbox1_Checkedchanged( Byval sender As System.Object,
Byval e As System.EventArgs) Handles Checkbox1.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style
Xor FontStyle.Bold)
End Sub
Private Sub Checkbox2_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox2.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Italic)
End Sub
Private Sub Checkbox3_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox3.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Underline)
End Sub
End Class
13.Calculator
Properties
Button1>
text > 0 Button7> text > 6
Button2>
text > 1 Button8> text > 7
Button3>
text > 2 Button9> text > 8
Button4>
text > 3 Button10> text >
9
Button5>
text > 4 Button11> text >
+
Button6>
text > 5 Button12> text >
-
Button13>
text > * Button15> text > .
Button14>
text > / Button16> text >
mod
Button17>
text > = Button18> text > c
Program
Public Class Form1
Private pre, cur As Double
Private opcode As String
PrivateSub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 3 To 7
Dim c As Control = Me.Controls(i)
AddHandler c.Click, AddressOf Op
Next
For i As Integer = 8 To 18
Dim c AsControl = Me.Controls(i)
AddHandler c.Click, AddressOf numbers
Next
End Sub
Private Sub numbers(ByVal s As Object, e As EventArgs)
Dim b As Button = s
TextBox1.Text = TextBox1.Text
&b.Text
End Sub
Private Sub op(ByVal s As Object, e As EventArgs)
Dim b As Button = s
opcode
= b.Text
pre
= CDbl(TextBox1.Text)
TextBox1.Text = ""
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
Dim res AsDouble
cur
= CDbl(TextBox1.Text)
Select Case opcode
Case "+"
res
= pre + cur
Case "-"
res
= pre - cur
Case "*"
res
= pre * cur
Case "/"
res = pre / cur
Case "mod"
res
= pre Mod cur
End Select
TextBox1.Text = res
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
pre
= 0
cur
= 0
opcode = ""
TextBox1.Text = ""
End Sub
End Class
14.WordProcesor
Properties
Menusprit
File
>open,new,save,exit
Edit
>copy,cut,paste,undo,redo
Format
>color,font,bullet
Richtextbox
Dialogbox
Colordialogbox,fontdilogbox,savedialogbox,opendialogbox
Program:
Public Class Form1
Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewToolStripMenuItem.Click
RichTextBox1.Clear()
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
If openfiledialog1.showdialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
If SaveFileDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SaveFile(SaveFileDialog1.FileName)
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click
RichTextBox1.Copy()
End Sub
Private SubCutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click
RichTextBox1.Cut()
EndSub
Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PasteToolStripMenuItem.Click
RichTextBox1.Paste()
End Sub
Private SubUndoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UndoToolStripMenuItem.Click
RichTextBox1.Undo()
End Sub
Private Sub RedoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedoToolStripMenuItem.Click
RichTextBox1.Redo()
End Sub
Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SelectionColor =
ColorDialog1.Color
End If
End Sub
Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SelectionFont =
FontDialog1.Font
End If
End Sub
Private Sub BulletToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BulletToolStripMenuItem.Click
RichTextBox1.SelectionBullet = True
End Sub
End Class
15.CreatingDialague Boxes
Form1
Textbox
Buttton1
Text
> enter text
Form2
Label>enter
text hole
Textbox
Button1>ok
Dialogresult>ok
Dialogresult>cancel
Public Class Form1
Private f As New Form3()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If f.ShowDialog = DialogResult.OK Then
TextBox1.Text = f.TextBox1.Text
Else
MsgBox("cancel was clicked")
End If
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
public class Form1
Private Sub Checkbox1_Checkedchanged( Byval sender As System.Object,
Byval e As System.EventArgs) Handles Checkbox1.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style
Xor FontStyle.Bold)
End Sub
Private Sub Checkbox2_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox2.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Italic)
End Sub
Private Sub Checkbox3_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox3.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Underline)
End Sub
End Class
Private Sub Checkbox1_Checkedchanged( Byval sender As System.Object,
Byval e As System.EventArgs) Handles Checkbox1.CheckedChanged
Xor FontStyle.Bold)
End Sub
Private Sub Checkbox2_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox2.CheckedChanged
End Sub
Private Sub Checkbox3_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox3.CheckedChanged
End Class
13.Calculator
Properties
Button1>
text > 0 Button7> text > 6
Button2>
text > 1 Button8> text > 7
Button3>
text > 2 Button9> text > 8
Button4>
text > 3 Button10> text >
9
Button5>
text > 4 Button11> text >
+
Button6>
text > 5 Button12> text >
-
Button13>
text > * Button15> text > .
Button14>
text > / Button16> text >
mod
Button17>
text > = Button18> text > c
Program
Public Class Form1
Private pre, cur As Double
Private opcode As String
PrivateSub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 3 To 7
Dim c As Control = Me.Controls(i)
AddHandler c.Click, AddressOf Op
Next
For i As Integer = 8 To 18
Dim c AsControl = Me.Controls(i)
AddHandler c.Click, AddressOf numbers
Next
End Sub
Private Sub numbers(ByVal s As Object, e As EventArgs)
Dim b As Button = s
TextBox1.Text = TextBox1.Text
&b.Text
End Sub
Private Sub op(ByVal s As Object, e As EventArgs)
Dim b As Button = s
opcode
= b.Text
pre
= CDbl(TextBox1.Text)
TextBox1.Text = ""
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
Dim res AsDouble
cur
= CDbl(TextBox1.Text)
Select Case opcode
Case "+"
res
= pre + cur
Case "-"
res
= pre - cur
Case "*"
res
= pre * cur
Case "/"
res = pre / cur
Case "mod"
res
= pre Mod cur
End Select
TextBox1.Text = res
End Sub
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
pre
= 0
cur
= 0
opcode = ""
TextBox1.Text = ""
End Sub
End Class
14.WordProcesor
Properties
Menusprit
File
>open,new,save,exit
Edit
>copy,cut,paste,undo,redo
Format
>color,font,bullet
Richtextbox
Dialogbox
Colordialogbox,fontdilogbox,savedialogbox,opendialogbox
Program:
Public Class Form1
Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewToolStripMenuItem.Click
RichTextBox1.Clear()
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
If openfiledialog1.showdialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
If SaveFileDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SaveFile(SaveFileDialog1.FileName)
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click
RichTextBox1.Copy()
End Sub
Private SubCutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click
RichTextBox1.Cut()
EndSub
Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PasteToolStripMenuItem.Click
RichTextBox1.Paste()
End Sub
Private SubUndoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UndoToolStripMenuItem.Click
RichTextBox1.Undo()
End Sub
Private Sub RedoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedoToolStripMenuItem.Click
RichTextBox1.Redo()
End Sub
Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SelectionColor =
ColorDialog1.Color
End If
End Sub
Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SelectionFont =
FontDialog1.Font
End If
End Sub
Private Sub BulletToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BulletToolStripMenuItem.Click
RichTextBox1.SelectionBullet = True
End Sub
End Class
15.CreatingDialague Boxes
Form1
Textbox
Buttton1
Text
> enter text
Form2
Label>enter
text hole
Textbox
Button1>ok
Dialogresult>ok
Dialogresult>cancel
Public Class Form1
Private f As New Form3()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If f.ShowDialog = DialogResult.OK Then
TextBox1.Text = f.TextBox1.Text
Else
MsgBox("cancel was clicked")
End If
End Sub
End Class
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
Subscribe to:
Posts (Atom)