applet is not initiallising.  
Author Message
Rajkumar Singh





PostPosted: 2006-6-4 17:07:00 Top

java-programmer, applet is not initiallising. 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[i]=Integer.parseInt(JOptionPane.showInputDialog("enter the
integer number."));

output="numbers are:\n";
for(int i=0; i<a.length; ++i)
output += " "+a[i];

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[i];

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[i] == k)
return i;

return -1;
}
}

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

 
IchBin





PostPosted: 2006-6-5 3:20:00 Top

java-programmer >> applet is not initiallising. Rajkumar Singh wrote:
> 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[i]=Integer.parseInt(JOptionPane.showInputDialog("enter the
> integer number."));
>
> output="numbers are:\n";
> for(int i=0; i<a.length; ++i)
> output += " "+a[i];
>
> 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[i];
>
> 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[i] == k)
> return i;
>
> return -1;
> }
> }
>
> ---------------------------------------------------------------------------------------------------------------------------------------
> 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-)
 
IchBin





PostPosted: 2006-6-5 3:26:00 Top

java-programmer >> applet is not initiallising. Rajkumar Singh wrote:
> 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-)
 
 
IchBin





PostPosted: 2006-6-5 3:44:00 Top

java-programmer >> applet is not initiallising. IchBin wrote:
> Rajkumar Singh wrote:
>> 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-)
 
 
Andrew T.





PostPosted: 2006-6-5 13:18:00 Top

java-programmer >> applet is not initiallising.
Rajkumar Singh wrote:
> 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.