Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read

Reply
 
Thread Tools Display Modes
Old December 8th, 2005, 01:34   #1
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Advertisement [Remove Advertisement]

Old December 8th, 2005, 06:14   #2
Kraelis
Transcended
 
Kraelis's Avatar
 
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.
__________________
--KrÆlis Cross


Mundus vult decipi, ergo decipiatur

===============
Athlon 64 x2 3800| Asrock ALiveNF6G-VSTA | Kingston DDR2 1 Gb RAM
Kraelis is offline   Reply With Quote

Old December 9th, 2005, 00:52   #3
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
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.
Attached Files
File Type: txt Google_Video_Link_Getter.txt (2.4 KB, 19 views)
__________________
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Old December 9th, 2005, 03:36   #4
Kurbster
Administrator
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 9,440
I have no problems running this code under Eclipse (1.5.0-04)...applet and all

your SDK sucks
__________________



Kurbster is offline   Reply With Quote

Old December 10th, 2005, 06:24   #5
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
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 //
3Dmark05 Demo - 2108


Last edited by Viper_Viper; December 11th, 2005 at 16:30..
Viper_Viper is offline   Reply With Quote

Old December 12th, 2005, 01:24   #6
Kraelis
Transcended
 
Kraelis's Avatar
 
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.
__________________
--KrÆlis Cross


Mundus vult decipi, ergo decipiatur

===============
Athlon 64 x2 3800| Asrock ALiveNF6G-VSTA | Kingston DDR2 1 Gb RAM
Kraelis is offline   Reply With Quote

Old December 12th, 2005, 19:14   #7
Kurbster
Administrator
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 9,440
Quote:
Originally Posted by Kraelis
Hey Kirby, mind telling us what SDK you were using?
Eclipse 3.1
Java SDK 1.5.0-04

__________________



Kurbster is offline   Reply With Quote

Old December 12th, 2005, 23:18   #8
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Old December 13th, 2005, 00:27   #9
Kraelis
Transcended
 
Kraelis's Avatar
 
Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
Quote:
Originally Posted by Kirby
Eclipse 3.1
Java SDK 1.5.0-04

Sorry, my bad for not noticing

@Viper_viper:

Don't bother with Eclipse. It's not the IDE really. Try getting Kirby's exact JDK version.
__________________
--KrÆlis Cross


Mundus vult decipi, ergo decipiatur

===============
Athlon 64 x2 3800| Asrock ALiveNF6G-VSTA | Kingston DDR2 1 Gb RAM
Kraelis is offline   Reply With Quote

Old December 13th, 2005, 00:38   #10
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
Join Date: Apr 2003
Location: United States of America
Posts: 866
Quote:
Originally Posted by Kraelis
Sorry, my bad for not noticing

@Viper_viper:

Don't bother with Eclipse. It's not the IDE really. Try getting Kirby's exact JDK version.
...why would getting a preveous version of java fix things? Maby I should just change some of the code compleatly. I want this to be an applet, widely usuable on the web, so I guess compatablilty is immportant.
__________________
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Old December 13th, 2005, 03:46   #11
Kraelis
Transcended
 
Kraelis's Avatar
 
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.
__________________
--KrÆlis Cross


Mundus vult decipi, ergo decipiatur

===============
Athlon 64 x2 3800| Asrock ALiveNF6G-VSTA | Kingston DDR2 1 Gb RAM
Kraelis is offline   Reply With Quote

Old December 13th, 2005, 06:01   #12
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
Join Date: Apr 2003
Location: United States of America
Posts: 866
Quote:
Originally Posted by Kraelis
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.
Sorry, I dident understand you when you said a bug in the SDK, I thought you ment mine might be coruppt. Ok, I am now downloading and installing the Java 5 Update 4 (which I hope means 1.5.0-04) and going to try it out. When putting my applet on the web, I use the .class file right? not the .java file? Thanks alot guys.
__________________
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Old December 13th, 2005, 08:03   #13
Kraelis
Transcended
 
Kraelis's Avatar
 
Join Date: Jun 2001
Location: Moonlight Spire
Posts: 1,409
Yeah... class file embedded in the HTML.
__________________
--KrÆlis Cross


Mundus vult decipi, ergo decipiatur

===============
Athlon 64 x2 3800| Asrock ALiveNF6G-VSTA | Kingston DDR2 1 Gb RAM
Kraelis is offline   Reply With Quote

Old December 13th, 2005, 16:25   #14
Kurbster
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
__________________



Kurbster is offline   Reply With Quote

Old December 15th, 2005, 01:52   #15
Viper_Viper
Experenced But New User
 
Viper_Viper's Avatar
 
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 //
3Dmark05 Demo - 2108

Viper_Viper is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 01:26.

© 2006 - 2012 Emu Forums | About Emu Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.