Sep

18

//Applet with Arc

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap6.class” width=”400″ height=”400″></applet>
*/
public class Ap6 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
g.fillArc(130,110,140,140,0,-180);
}
}

//Applet with Animation-1

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap7.class” width=”400″ height=”400″></applet>
*/
public class Ap7 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
for(int i=0;i<=310;i+=10){
repaint();
g.fillOval(i,20,90,90);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}

//Applet with Animation-2

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap8.class” width=”400″ height=”400″></applet>
*/
public class Ap8 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
int x=0;
int y=20;
public void paint(Graphics g){
if(x<=310){
x=x+5;
}else{
y=y+5;
}
g.fillOval(x,y,90,90);
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
repaint();
}
}

//Applet with Mouse Event-1

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<Applet code=”Ap9.class” width=”400″ height=”400″></applet>
*/
public class Ap9 extends Applet implements MouseListener{
public void init(){
addMouseListener(this);
}
public void mouseExited(MouseEvent e){
System.out.println(“mouseExited”);
}
public void mouseEntered(MouseEvent e){
System.out.println(“mouseEntered”);
}
public void mouseReleased(MouseEvent e){
System.out.println(“mouseReleased”);
}
public void mousePressed(MouseEvent e){
System.out.println(“mousePressed”);
}
public void mouseClicked(MouseEvent e){
System.out.println(“mouseClicked”);
}
public void paint(Graphics g){
}
}

//Applet with Mouse Event-2

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<Applet code=”Ap10.class” width=”400″ height=”400″></applet>
*/
public class Ap10 extends Applet implements MouseListener{
public void init(){
addMouseListener(this);
}
public void mouseExited(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
int x,y;
public void mousePressed(MouseEvent e){
x=e.getX();
y=e.getY();
showStatus(x+”,”+y);
repaint();
}
public void mouseClicked(MouseEvent e){
}
public void paint(Graphics g){
g.drawString(x+” , “+y,x,y);
}
}

Sep

16

//Multiple Inheritance in C++ Code-1

#include<iostream.h>
class A{
public:
void fun1(){
cout<<“fun1() is called from class A”<<endl;
}
};
class B{
public:
void fun2(){
cout<<“fun2() is called from class B”<<endl;
}
};
class C:public A, public B{
};
void main(){
C c1;
c1.fun1();
c1.fun2();
}

//Multiple Inheritance in C++ Code-2

#include<iostream.h>
class A{
public:
void fun1(){
cout<<“fun1() is called from class A”<<endl;
}
};
class B{
public:
void fun2(){
cout<<“fun2() is called from class B”<<endl;
}
};
class C: A, B{
public:
void fun3(){
fun1();
fun2();
}
};
void main(){
C c1;
/*c1.fun1();
c1.fun2();*/
c1.fun3();
}

//Multiple Inheritance in C++ Code-3

#include<iostream.h>
class A{
public:
int numA;
void getNumA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
};
class B{
public:
int numB;
void getNumB(){
cout<<“Enter Value for numB: “;
cin>>numB;
}
};
class C: public A, public B{
};
void main(){
C c1;
c1.getNumA();
c1.getNumB();
cout<<c1.numA+c1.numB<<endl;
}

//Multiple Inheritance in C++ Code-4

#include<iostream.h>
class A{
int numA;
public:
void getNumA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
int returnNumA(){
return(numA);
}
};
class B{
int numB;
public:
void getNumB(){
cout<<“Enter Value for numB: “;
cin>>numB;
}
int returnNumB(){
return(numB);
}
};
class C: public A, public B{
};
void main(){
C c1;
c1.getNumA();
c1.getNumB();
cout<<c1.returnNumA()+c1.returnNumB()<<endl;
}

//Multiple Inheritance in C++ Code-5

#include<iostream.h>
class A{
int numA;
public:
void getNumA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
int returnNumA(){
return(numA);
}
};
class B{
int numB;
public:
void getNumB(){
cout<<“Enter Value for numB: “;
cin>>numB;
}
int returnNumB(){
return(numB);
}
};
class C: public A, public B{
int numC;
public:
void getNumC(){
cout<<“Enter Value for numC: “;
cin>>numC;
}
int returnNumC(){
return(numC);
}
};
void main(){
C c1;
c1.getNumA();
c1.getNumB();
c1.getNumC();
int result=c1.returnNumA()+c1.returnNumB()+c1.returnNumC();
cout<<result<<endl;
}

Sep

15

//:APPLET LIFE CYCLE EXAMPLE:

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap.class” width=”300″ height=”300″></applet>
*/
public class Ap extends Applet{
public void init(){
System.out.println(“init() called”);
}
public void start(){
System.out.println(“start() called”);
}
public void paint(Graphics g){
System.out.println(“paint() called”);
}
public void stop(){
System.out.println(“stop() called”);
}
public void destroy(){
System.out.println(“destroy() called”);
}
}

//:APPLET CODE-1:

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap2.class” width=”300″ height=”300″></applet>
*/
public class Ap2 extends Applet{
public void init(){
//setBackground(Color.red);
setBackground(new Color(100,255,0));
}
public void paint(Graphics g){
g.drawString(“HELLO”,100,100);
g.drawLine(50,50,200,200);
}
}

//:APPLET CODE-2:

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap3.class” width=”300″ height=”300″></applet>
*/
public class Ap3 extends Applet{
public void init(){
//setBackground(Color.red);
setBackground(new Color(100,255,0));
}
public void paint(Graphics g){
g.drawRect(50,50,100,200);
g.fillRect(100,100,50,50);
g.drawOval(150,150,200,200);
g.fillOval(200,100,150,50);
}
}

//:APPLET FACE OUTLINE CODE-3:

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap4.class” width=”400″ height=”400″></applet>
*/
public class Ap4 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
g.drawOval(20,20,350,350);
g.drawOval(90,120,40,40);
g.drawOval(240,120,40,40);
g.drawOval(170,150,40,140);
g.drawOval(130,310,140,40);
}
}

