Example usage for java.net URL URL

List of usage examples for java.net URL URL

Introduction

In this page you can find the example usage for java.net URL URL.

Prototype

public URL(String spec) throws MalformedURLException 

Source Link

Document

Creates a URL object from the String representation.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new RedBlueSwapFilter()));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new XorFilter()));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new GrayFilter()));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage original = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    BufferedImage rotated1 = create(original, -Math.PI / 2, gc);
    BufferedImage rotated2 = create(original, +Math.PI / 4, gc);
    BufferedImage rotated3 = create(original, Math.PI, gc);

    JPanel cp = new JPanel();
    cp.add(new JLabel(new ImageIcon(original)));
    cp.add(new JLabel(new ImageIcon(rotated1)));
    cp.add(new JLabel(new ImageIcon(rotated2)));
    cp.add(new JLabel(new ImageIcon(rotated3)));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(cp);//  w w  w.  j  av  a  2  s .c  om
    f.pack();
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textfield = new WatermarkTextField(new URL("http://www.java2s.com/style/download.png"));
    textfield.setText("www.java2s.com");
    frame.getContentPane().add(textfield);
    frame.pack();/*from   ww w  .  j  a v a  2  s .c o  m*/
    frame.setVisible(true);
}

From source file:ListAllCookies.java

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("usage: java ListAllCookies url");
        return;//from  w  w  w.  ja  v a 2  s .  c  o  m
    }

    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL(args[0]).openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String mapUrlPath = "http://www.java2s.com/style/download.png";
    URL mapUrl = new URL(mapUrlPath);
    BufferedImage mapImage = ImageIO.read(mapUrl);
    Image newMapImage = Toolkit.getDefaultToolkit()
            .createImage(new FilteredImageSource(mapImage.getSource(), new GrayToColorFilter(Color.red)));
    ImageIcon mapIcon = new ImageIcon(mapImage);
    ImageIcon newMapIcon = new ImageIcon(newMapImage);

    JPanel imagePanel = new JPanel();
    imagePanel.add(new JLabel(mapIcon));
    imagePanel.add(new JLabel(newMapIcon));

    JOptionPane.showMessageDialog(null, imagePanel);
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("EditorPane Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    try {/*from ww w  .jav  a  2s  .c  o m*/
        JEditorPane editorPane = new JEditorPane(new URL("http://www.java2s.com"));
        editorPane.setEditable(false);

        HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(editorPane);
        editorPane.addHyperlinkListener(hyperlinkListener);

        JScrollPane scrollPane = new JScrollPane(editorPane);
        frame.add(scrollPane);
    } catch (IOException e) {
        System.err.println("Unable to load: " + e);
    }

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();/*w  w w  . java2 s. co  m*/

    // From file
    InputStream input = new BufferedInputStream(new FileInputStream(new File("midiaudiofile")));

    // From URL
    input = new BufferedInputStream(new URL("http://hostname/rmffile").openStream());

    sequencer.setSequence(input);

    // Start playing
    sequencer.start();
}

From source file:com.tbs.devcorner.simple.App.java

public static void main(String[] args) {
    try {/*from  w  w  w  .j a v  a  2  s.  c  o m*/
        // Build Connection
        URL api_url = new URL("http://www.earthquakescanada.nrcan.gc.ca/api/earthquakes/");
        URLConnection api = api_url.openConnection();

        // Set HTTP Headers
        api.setRequestProperty("Accept", "application/json");
        api.setRequestProperty("Accept-Language", "en");

        // Get Response
        JSONTokener tokener = new JSONTokener(api.getInputStream());
        JSONObject jsondata = new JSONObject(tokener);

        // Display API name
        System.out.println(jsondata.getJSONObject("metadata").getJSONObject("request").getJSONObject("name")
                .get("en").toString());

        // Iterate over latest links
        JSONObject latest = jsondata.getJSONObject("latest");
        for (Object item : latest.keySet()) {
            System.out.println(item.toString() + " -> " + latest.get(item.toString()));
        }

    } catch (MalformedURLException e) {
        System.out.println("Malformed URL");
    } catch (IOException e) {
        System.out.println("IO Error");
    }
}