Wednesday, 10 April 2013

INFORMATION


PLEASE FEEL FREE TO ASK ANY DOUBTS ABOUT THE WORKING OF THE PROGRAM.
IF YOU HAVE ANY PROBLEM REGARDING THE EXECUTION OF ANY OF THE PROGRAMS YOU CAN COMMENT ON THE PROGRAM . I'LL DEFINITELY REPLY TO YOUR QUERIES .

REGARDS
SHWETHA (FOUNDER)

JAVA PROGRAMS USING SWINGS PART 2 CONTINUNITY OF THE PREVIOUS SWING PROGRAM



package GUI;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;


public class ProgressBarEg extends JPanel {
static ProgressThread pth; 
static JProgressBar pb;
static JFrame jf; 

public ProgressBarEg() {
setLayout(new BorderLayout()); 
pb = new JProgressBar(); 
JPanel btnpanel = new JPanel();
JButton startbtn = new JButton("Start");
btnpanel.add(startbtn); 
btnpanel.add(pb,"Center");
startbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
startProgressBar(); 
}
}); 
JButton stopbtn = new JButton("Stop");
btnpanel.add(stopbtn); 
    stopbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
stopProgressBar(); 
}
}); 
add(btnpanel);
}//end constructor 
public void startProgressBar() {

if(pth == null || pth.isAlive()) {
pth = new ProgressThread(pb);
pth.start(); 
}
}//end method 
public void stopProgressBar() {
pth.setStop(true); 
}//end method 
public static void main(String a[]){
jf = new JFrame("Copying Files..."); 
ProgressBarEg objpbar = new ProgressBarEg(); 
jf.getContentPane().add("Center", objpbar); 
jf.setSize(200,100); 
jf.addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent we){
System.exit(0); 
}
}); 
jf.setVisible(true); 
}//end main 
}//end ProgressBarEg 

class ProgressThread extends Thread {
JProgressBar pb; 
boolean stopStatus = false; 
boolean aliveStatus = false;
public ProgressThread(JProgressBar pb){
this.pb = pb;
}//end constructor 
public void setStop(boolean value){
stopStatus = value; 
}//end method 
public void run(){
int mini = 0; 
int max = 30; 
pb.setMinimum(mini); 
pb.setMaximum(max); 
for (int x = mini; x<=max; x++){
if(stopStatus){
break; 
}
else {
pb.setValue(x); 
try {
Thread.sleep(100); 
}
catch(InterruptedException ie){
}
}//end else 
}//end for 
aliveStatus=false; 
}//end run method 
}//end class ProgressThread 

JAVA PROGRAMS USING SWINGS PART 1


package GUI;
import javax.swing.*;

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

public class Five extends JPanel implements ActionListener, ItemListener {

String name,hobby,address,citizenship;
static JLabel jl1;

static JMenuBar jmb;
static JMenu jm1;
static JMenuItem jmit1, jmit2, jmit3;
static JTextField jtf;
static JCheckBox jcb;
static JLabel jl2;
static JComboBox jcmb;
static JLabel jl3;
static JTextArea jta;
static JButton jb;
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==jb){
name=jtf.getText();
address=jta.getText();
String tooltip = jb.getToolTipText();
citizenship=jcb.getText();
System.out.println(ae.getActionCommand()+" Was Pressed ");
System.out.println("Name Entered is "+name);
System.out.println(" Address is "+address);
System.out.println(" Citizeship is "+citizenship);
System.out.println(" Tool Tip Text Value for Button is "+tooltip);
}
/*if(ae.getSource()==jcmb){
System.out.println(ae.getActionCommand()+" Was Pressed ");
hobby=(String)jcmb.getSelectedItem();
System.out.println("Hobby Selected is "+hobby);

}*/

}//end actionPerformed

public void itemStateChanged(ItemEvent e){
if(e.getSource() ==jcmb){
if(jcmb.getSelectedItem().equals("Painting")){
System.out.println("Hello Junior MF Hussain!!");
}
else if(jcmb.getSelectedItem().equals("Dancing")){
System.out.println("Hello Junior Vani Ganapathi!!");
}
else if(jcmb.getSelectedItem().equals("Singing")){
System.out.println("Hello Junior Asha Bhosle!!");
}
}
}

