applet is not initiallising.

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;
}
}
 
I

IchBin

Rajkumar said:
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;
}
}


Try using an IDE debugger. Your error is this..

java.lang.ArrayIndexOutOfBoundsException: 4
at LinearSearch.init(LinearSearch.java:34)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)



Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

Rajkumar said:
what's wrong with this source code.

[snip ]
for(int i=1; i<a.length; ++i)
for(int j=0; j<=a.length-1; ++j)

Line 34 > if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
[snip]

it is asking for no. of elements. and input the numbers. but after then
applet is not able to initialise.



Try using an IDE debugger. Your error is this..

java.lang.ArrayIndexOutOfBoundsException: 4
at LinearSearch.init(LinearSearch.java:34)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

IchBin said:
Rajkumar said:
what's wrong with this source code.

[snip ]
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;
}
[snip]


It would make better sense to replace the above code with this:

Arrays.sort(a);

Your naming convention is unreadable.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
A

Andrew T.

Rajkumar said:
what's wrong with this source code.

it is showing the message applet is not initiallising.

This message is common for IE that is using the MSVM
(Java 1.1) when you try to use..
.....
import javax.swing.*;

...Swing, or anything else 1.2+.

(Though it seems IchBin has identified further problems in the code.)

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top