Skip to main content

Posts

Showing posts from April, 2014

Java Applet MouseListener example

import java.applet.*; import java.awt.*; import java.awt.event.*; public class MouseEventHandle extends Applet implements MouseListener{ String message="\0"; int Xcoordinate=0, Ycoordinate=20; public void mouseClicked(MouseEvent e){ message="Mouse Clicked Event"; repaint(); } public void mouseEntered(MouseEvent e){ message="Mouse Entered Event"; repaint(); } public void mouseExited(MouseEvent e){ message="Mouse Exited Event"; repaint(); } public void mousePressed(MouseEvent e){ message="Mouse Pressed Event"; repaint(); } public void mouseReleased(MouseEvent e){ message="Mouse Released Event"); repaint(); } public void mouseMoved(MouseEvent e){ message="Mouse Moved Event"; showstatus(message); } public void paint(Graphics g){ g.drawString(message, Xcoordinate, Ycoordinate); } }

Java Applet KeyListener example

import java.appleat.*; import java.awt.*; import java.awt.event.*; public class KeyListenerExample extends Applet implements KeyListener{ String pstr="This is your KeyListener class example"; public void init(){ addKeyListener(this); } public void keyPressed(KeyEvent e){ showstatus("You have pressed a key"); } public void keyReleased(KeyEvent e){ showstatus("You have released the key"); } public void paint(Graphics g){ g.drawString(pstr, 20, 40); } public void keyTyped(KeyEvent e){ repaint(); } }

Java applet passing values using parameters example

import java.applet.*; public class ParameterExample extends Applet{ String str; int a, b, sum; public void init(){ pstr=getParameter("msg"); a=Integer.parseInt(getParameter("first")); b=Integer.parseInt(getParameter("second")); sum=a+b; repaint(); } public void paint(Graphics g){ g.drawString("First Number: "+a, 20, 40); g.drawString("Second Number: "+b, 20, 60); g.drawString("Sum: "+sum, 20, 80); } } HTML:- <html> <head> <title>Java Applet</title> </head> <body> <applet code="ParameterExample.class" width="600" height="250"> <param name="msg" value="Add"/> <param name="first" value="52"/> <param name="second" value="87"/> </applet> </body> </html>

C++ program to perform addition and multiplication using inheritance

#include<iostream.h> #include<conio.h> class a{ public: int no1, no2; void put(); }; void a::put(){ cout<<"Enter two numbers:-"<<endl; cin>>no1>>no2; } class b:public virtual a{ public: int sum; void add(); }; void b::add(){ sum=no1+no2; } class c:public virtual a{ public: int pro; void multiply(); }; void c::multiply(){ pro=no1*no2; } class d:public b, public c{ public: display(); }; void d::display(){ cout<<"Sum: "<<sum<<"\nProduct: "<<pro<<endl; } void main(){ d obj(); clrscr(); d.put(); d.add(); d.multiply(); d.display(); getch(); }

C++ program to swap the values of four variables without using fifth variable

#include<iostream.h> #include<conio.h> int a, b, c, d; void main(){ clrscr(); cout<<"Enter four numbers:"<<endl; cin>>a>>b>>c>>d; a=a+b+c+d; b=a-b-c-d; c=a-b-c-d; d=a-b-c-d; a=a-b-c-d; cout<<"Before swapping the values:- "<<endl<<"A:"<<a<<endl<<"B:"<<b<<endl<<"C:"<<c<<endl<<"D:"<<d<<endl<<"After swapping the values:-"<<endl<<"A:"<<a<<endl<<"B:"<<b<<endl<<"C:"<<c<<endl<<"D:"<<d; getch(); }

C++ program declaring class & object

#include<iostream.h> #include<conio.h> #include<iomanip.h> class Student{ private: char a[5][10]; int r[5], c[5], f[5], i; public: void input(); void display(); }; void Student::input(){ cout<<"Enter Name, Class, Roll Number & Fee of five students"<<endl; for(i=0; i<5; i++){ cout<<(i+1)<<". Student:"<<endl; cin>>a[i]>>c[i]>>r[i]>>f[i]; } } void Student::display(){ cout<<"Name"<<setw(25)<<"Class"<<setw(25)<<"Roll Number"<<setw(25)<<"Fee"<<endl; for(i=0; i<5; i++){ cout<<a[i]<<setw(25)<<c[i]<<setw(25)<<r[i]<<setw(25)<<f[i]<<endl; } } void main(){ Student obj; clrscr(); obj.input(); obj.display(); getch(); }

JQuery dragaable example

<html>     <head>         <title>Draggable</title>         <script src="jquery.js"></script>         <script src="jquery-ui.js"></script>         <style>             #draggable{                 width: 150px;                 height: 150px;                 padding: 0.5em;             }         </style>         <script>          ...

PHP create an image with custom text, background and foreground colors

PHP code:- <?php header("Content-Type: image/png"); $size = NULL; $x = NULL; $height = NULL; $y = NULL; /* $fonts = array("font.ttf", "font bd.ttf");   shuffle($fonts);   $font = $fonts[0]; */ $font = "font.ttf"; if (!isset($_GET["favicon"]) && !isset($_GET['image-min'])) {     $width = NULL;     if (isset($_GET["width"]))         $width = $_GET["width"];     if ($width > 920) {         $size = 100;         $height = 110;     } elseif ($width < 920 && $width > 750) {         $size = 50;         $height = 60;     } elseif ($width < 750 && $width > 550) {         $size = 30;         $height = 40; ...

Java program to perform binary addition

import java.util.*; public class BinaryAddition {     private Scanner scan;     private String num1, num2, binary;     public BinaryAddition() {         scan = new Scanner(System.in);         num1 = num2 = binary = "";     }     public void input() {         try {             System.out.printf("Enter First Number: ");             num1 = scan.next();             if (!isBinary(num1)) {                 System.err.printf("Binary Number Expected.");                 System.exit(0);    ...

Java program to print fibonacci series in reverse order

import java.util.*; public class FabonicRev {     Scanner scan;     int a1, b1, c1, a2, b2, c2, limit, i;     public FabonicRev() {         scan = new Scanner(System.in);         a1 = c1 = 1;         b1 = a2 = b2 = c2 = limit = i = 0;     }     public void input() {         try {             System.out.printf("Enter limit: ");             limit = scan.nextInt();             scan.close();         } catch (InputMismatchException | NumberFormatException e) {             System.err.println("Error Occurred!");   ...

Java program to perform number system conversions

import java.util.*; interface ConversionBase {     Scanner scan = new Scanner(System.in);     byte bin = 2, dec = 10, hex = 16, oct = 8;     char hex1[] = new char[]{'A', 'B', 'C', 'D', 'E', 'F'};     int hex2[] = new int[]{10, 11, 12, 13, 14, 15}; } class Number implements ConversionBase {     String nm;     char ch;     long num;     byte base;     int i;     public Number() {         nm = "\0";         ch = '\0';         num = i = base = 0;     }     public boolean isBinary(long num) {         nm = Long.toString(num);         for (; i < nm.length(); i++) {             ch ...