The Artima Developer Community
Sponsored Link

Java Answers Forum
applet not running

7 replies on 1 page. Most recent reply: Jul 17, 2004 1:52 AM by Aing Roda

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
Aing Roda

Posts: 9
Nickname: roda
Registered: Jul, 2004

applet not running Posted: Jul 13, 2004 7:17 PM
Reply to this message Reply
Advertisement
Hi there,


I am having problem with my java applet code. I have the following FirstLine.java file.


import java.io.*;
import java.applet.*;
import java.awt.*;
 
class getValue
{
	int count=0;
	int[] y = new int[1560];
	public void getx() throws IOException
	{
		FileInputStream LogFile = new 
FileInputStream("Record.log");
		DataInputStream in = new DataInputStream(LogFile);
		while (in.available() !=0) 
		{ 
			y[count] = Integer.parseInt(in.readLine());
			count++;
		}			
	}		
};
 
public class FirstLine extends Applet
{
	public void paint(Graphics g)
	{	
		getValue x;
		x = new getValue();
		try
		{
			x.getx();
		}
		catch (IOException e)
		{
			g.drawString("File not found", 100, 100);
		}
		this.setBackground(Color.white);
		g.drawString("Mobitel", 100, 100);
		this.setForeground(Color.blue);
		for (int i=0; i < 383; i++)
		{
			g.drawLine(i, 300-x.y[i], i, 300-x.y[i+1]);
		}
	}
};



And below is my html code of the file named FirstLine.html


<applet code=FirstLine.class width=400 height=300>
</applet>
[code]

The problem is that I can sucessfully run the applet in appletviewer, but failed to run in web browser. I am using Internet Explorer.

Can anyone help me to correct my code?

Thanks


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: applet not running Posted: Jul 14, 2004 9:11 PM
Reply to this message Reply
g.drawLine(i, 300-x.y, i, 300-x.y[i+1]);

This does not even compile.

--------

I commented the line which was giving compilation error and opened FirstLine.html in the browser and your applet displayed the string "File not found"

KevinT

Posts: 24
Nickname: metzedler
Registered: Jun, 2003

Re: applet not running Posted: Jul 15, 2004 8:55 PM
Reply to this message Reply
Hi,

I think firstly

g.drawLine(i, 300-x.y, i, 300-x.y[i+1]);


is wrong because, you're suppose to do 300 - an element of y array ( y) not y array i think.
it should be
g.drawLine(i, 300-x.y, i, 300-x.y[i+1]);
or whatever coordinate you like.


next you seems want to open a file called Record.log, you should have that file in the same folder then i should works

Cheers

KevinT

Posts: 24
Nickname: metzedler
Registered: Jun, 2003

Sorry something wrong w typng Posted: Jul 15, 2004 8:59 PM
Reply to this message Reply
it should be
g.drawLine(i, 300-x.y[i], i, 300-x.y[i+1]);

or whatever coordinate you like.

KevinT

Posts: 24
Nickname: metzedler
Registered: Jun, 2003

Re: Sorry something wrong w typing Posted: Jul 15, 2004 9:11 PM
Reply to this message Reply
it should be

g.drawLine(i, 300-x.y[i+2], i, 300-x.y[i+1]);


or whatever coordinate you like.

Aing Roda

Posts: 9
Nickname: roda
Registered: Jul, 2004

Re: Sorry something wrong w typing Posted: Jul 16, 2004 12:42 AM
Reply to this message Reply
Hi there

The correct code is:


g.drawLine(i, 300-x.y[i], i, 300-x.y[i+1]);


This line of code is correct, but the italic text formatting changed my code. That's why all text after 300-x.y become italic.

Note: The code can run in applet viewer, but can not run in web browser.

Any idea?

Roda

KevinT

Posts: 24
Nickname: metzedler
Registered: Jun, 2003

maybe the log file or your IE option is ot correct Posted: Jul 16, 2004 7:48 PM
Reply to this message Reply

<html>
<body>
<applet code=FirstLine.class width=400 height=300>
</applet>
</body>
</html>


I've this code for a htm page, it works fine.
So what happen when you embeded the code in your page, blank or a applet started or what?
- Make sure you've the Record.log file with some figures inside
- Check your web browser, what are you using ? (IE or netscape ?)
If IE then go to the internet option:
go to advanced tab and look in the tick box inside, and check evry box that's related to Java ( Microsoft VM, JIT,...)

Hope this help

Aing Roda

Posts: 9
Nickname: roda
Registered: Jul, 2004

Re: maybe the log file or your IE option is ot correct Posted: Jul 17, 2004 1:52 AM
Reply to this message Reply
Hi KevinT and SinghM,

I have done that. I have fixed my problem.

Thank you very much for your help.

Roda

Flat View: This topic has 7 replies on 1 page
Topic: A Business Case Question Previous Topic   Next Topic Topic: Hi Lo Card Game

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use