R
Rajkumar Singh
what's wrong with this source code.
it is showing the message applet is not initiallising.
--------------------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LinearSearch extends JApplet implements ActionListener
{
JLabel enterLabel;
JTextField enter;
JTextArea outputArea1, outputArea2;
JButton search;
String output;
int a[];
public void init()
{
a=new int[Integer.parseInt(JOptionPane.showInputDialog("how many
numbers, you want to input:"))];
for(int i=0; i<a.length; ++i)
a=Integer.parseInt(JOptionPane.showInputDialog("enter the
integer number."));
output="numbers are:\n";
for(int i=0; i<a.length; ++i)
output += " "+a;
for(int i=1; i<a.length; ++i)
for(int j=0; j<=a.length-1; ++j)
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
output += "\n\nnow numbers are in ascending order.\n";
for(int i=0; i<a.length; ++i)
output += " "+a;
Container c=getContentPane();
c.setLayout(new FlowLayout());
outputArea1=new JTextArea();
c.add(outputArea1);
outputArea1.setText(output);
enterLabel=new JLabel("enter the number, you want to search.");
c.add(enterLabel);
enter=new JTextField(10);
enter.addActionListener(this);
c.add(enter);
outputArea2=new JTextArea();
c.add(outputArea2);
search=new JButton("new search");
search.addActionListener(this);
c.add(search);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == enter)
{
int subscript=linearSearch(a,
Integer.parseInt(e.getActionCommand()));
if(subscript != -1)
outputArea2.setText("number found at position no. "+subscript+"
in the sorted list.");
else
outputArea2.setText("Sorry!!! number not found. \n\nhave a look
on new search");
}
else
JOptionPane.showMessageDialog(null, "Please click on the Applet
menu on the menu Bar.\n"+"click on the clone option.\n"+"Repeat the
search process again.");
}
public int linearSearch(int b[], int k)
{
for(int i=0; i<b.length; ++i)
if(b == k)
return i;
return -1;
}
}
it is showing the message applet is not initiallising.
--------------------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LinearSearch extends JApplet implements ActionListener
{
JLabel enterLabel;
JTextField enter;
JTextArea outputArea1, outputArea2;
JButton search;
String output;
int a[];
public void init()
{
a=new int[Integer.parseInt(JOptionPane.showInputDialog("how many
numbers, you want to input:"))];
for(int i=0; i<a.length; ++i)
a=Integer.parseInt(JOptionPane.showInputDialog("enter the
integer number."));
output="numbers are:\n";
for(int i=0; i<a.length; ++i)
output += " "+a;
for(int i=1; i<a.length; ++i)
for(int j=0; j<=a.length-1; ++j)
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
output += "\n\nnow numbers are in ascending order.\n";
for(int i=0; i<a.length; ++i)
output += " "+a;
Container c=getContentPane();
c.setLayout(new FlowLayout());
outputArea1=new JTextArea();
c.add(outputArea1);
outputArea1.setText(output);
enterLabel=new JLabel("enter the number, you want to search.");
c.add(enterLabel);
enter=new JTextField(10);
enter.addActionListener(this);
c.add(enter);
outputArea2=new JTextArea();
c.add(outputArea2);
search=new JButton("new search");
search.addActionListener(this);
c.add(search);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == enter)
{
int subscript=linearSearch(a,
Integer.parseInt(e.getActionCommand()));
if(subscript != -1)
outputArea2.setText("number found at position no. "+subscript+"
in the sorted list.");
else
outputArea2.setText("Sorry!!! number not found. \n\nhave a look
on new search");
}
else
JOptionPane.showMessageDialog(null, "Please click on the Applet
menu on the menu Bar.\n"+"click on the clone option.\n"+"Repeat the
search process again.");
}
public int linearSearch(int b[], int k)
{
for(int i=0; i<b.length; ++i)
if(b == k)
return i;
return -1;
}
}