title: linked list using JApplet
body: <p>this is one of the assignments in my college..i have a linked list using JApplet and there r 3 problem that i m facing first i want that after clicking the Insert_Front button the new button should be placed before any button that is present on the panel and not at the last(ex- a button whose value is 5 which is already present and after clicking the Insert_Front button the new button created should be placed before the button 5)2nd problem is that after clicking the Del_Front button the first button is to be removed and not the last one and finally the search button is not being able to find a button which is present in the panel..solutions are welcome..here is the code..   </p>
  
  <pre><code>public interface BasicLinkedList1&lt;itemtype&gt;  
  {
     public void insert_front(itemtype item);
     public void delete_front();
     public void insert_rear(itemtype item);
  }
  public interface listsearch&lt;itemtype&gt;  
  {
     public void search(itemtype v);
  }
  
  
  import java.awt.*;
  import javax.swing.*;
  import java.util.*;
  import java.awt.event.*;
  /* &lt;applet code="LinkedListApplet.class" height=300 width=500&gt;&lt;/applet&gt;*/
  public class LinkedListApplet extends JApplet implements listsearch&lt;JButton&gt;,BasicLinkedList1&lt;JButton&gt;
  {
      JButton Insert_Front,Insert_Rear,Del_Front,search;
      JLabel label;JPanel npanel,spanel;JTextField field;
      LinkedList&lt;JButton&gt; linklist;
      public void init()
      {
          EventQueue.invokeLater(new Runnable()
          {
              public void run()
              {
                  makegui();
              }
          });
      }
      void makegui()
      {
          linklist = new LinkedList&lt;JButton&gt;();
          npanel = new JPanel();
          spanel = new JPanel();
          label = new JLabel();
          field = new JTextField(40);
          spanel.setLayout(new FlowLayout());
          npanel.setLayout(new GridLayout(2,5));
          listener list = new listener();
          Insert_Front = new JButton("Insert_Front");
          Insert_Front.addActionListener(list);
          npanel.add(Insert_Front);
          Insert_Rear = new JButton("Insert_Rear");
          Insert_Rear.addActionListener(list);//adding listener for buttons
          npanel.add(Insert_Rear);
          Del_Front=new JButton("Del_Front");
          Del_Front.addActionListener(list);
          npanel.add(Del_Front);
          search=new JButton("search");
          search.addActionListener(list);
          npanel.add(search);
          npanel.add(field);
          npanel.add(label,SwingUtilities.CENTER);
          add(npanel,BorderLayout.NORTH);
          add(spanel,BorderLayout.CENTER);
      }
      private class listener implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              String cmd=e.getActionCommand(),text="";
              System.out.println(cmd);
              if(cmd.equals("Insert_Front"))
              {
                  text=field.getText();
                  if(text.length()==0)
                      label.setText("enter some value!!!");
                  else
                  {
                      label.setText("node successfully created");  
                      insert_front(new JButton(text));
                  }
              }
              else if(cmd.equals("Insert_Rear"))
              {
                  text=field.getText();
                  if(text.length()==0)
                      label.setText("enter some value!!!");
                  else
                  {
                      label.setText("node successfully created");  
                      insert_rear(new JButton(text));
                  }
              }
              else if (cmd.equals("Del_Front"))
              {
                  label.setText("node successfully destroyed");  
                  delete_front();
              }
              else if(cmd.equals("search"))
                  search(new JButton(text));
          }        
      }
  
      public void search(JButton b)
      {
          if(linklist.contains(b))
          {
              label.setText("element found:"+b.getText());
          }
          else
              label.setText("no such elements");
      }
  
      public void insert_front(JButton item)
      {
          linklist.addFirst(item);
          ListIterator&lt;JButton&gt; itr=linklist.listIterator();
          JButton b=itr.next();
          spanel.add(b);
      }
  
      public void delete_front()
      {
          JButton b=null;
          if(linklist.size()==0)
              label.setText("cannot delete node,list is empty!");
          else
          {
              b=linklist.removeFirst();
              spanel.remove(b);
          }
      }
  
      public void insert_rear(JButton item)
      {
          linklist.addLast(item);JButton s=null;
          ListIterator&lt;JButton&gt; itr=linklist.listIterator();
          while(itr.hasNext())
              s=itr.next();
          JButton b=s;
          spanel.add(b);
      }
  }
  </code></pre>