Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Modify a website 'screen capture' program, to remove javascript 'errors'

Posted on 2005-03-08
3
Medium Priority
?
429 Views
Last Modified: 2008-02-01
The program below is designed to do a 'screen capture' of a whole webpage. It uses a text area to accomplish this. The problem is that if the webpage has javascript on it, it will show up as errors. I am looking to modify this program so that the errors are not displayed. If the way to do this is to not use a text area, this is fine. If using a browser would be better, that is ok as well. In the end, I just need the image of the whole web page. The test url (CNN) is just a popular page that has javascript on it. If you could help out, it would be greatly appreciated. If you have any questions, please let me know.

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.net.*;
 
public class SavingAScrollingComponent
{
    public SavingAScrollingComponent()
    {
        JEditorPane textArea = getTextArea();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(getUIPanel(textArea), "North");
        f.getContentPane().add(new JScrollPane(textArea));
       
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
       

    }
 
    private void save(Component c)
    {
        int w = c.getWidth();
        int h = c.getHeight();
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        c.paint(g2);
        g2.dispose();
        File file = new File("scrollingComponent.png");
        try
        {
            ImageIO.write(image, "png", file);
        }
        catch(IOException ioe)
        {
            System.err.println("write: " + ioe.getMessage());
        }
    }
 
    private JPanel getUIPanel(final JEditorPane ta)
    {
        JButton save = new JButton("save");
        save.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                save(ta);
            }
        });
        JPanel panel = new JPanel();
        panel.add(save);
        return panel;
    }
 
    private JEditorPane getTextArea()
    {
        JEditorPane ta = new JEditorPane();
        ta.setMargin(new Insets(0,5,0,5));
        try
        {
       
          URL file = new URL("http://www.cnn.com/");
             ta.setPage(file);
        }
        catch(IOException ioe)
        {
            System.err.println("read: " + ioe.getMessage());
        }
        return ta;
    }
 
    public static void main(String[] args)
    {
        new SavingAScrollingComponent();
    }
}
0
Comment
Question by:stakor
  • 2
3 Comments
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13493540
hi stakor,
  using JEditorPane, you cannot render javascript.
 
 Try using webrender. http://www.webrenderer.com/ [but it is shareware ]

  see this link http://www.jguru.com/faq/view.jsp?EID=25662 

       http://www.ii.uib.no/~alexey/jb/
       http://www.netcluesoft.com/desktop/desktop.php3?sub=deskload

Hope this helps
0
 

Author Comment

by:stakor
ID: 13499828
I fear that I neglected to mention how much of a newbie I am to Java. I see that the general idea here is to replace the JEditorPane with a java web browser. But, that is about as far as I get...

In the example that you provide, I see that there is a new object called SormBase, and that it is using Swing. Now keep in mind I only know that there are books writien on swing, but I know nothing about it. (Actually I think it is a method for communicating between objects? - I really don't know) After that there is a new JPannel, and a viewport is created via Storm Base's Storm Panel.

I guess my major problem here (other than not knowing much Java) is that I don't fully understand how to replace the JEditorPane in 'my' application. I am not even certain where I need to place the ICE browser's jb.class in relation to my application. Does it only need to be visable in the path, or does it need something more specific? Sorry, should have mentioned I am very new to Java.
0
 
LVL 6

Accepted Solution

by:
durgaprasad_j earned 2000 total points
ID: 13503786
hi,
           would you be able to put any of the given browser software in your application /?
           If you have done it, saving part is same. Instead of sending JLabel, just send that component to save function.

           If you have n't got how to mix your program with that software, i will try and let you know tomorrow.
           BTW  Follow these steps:
                         JEditorPane is a class. Like this , any api has a starting class, using that you can display web pages.
                         You are adding JEditorPane into JFrame. Similarly here also, add that browser object instead of JEditorPane to JFrame .

                         Just think of that browser object as something alternative for JEditorPane. [ it is simple, dont get afraid of this]

Hope this helps
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question