public static void main(String a[]){
Five objfive = new Five();
JFrame jf = new JFrame("Frame");
JPanel jp = new JPanel();
jf.add(jp);
jl1 = new JLabel("Enter Your Name");
jtf = new JTextField(15);
jcb = new JCheckBox("Indian Citizen",true);
jl2 = new JLabel("Choose Your Hobby");
jcmb = new JComboBox();
jcmb.addItem("Painting");
jcmb.addItem("Dancing");
jcmb.addItem("Singing");
jcmb.addItem("Trekking");
jl3 = new JLabel("Enter Your Address");
jta = new JTextArea(20,20);
jb = new JButton("Click Me");
jb.setBounds(20,20,120,120);
jb.setToolTipText("Submit Values...See Console");
jmb = new JMenuBar();
jm1 = new JMenu("File");
jm1.setMnemonic(KeyEvent.VK_F);
jmit1 = new JMenuItem("Open");
jmit1.setMnemonic(KeyEvent.VK_O);
        jmit2 = new JMenuItem("Save");
        jmit2.setMnemonic(KeyEvent.VK_S);
        jmit3 = new JMenuItem("Exit");
        jmit3.setMnemonic(KeyEvent.VK_X);
        jmit3.setToolTipText("Exit application");
        jm1.add(jmit1);
        jm1.add(jmit2);
        jm1.add(jmit3);
        jmb.add(jm1);
        //setJMenuBar(jmb);
        jf.setTitle("Simple menu");
jp.add(jl1);
jp.add(jtf);
jp.add(jcb);
jp.add(jl2);
jp.add(jcmb);
jp.add(jl3);
jp.add(jta);
jb.addActionListener(objfive);
//jcmb.addActionListener(objfive);
jcmb.addItemListener(objfive);
jp.add(jb);
//jf.add(jmb);
jf.setSize(400,400);
jf.setVisible(true);
}//end main
}//end class Five

Wednesday, 27 March 2013

JAVA PROGRAMS USING LINKEDLIST, GENERIC COLLECTIONS FOR STUDENT LIST


 import java.util.*; /* scanner function is used*/

class StudList {
  private String name;
  private String USN;
  private String college;

   StudList(String n, String s, String c) {
    name = n;
    USN = s;
    college = c;
  }

  public String toString() {
    return name + ":" + USN + ":" + college;
  }
}

public class FourB {
  public static void main(String args[]) 
{
  LinkedList<StudList> ml = new LinkedList<StudList>();

  ml.add(new StudList("Shwetha", "1MS00IS101", "MSRIT"));
  ml.add(new StudList("Mishti", "1MS00IS102", "RVCE"));
  ml.add(new StudList("Purvi ", "1MS00IS103","BMSCE"));
  ml.add(new StudList("Aditya", "1MS00IS104", "PESIT"));
  ml.add(new StudList("Rohit", "1MS00IS105", "NMIT"));


System.out.println("Accessing Via Iterator....");
Iterator<StudList> it = ml.iterator();

while (it.hasNext()) {
   String element=it.next().toString();
   System.out.println(element + "");
}

System.out.println("Number of students in the list: "+ml.size());

System.out.println("Which student do you want to remove?");
Scanner s = new Scanner(System.in);
int pos = s.nextInt();
ml.remove(pos);

System.out.println("New Kind of For Loop...List is now...");
    for (StudList element : ml){
      System.out.println(element);
    }
System.out.println("Number of students in the list is"+ml.size());
System.out.println("Shuffling the list...");
Collections.shuffle(ml);
System.out.println("List after shuffling is ...");
    for (StudList element : ml){
      System.out.println(element);
    }

System.out.println("First Student is :"+ml.getFirst());
System.out.println("Last Student is :"+ml.getLast());
  }
}



Sunday, 24 March 2013

CN2 LEAKY BUCKET PROGRAM


#include<stdio.h>
#include<stdlib.h>
#define MIN(x,y) (x>y)? y:x
int main()
{

    int orate, drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
    printf("\n enter the bucket size");
    scanf("%d",&cap);
    printf("\n enter the output rate");
    scanf("%d",&orate);
    do
    {
        printf("\n enter the number of packets coming at second %d",i+1);
        scanf("%d",&inp[i]);
        i++;
        printf("\n press 1 to continue or 0 to exit------");
        scanf("%d",&ch);
        }
         while(ch);
         nsec=i;
        printf("\n sec\t rec\t sent\t drop\t rem\n");
        for(i=0;count||i<nsec;i++)
       {
        printf("%d",i+1);
        printf("\t %d\t",inp[i]);
        printf("%d\t", MIN((inp[i]+count),orate));
        if((x=inp[i]+count-orate)>0)
        {
           if(x>cap)
           {
             count=cap;
            drop=x-cap;
            }
            else
            count=x;
            drop=0;
            }
        else
        {
        drop=0;
        count=0;
        }
        printf("%d\t %d\n",drop,count);
    }
    }
    


