Skip to main content

Posts

Showing posts from December, 2011

Java Sample: Working with TextField

import java.awt.*; import java.awt.event.*; import java.applet.*; public class JTextFieldTest extends Applet implements ActionListener { TextField name,pass; public void init() { Label nameL=new Label("User Name :: ",Label.RIGHT); Label passL=new Label("Password  :: ",Label.RIGHT); name=new TextField(10); pass=new TextField(10); pass.setEchoChar('*'); add(nameL); add(name); add(passL); add(pass); name.addActionListener(this); pass.addActionListener(this); } public void actionPerformed(ActionEvent ae) { repaint(); } public void paint(Graphics g) { g.drawString("USER NAME :: "+name.getText(),6,60); g.drawString("PASSWORD IS :: "+pass.getText(),6,80); } }

Java Sample : Applet with Checkbox control

//Java ItemListener  import java.awt.*; import java.applet.*; import java.awt.event.*; public class JCheckBox extends Applet implements ItemListener { String msg=""; Checkbox winXP,winVista,Solaris,Mac; public void init() { winXP=new Checkbox("Windows XP"); winVista=new Checkbox("Windows Vista"); Solaris=new Checkbox("Solaris"); Mac=new Checkbox("Mac"); add(winXP); add(winVista); add(Solaris); add(Mac); winXP.addItemListener(this); winVista.addItemListener(this); Solaris.addItemListener(this); Mac.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current State :: "; g.drawString(msg,6,80); msg="Windows XP :: "+winXP.getState(); g.drawString(msg,6,100); msg="Windows Vista :: "+winVista.getState(); g.drawString(msg,6,120); msg="Solaris ::

C Sample: Bubble, Selection & Insertion Sort [o(n2)]

#include<stdio.h> #include<conio.h> int list[8]={82,42,49,8,92,25,59,52}; void declare() { int list[8]={82,42,49,8,92,25,59,52}; printf("\n"); } void BubbleSort() { int i,j,k; declare(); printf("\n\t\tBUBBLE SORT\n"); for(i=0;i<=7;i++) { for(j=0;j<=7;j++) { if(list[i]<list[j]) { k=list[j]; list[j]=list[i]; list[i]=k; } } printf("\nPhase :: %d",i); display(); } } void SelectionSort() { int i,j,f; declare(); printf("\n\t\tSELECTION SORT\n"); for(i=0;i<=7;i++) { for(j=i+1;j<=7;j++) { if(list[i]>list[j]) { f=list[j]; list[j]=list[i]; list[i]=f; } } printf("\nPhase :: %d",i); display(); } } void InsertionSort() { int i,j,k; declare(); printf("\n\t\tINSERTION SORT\n"); for(i=0;i<=7;i++) { for(j=0;j<=i;j++) { if(list[j]>list[i]) { k=list[i]

C Sample: String Comparison In C Language

#include<stdio.h> #include<conio.h> #include<string.h> main() { char str1[30],str2[30]; clrscr(); printf("\nEnter 1st String"); gets(str1); printf("\nEnter 2nd String"); gets(str2); if(compare(*str1,*str2)==1) { printf("\nStrings are not same"); }else { printf("\nStrings are same"); } getch(); } int compare(char *str1,char *str2) { while(*str1!='\0' || *str2!='\0') { if(*str1==*str2) { str1++;str2++; }else{return(1);} } return(0); }

C Sample: String Concatenation In C Language

#include<stdio.h> #include<conio.h> #include<string.h> main() { char str1[30],str2[30]; printf("\nEnter 1st String"); gets(str1); printf("\nEnter 2nd String"); gets(str2); concat(str1,str2); printf("Output :: %s",str1); getch(); } concat(char *str1,char *str2) { while(*str1!='\0') str1++;      //Points to end of line while(*str2!='\0') { *str1=*str2; str1++; str2++; }*str1='\0'; }

Java Sample: Super keyword in java

class Jsuper { public void show() { System.out.println("\nThis is from SUPER class"); } } class Jsub extends Jsuper { public void show() { System.out.println("\nThis is from SUB class"); super.show(); // calling the function from parent class } } class JsuperTest { public static void main(String args[]) { Jsub ob=new Jsub(); ob.show(); } }

Java Sample: Method Overriding, Overloading and Constructor, this keyword

import java.io.*; class A { public int sum(int i,int j) { return(i+j); } } class B extends A { public float sum(float i,float j) // Method Overriding { return(i+j); } B() // Constructor is using to run SUM method by THIS keyword { System.out.println(this.sum(22.95F,66.52F)); } } class Jtest { public static void main(String args[]) { A oA=new A(); System.out.println(oA.sum(6,5)); B oB=new B(); System.out.println(oB.sum(90.50F,66.52F)); // Overring Is Calling... System.out.println(oB.sum(22,44)); // Method is Overloading.... //oB.goAction(); } }