//:APPLET FILLED FACE CODE-4:

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap5.class” width=”400″ height=”400″></applet>
*/
public class Ap5 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
g.setColor(Color.white);
g.fillOval(20,20,350,350);
g.setColor(Color.black);
g.fillOval(90,120,40,40);
g.setColor(Color.blue);
g.fillOval(240,120,40,40);
g.setColor(Color.red);
g.fillOval(170,150,40,140);
g.setColor(Color.green);
g.fillOval(130,310,140,40);
}
}

Sep

09

class TestEx{
public static void main(String args[]){
try{
if(args.length==0){
String s=null;
System.out.println(s.length());
}
System.out.println(args[0].length());//3
int num1=Integer.parseInt(args[0]);
int num2=Integer.parseInt(args[1]);
System.out.println(num1/num2);
}
catch(NullPointerException e){
System.out.println(e);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(e);
}
catch(ArithmeticException e){
System.out.println(e);
}
catch(NumberFormatException e){
System.out.println(e);
}
catch(Exception e){
System.out.println(e);
}
System.out.println(“exit from main”);
}
}

Sep

09

// CHANGE THE SEQUENCE FINALLY THEN OBSERVE THE RESULTĀ 

class TestEx{
public static void main(String args[]){
try{
if(args.length==0){
String s=null;
System.out.println(s.length());
}
System.out.println(args[0].length());//3
int num1=Integer.parseInt(args[0]);
int num2=Integer.parseInt(args[1]);
System.out.println(num1/num2);
}
catch(Exception e){
System.out.println(e);
}
finally{
System.out.println(“finally executed”);
}
System.out.println(“exit from main”);
}
}

Sep

09

class MyEx extends Exception{
MyEx(String s){
super(s);
//System.out.println(s);
}
}
class TestMyEx{
public static void main(String args[]){
int i=10;
if(i==10){
try{
throw new MyEx(“MY Exception is raised”);
}
catch(MyEx e){
System.out.println(e);
}
}
System.out.println(i);
}
}

Sep

09

#include<iostream.h>
class A{
protected:
int numA;
void inputA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
};
class B:public A{
protected:
int numB;
void inputB(){
inputA();
cout<<“Enter Value for numB: “;
cin>>numB;
}
};
class C:public B{
protected:
int numC;
public:
void inputC(){
inputB();
cout<<“Enter Value for numC: “;
cin>>numC;
}
void max(){
int temp;
temp=numA>numB?numA:numB;
temp=temp>numC?temp:numC;
cout<<“Greatest Number is: “<<temp<<endl;
}
};
void main(){
C c1;
c1.inputC();
c1.max();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
int numA;
protected:
void inputA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
void outputA(){
cout<<“numA = “<<numA<<endl;
}
};
class B:public A{
int numB;
protected:
void inputB(){
inputA();
cout<<“Enter Value for numB: “;
cin>>numB;
}
void outputB(){
outputA();
cout<<“numB = “<<numB<<endl;
}
};
class C:public B{
protected:
int numC;
public:
void inputC(){
inputB();
cout<<“Enter Value for numC: “;
cin>>numC;
}
void showData(){
outputB();
cout<<“numC = “<<numC<<endl;
}
};
void main(){
C c1;
c1.inputC();
c1.showData();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
protected:
int numA;
public:
void inputA(){
cout<<“Enter Value for numA: “;
cin>>numA;
}
};
class B:public A{
protected:
int numB;
public:
void inputB(){
inputA();
cout<<“Enter Value for numB: “;
cin>>numB;
}
};
class C:public B{
protected:
int numC;
public:
void inputC(){
inputB();
cout<<“Enter Value for numC: “;
cin>>numC;
}
void showData(){
cout<<“numA = “<<numA<<endl;
cout<<“numB = “<<numB<<endl;
cout<<“numC = “<<numC<<endl;
}
};
void main(){
C c1;
c1.inputC();
c1.showData();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
public:
void fun_A(){
cout<<“fun_A() Called”<<endl;
}
};
class B:public A{
public:
void fun_B(){
fun_A();
cout<<“fun_B() Called”<<endl;
}
};
class C:public B{
public:
void fun_C(){
fun_B();
cout<<“fun_C() Called”<<endl;
}
};
void main(){
C c1;
c1.fun_C();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
public:
void fun_A(){
cout<<“fun_A() Called”<<endl;
}
};
class B:public A{
public:
void fun_B(){
cout<<“fun_B() Called”<<endl;
}
};
class C:public B{
public:
void fun_C(){
fun_A();
fun_B();
cout<<“fun_C() Called”<<endl;
}
};
void main(){
C c1;
c1.fun_C();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
public:
void fun_A(){
cout<<“fun_A() Called”<<endl;
}
};
class B:public A{
public:
void fun_B(){
cout<<“fun_B() Called”<<endl;
}
};
class C:public B{
public:
void fun_C(){
cout<<“fun_C() Called”<<endl;
}
};
void main(){
C c1;
c1.fun_A();
c1.fun_B();
c1.fun_C();
}

Filled Under: C++

Sep

09

#include<iostream.h>
class A{
public:
A(){
cout<<“A() Constructor Called”<<endl;
}
};
class B:public A{
public:
/*B(int n){
cout<<“B(int n) Constructor Called”<<endl;
}*/
B(){
cout<<“B() Constructor Called”<<endl;
}
};
class C:public B{
public:
C(int num){
cout<<“C(int num) Constructor Called”<<endl;
}
};
void main(){
C c1(90);
}

Filled Under: C++