Thursday, 7 March 2013

SS pass1 assembler program


there following files have to be included in the program 
# include <stdio.h>
# include <string.h>
void main()
{
char opcode[10],mnemonic[3],operand[10],label[10],code[10];
int locctr,start,length;
FILE *fp1,*fp2,*fp3,*fp4;
fp1=fopen("input.txt","r");
fp2=fopen("symtab.txt","w");
fp3=fopen("out.txt","w");
fp4=fopen("optab.txt","r");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start=atoi(operand);
locctr=start;
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%d\t",locctr);
if(strcmp(label,"**")!=0)
fprintf(fp2,"%s\t%d\n",label,locctr);
rewind(fp4);
fscanf(fp4,"%s",code);
while(strcmp(code,"END")!=0)
{
if(strcmp(opcode,code)==0)
{
locctr+=3;
break;
}
fscanf(fp4,"%s",code);
}
if(strcmp(opcode,"WORD")==0)
locctr+=3;
else if(strcmp(opcode,"RESW")==0)
locctr+=(3*(atoi(operand)));
else if(strcmp(opcode,"RESB")==0)
locctr+=(atoi(operand));
else if(strcmp(opcode,"BYTE")==0)
++locctr;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
fprintf(fp3,"%d\t%s\t%s\t\%s\n",locctr,label,opcode,operand);
length=locctr-start;
printf("The length of the program is %d",length);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
}

INPUT FILES

input.txt


** START 2000
** LDA FIVE
** STA ALPHA
** LDCH CHARZ
** STCH C1
ALPHA RESW 1
FIVE WORD 5
CHARZ BYTE C’Z’
C1 RESB 1
** END **

optab.txt

START
LDA
STA
LDCH
STCH
END


OUTPUT FILES

out.txt

** START 2000
2000 ** LDA FIVE
2003 ** STA ALPHA
2006 ** LDCH CHARZ
2009 ** STCH C1
2012 ALPHA RESW 1
2015 FIVE WORD 5
2018 CHARZ BYTE C’Z’
2019 C1 RESB 1
2020 ** END **

symtab.txt

ALPHA 2012
FIVE 2015
CHARZ 2018
C1 2019




JAVA PACKAGES PROGRAMS


We have to create 3 different packages for this program  and execute  it.

Vehicle.java



package package1;

public abstract class Vehicle
{    
            public int year;
            public abstract void getData();
            public abstract void putData();
}

class FourWheeler extends Vehicle{
            public void getData()
            {
                  year=92;
            }
            public void putData()
            {
                  System.out.println("Year of manufacture of the fourwheeler is"+year);
            }
}
 

prog2.java

package package2;
import package1.*;
class TwoWheeler extends Vehicle{
      private String EngineType="2-s";
      protected String Brand="Y";
      public String Color="Black";
      public void getData()
      {
                  EngineType="2-stroke";
                  Brand="Yamaha";
                  Color="Black";
                  year=88;
      }
      public void putData()
      {
                  System.out.println("Year of manufacture of the twowheeler is"+year);
                  System.out.println("Engine type is " +EngineType+" ,Brand is "+Brand+" ,Color is "+Color);
      }
            void printprivate()
      {
                  System.out.println("Accessing private variable"+ EngineType);
      }
      }
class MyTwoWheeler extends TwoWheeler
{
      public String OwnerName;
      MyTwoWheeler()
      {
            super();
            OwnerName="Mandhara";
            printprivate();
            System.out.println(""+Brand+" "+Color+" "+OwnerName);
      }
     
}

public class prog2 {
      public static void main(String[] args)
      {
            TwoWheeler a=new TwoWheeler();
            a.getData();
            a.putData();
            MyTwoWheeler b=new MyTwoWheeler();
      }

}
 

prog.java

package package3;

public class prog {

}