Wednesday, April 30, 2008

JAVA Applet Program for doing simple calculation Addition, Substraction, Multiplication

/*
It is a JAVA Applet program for doing simple calculation using GUI. It performs Addition, Substraction, Multiplication Here in this program Buttons, TextField, Labels, CheckboxGroup and Checkbox are used. User has to input values into and A and B textboxes and then choose the appropriate operation such as Add, Sub or mul then press calculate button to perform the choosen operation.
*/


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

public class lademo extends Applet implements ActionListener
{
Button b1;
TextField t1,t2,t3;
Label l1,l2,l3;
String a;
CheckboxGroup cbg;
Checkbox c1,c2,c3;



public void init()
{
setLayout(null);

cbg=new CheckboxGroup();
t1 = new TextField(10);
b1 = new Button("Calculate");
t2 = new TextField(10);
t3 = new TextField(10);

l1 = new Label("A");
l2 = new Label("B");
l3 = new Label("C");

c1 = new Checkbox("Add",cbg,true);
c2 = new Checkbox("Sub",cbg,false);
c3 = new Checkbox("Mul",cbg,false);

add(b1);
add(t1);
add(t2);
add(t3);
add(l1);
add(l2);
add(l3);
add(c1);
add(c2);
add(c3);


l1.setBounds(100,10,100,20);
l2.setBounds(100,30,100,20);
l3.setBounds(100,50,100,20);
t1.setBounds(200,10,100,20);
t2.setBounds(200,30,100,20);
t3.setBounds(200,50,100,20);
b1.setBounds(200,70,100,20);
c1.setBounds(200,90,100,20);
c2.setBounds(300,90,100,20);
c3.setBounds(400,90,100,20);
b1.addActionListener(this);
}


public void actionPerformed(ActionEvent ae)
{

if (ae.getSource()==b1)
{

if (cbg.getSelectedCheckbox().getLabel()=="Add")
{
int z= Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText());
t3.setText(Integer.toString(z));
}

if (cbg.getSelectedCheckbox().getLabel()=="Sub")
{
int z= Integer.parseInt(t1.getText())-Integer.parseInt(t2.getText());
t3.setText(Integer.toString(z));
}

if (cbg.getSelectedCheckbox().getLabel()=="Mul")
{
int z= Integer.parseInt(t1.getText())*Integer.parseInt(t2.getText());
t3.setText(Integer.toString(z));
}

}
}

};


Output of the above program as shown below

Monday, March 31, 2008

Keyboard shortcuts for Mozilla Firefox and Explorer

Keyboard Shortcuts:
Alt + Left Arrow key : To go to back page

Alt + Right Arrow key : To go to next page

Alt + Home key : To go to Home page.

Ctrl + + : To increase font size.

Ctrl + - : To decrease font size

Ctrl + 0 : To Default font size

Ctrl + F : To search any text

Ctrl + G or F3 : To search again last searched

Ctrl + T : To create new tab

Ctrl + N : To create new window

Ctrl + Tab key : To select next tab

Ctrl + W : To close tab.

Ctrl + Shit + T : To restore recently closed tab.

Ctrl + Shift + W : To close window.

Ctrl + F4 : To close tab.

Alt + F4 : To close window

Ctrl + Shift T : Open recently closed tab.

Ctrl + R : Reload

Ctrl + U : To view page source file

Ctrl + Tab key : To select next tab

Ctrl + Shift + Tab key : To select previous tab

Ctrl + 9 : To select last tab

Alt + Enter key : When you typed URL in address bar and you want to open it in a new window then type URL and Press Alt + Enter key.

F11 : To full screen.

F5 : Reload

If you want to Add and Remove buttons in Firefox Standard toolbar by clicking View Menu select Customize in Toolbar option here you can add and remove buttons. To add new button select and drag and drop where you want.


Mouse Shortcuts

Shift + Scroll down button : To go back

Middle click on the tab : To close tab

Ctrl + Scroll Up : To decrease font size

Ctrl + Scroll Down : to increase font size

Double click on tab toolbar : To load new tab

Wednesday, February 27, 2008

Protected member of the class in C++

Protected member of the class can be accessed in class itself and its derived class
but cannot be accessed outside of the class. This example shows the same.
This program will raise an error
#include<iostream.h>
#include<conio.h>
class demo1
{
protected :
int a,b,c;
public:
void add()
{
a=10; // protected members a,b and c are accessed within the class
b=20;
c=a+b;
cout << c <<endl;
}
};

class demo2: public demo1
{
public:
void sub()
{
a=30; // protected members of the class can be accessed in its derived class.
b=20;
c=a-b;
cout << c <<endl;
}
};
main()
{
clrscr();
demo2 d;
d.add();
d.sub();
d.a=50; // protected members can not be accessed outside of the class.
d.b=60;
d.c=d.a+d.b;
cout << d.c <<endl;
getch();
}