1

i tried to have my processing project show a webpage, but its not working. does anyone know why?

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class GetWebPage {
    public static void main(String args[]) throws Exception {
        JEditorPane website = new JEditorPane("https://www.google.nl/maps/@51.7385025,-2.6407162,3a,79y,132.82h,79.64t/data=!3m6!1e1!3m4!1sMe0y36wXo7_CSHvur_4kPg!2e0!7i13312!8i6656?hl=nl");
        website.setEditable(false);
        JFrame frame = new JFrame("Google");
        frame.add(new JScrollPane(website));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        frame.setVisible(true);
    }
}
  • How does processing enter the picture here? I only see a simple swing program. – Federico klez Culloca Jul 01 '21 at 07:57
  • @KajvanVeen what is the overall goal you're trying to achieve ? (maybe there's a different route other than JEditorPane which [is quite limited](https://stackoverflow.com/questions/4153806/jeditorpane-as-a-web-browser/4154006#:~:text=4%20Answers&text=JEditorPane%20has%20limited%20html%20and,used%20as%20a%20web%20browser.)) – George Profenza Jul 01 '21 at 10:16
  • @KajVanVeen first: it is working - the code seems to be correct. seconds: what do you mean "not working"? Do you get error-messages? What does a debug-run? Do you get the main-frame? – Melvin Jul 01 '21 at 10:41
  • @Melvin hey Melvin, it just doesn't start, when i click on run it says ''Illegal modifier for the local class GetWebPage; only abstract or final is permitted" – Kaj van Veen Jul 01 '21 at 18:03
  • @GeorgeProfenza im trying to display google streetview in my program – Kaj van Veen Jul 01 '21 at 18:06
  • @KajVanVeen OK - then take a look: https://stackoverflow.com/questions/21280038/java-error-illegal-modifier-for-parameter-only-final-permitted This may help. – Melvin Jul 01 '21 at 21:15

1 Answers1

1

As mentioned in the comments JEditorPane is quite limited (mainly doesn't support JS which is required).

For example:

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

void setup(){
  showWebPage();
  println("done");
}

void draw(){
  
}

void showWebPage(){
  try{
    JEditorPane website = new JEditorPane("https://www.google.nl/maps/@51.7385025,-2.6407162,3a,79y,132.82h,79.64t/data=!3m6!1e1!3m4!1sMe0y36wXo7_CSHvur_4kPg!2e0!7i13312!8i6656?hl=nl");
    website.setEditable(false);
    JFrame frame = new JFrame("Google");
    frame.add(new JScrollPane(website));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 600);
    frame.setVisible(true);
  }catch(IOException e){
    e.printStackTrace();
  }
}

outputs:

StreetView noJS error

If you don't need interactivity you might be able to get away with the Google Street View Static API

Here's one of the examples:

PImage streetView;

void setup() {
  size(400, 400);
  streetView = loadImage("https://maps.googleapis.com/maps/api/streetview?size=400x400&location=47.5763831,-122.4211769&fov=80&heading=70&pitch=0&key=AIzaSyA3kg7YWugGl1lTXmAmaBGPNhDW9pEh5bo&signature=hg7yTczCuAp4fwIWFySlSr_vq7o=&filename=streetview.png");
}

void draw() {
  image(streetView, 0, 0);
}

There are a couple of caveats:

  1. As the Street View API documentation mentions, you need to get an API Key and Signature
  2. loadImage() needs an extension to know how to decode data, hence the &filename=streetview.png I added at the end (could be something like &ext=.png for example, as long as it's a valid URL and ends with the extension for Processing)

StreetView Static loaded as image in Processing

If you need to load a dynamic webpage you can try your luck with JavaFX. I'm not an experienced with it, but hopefully you can get something off the ground with the FX2D renderer in Processing

Personally I find using WebAPIs in Java a bit cumbersome/verbose. Depending on how you plan to integrate the street view in a larger application you can consider using the Street View Service directly in JavaScript and the Processing functionality with p5.js. If you need native system functionality you could load the p5.js front-end in an electron app

George Profenza
  • 50,687
  • 19
  • 144
  • 218