Sunday, October 27, 2013

Queue implementation in Java Applet Frame

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class que_2 extends JFrame implements ActionListener {
JTextField t1;
String abc="";
JButton b1,b2,b3;
JLabel l1,l3;
int arr[]=new int[50];
int str=0;
int end=0;
que_2()
{
     setTitle("Queue");
     setLayout(new FlowLayout());
     t1=new JTextField(10);
     add(t1);
b1=new JButton("Insert");
add(b1);
b1.addActionListener(this);


b2=new JButton("Remove"); 
add(b2);
b2.addActionListener(this);
b3=new JButton("Exit");   
add(b3);
b3.addActionListener(this);
l1=new JLabel("Message");
//l2=new JLabel("Stack is");
l3=new JLabel();
add(l1);
//add(l2);
add(l3);
//add(l);
}
public static void main(String args[])
{
que_2 f=new que_2();
f.setSize(500, 500);
f.setVisible(true);

 }
public void actionPerformed(ActionEvent ae)
{//int i=9,j=0;
String strn="";
strn=ae.getActionCommand();
if(strn=="Insert")
{
     //l2=new JLabel("");
           //int x;
           if(end!=49)
           {         
           arr[end]=Integer.parseInt(t1.getText());
           t1.setText(null);
           end++;
           }
                else
                {l1.setText("operation can not be performed");}
           for(int i=str;i<end;i++)
           {
                abc=abc+" "+arr[i];
           }
           l3.setText(abc);
           //i--;
           abc="";
}
if(strn=="Remove")
{
     //l2.setText("0");
     if(str!=end)
     {
           str++;
           int x=arr[str];

     //cout<<x<<endl;
}

     else
     {
          
           l1.setText("operation can not be performed");
     }
     for(int i=str;i<end;i++)
     {
           abc=abc+" "+arr[i];
     }
     l3.setText(abc);
     //i--;
     abc="";
}
else if(strn=="Exit")
{
      System.exit(0);    
}
}
}




No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...