|
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Problem with a java Applet :(
Ok, this is my first year in Java coding. I am taking AP Computer Science at my HighSchool. I have ripped apart a few Java programs I found to make something. The problem is that it my java applet will not get past a certain part in the code, when it tryes to capture the html of a website into a buffer. I did not write this code but I know it works because I it works outside of an applet. This goal of this applet is for people to type the URL of a video on google video and create HTML code to add the video to your own site. You can see this working here on my first ever website. Anyone experenced enuph with Java to help me? Here is the .java file. Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Google_GUI extends Applet
{
private TextField input;
private TextArea output;
public void init()
{
// Construct the TextField, TextArea, and Button
this.input = new TextField("http://", 50);
this.output = new TextArea("Insert the URL of the google video you want HTML code to be generated for.", 4, 60);
this.output.setEditable(false);
Button button = new Button("Generate");
// add the stuff to the layout
this.add(input);
this.add(button);
this.add(output);
// specify that action events sent by the
// button or the input TextField should be handled
// by the same CapitalizerAction object
GenerateHTML gen = new GenerateHTML();
button.addActionListener(gen);
this.input.addActionListener(gen);
// notice that ActionEvents produced by output are ignored.
}
private class GenerateHTML implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
output.setText("Working");
String text;
try
{
text = getUserOutput();
}
catch (MalformedURLException mue)
{
text = "Error: URL";
}
catch (IOException mue)
{
text = "Error: Buffer";
}
output.setText(text);
}
}
public String getUserOutput() throws MalformedURLException, IOException
{
output.setText("Working -");
URL google = new URL(input.getText());
output.setText("Working - Got");
//The applet gets to here, it displays "Working - Got" in the window but not "Working - Got HTML". I Dont know why the next part of the code doest work inside the applet
BufferedReader buffer = new BufferedReader(new InputStreamReader(google.openStream()));
output.setText("Working - Got HTML");
String inputLine;
String importantString = new String("Error");
while ( (inputLine = buffer.readLine()) != null)
{
if (inputLine.contains("googleplayer.swf"))
{
importantString = inputLine;
}
}
buffer.close();
output.setText("Working - Got HTML - Found String");
int length = importantString.length();
int start = importantString.indexOf("googleplayer.swf");
int end = importantString.indexOf("\" style=\"width:100%");
String googleVideoCode = new String(importantString.substring(start, end));
int flashWidth = 400;
int flashHeight = 300;
return "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\">\n\t<param name=\"movie\" value=\"" + googleVideoCode + "\" />\n\t<param name=\"quality\" value=\"high\" />\n\t<embed src=\"" + googleVideoCode + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\"></embed>\n</object>";
}
}
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
| Advertisement | [Remove Advertisement] |
|
|
|
|
|
#2 |
|
Transcended
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
|
I'd love to help but I don't have the time to grab a new SDK. I can't resolve String.contains() for one. However, here's a tip while the gurus are still out.. try splitting up the code: InputStream is = google.openStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); Then put setTexts inbetween each. This way, you'll know where exactly it hangs so you can check it out. At first glance, it should work, but it might have some issues with google.openStream(). I haven't personally retrieved streams from a URL object before, so you might wantg to investigate this as the possible culprit first. |
|
|
|
|
|
#3 |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Yes, my teacher could not help me out either because he did not have Java 5 either. I will try spliting up the code toamrow in class and see spisifically what is not working. The thing that pisses me off is that it works while its not an applet. I am attaching a java file that I made before turning it into an applet. I attached the code in a text file of the nonapplet verson that works. Thanks Alot! PS: We use BlueJ to edit our code.
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
|
|
#4 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 9,440
|
|
|
|
|
|
|
#5 |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Really!?!?!? I have no idea why it wouldent work, its perfect! I just downloaded an upgrade to JAVA today becasue of some popup, so I am going to test it later. Edit: Ok, I am really pissed off at java right now (because you know, its java's fault, not mine) and I have uninstalled it from my computer and I am currently installing the newest version I could find. I am really pissed off at the number of different types of java and how they don't have a super uber large one for all download that has everything. Edit 2: Ok now I am really getting frustrated, I downloaded some sort of gay server edition. I am going to be really pissed if I have to reinstall it again. Ahhhhhhh! Edit 3: This is really pissing me off, I uninstalled the server edition and reinstalled the normal SDK. Everything is back to a perfect clean slate, and I still can't get it to run. Even when I tryed to put the applet on my website it doesnt even start to run. Look here to see what I mean.
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
Last edited by Viper_Viper; December 11th, 2005 at 16:30.. |
|
|
|
|
|
#6 |
|
Transcended
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
|
Hey Kirby, mind telling us what SDK you were using? Welcome to the wonderful world of Java, Viper_Viper. you should have seen the ruckus caused by Java SDK 1.3. Code which ran perfectly for 1.2 and 1.4 broke on 1.3.
|
|
|
|
|
|
#7 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 9,440
|
|
|
|
|
|
|
#8 |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
I am currently using "jdk1.5.0_06" and my code wont correctly run in BlueJ. I downloaded Eclipse 3.1 but am still figureing out how it works. I was not able to test my applet correctly, like the "run" box was faded out. Ill look into it more tonight.
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
|
|
#9 | |
|
Transcended
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
|
Quote:
@Viper_viper: Don't bother with Eclipse. It's not the IDE really. Try getting Kirby's exact JDK version. |
|
|
|
|
|
|
#10 | |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Quote:
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
|
|
|
#11 |
|
Transcended
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
|
Like I said... it may be a bug with the SDK. Don't worry... once it's compiled, it shouldn't have any more problems no matter the VM used to run it. You can try changing it but, so far, the only thing I see questionable in your code is URL to stream. I've only really evry used sockets and not URLs before, and the exact same code works. |
|
|
|
|
|
#12 | |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Quote:
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
|
|
|
#13 |
|
Transcended
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
|
|
|
|
|
|
|
#14 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 9,440
|
I was also using Linux at the time....shouldn't make any difference, though. Once I get some free time, I'll try it again with JDK 1.5.0-06, Eclipse 3.1.1, and Windows 2000 but like you said, the code looks perfect, even to me (and Eclipse doesn't give any compiling errors).... edit> I just happened to remember I got a error at that line when I ran the program w/o putting in a valid Goggle Video URL.....I'll look into it more |
|
|
|
|
|
#15 |
|
Experenced But New User
![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: United States of America
Posts: 866
|
Thanks alot guys. This is my first year in programing and I was getting frustrated. My teacher is a compleate idiot (well, not to be too harsh, it is his first year teaching the class). Me and my friends just play games all day. We try to tell him that the easiest way for us to learn would be to make somthing that we could accualy use, but we keep doing these stupid System.out.print("heylooktext!") labs that dont help us at all.
__________________
MY PC!!!! Intel 2.44 ghz // Intel Desktop Board D845PEBT2 (533MHz FSB) // 1GIG DDR PC2700 (NEW) // 120 gig Western Digital HD // 8x DVD+/-R 4x DVD+/-RW Burner (NEW) // 48x15x48 CD-RW // ATI Radeon 9800 Pro 128mb // USB 2.0 // Firewire (soon) // 6 Channel Digital Audio // Serial ATA //
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|