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 IOException {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im = ImageIO.read(url);
    URL url2 = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im2 = ImageIO.read(url2);
    Graphics2D g = im.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    g.drawImage(im2, (im.getWidth() - im2.getWidth()) / 2, (im.getHeight() - im2.getHeight()) / 2, null);
    g.dispose();/*from w ww  .ja v a  2s  .  com*/

    display(im);
    ImageIO.write(im, "jpeg", new File("output.jpeg"));
}

From source file:LoadingWebPageToJEditorPane.java

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

    JEditorPane editorPane = new JEditorPane();

    editorPane.setPage(new URL("http://www.java2s.com"));

    frame.add(new JScrollPane(editorPane));

    frame.setSize(300, 200);/*from ww w  . j av a 2 s.c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").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();/*ww w.j av  a  2s.c o m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").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();/*w w w . j ava  2  s . c o  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage image = ImageIO.read(url);
    int x = 50;//  ww w .  j  a va2  s.c  o m
    final Image crop = image.getSubimage(x, 0, image.getWidth() - x, image.getHeight());
    Runnable r = new Runnable() {
        @Override
        public void run() {
            JPanel gui = new JPanel();
            gui.add(new JLabel(new ImageIcon(image)), BorderLayout.LINE_START);
            gui.add(new JLabel("java2s.com"));
            gui.add(new JLabel(new ImageIcon(crop)), BorderLayout.LINE_END);
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();
    CookieStore cookieStore = cm.getCookieStore();

    List<URI> uriList = cookieStore.getURIs();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").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   w w w.j  a  va2s  . c om
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JOptionPane jop = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);

    JDialog dialog = jop.createDialog("Dialog Title");

    Image image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    dialog.setIconImage(image);/*  ww w.  j a v  a  2 s.c  o  m*/
    dialog.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    try {/*w  ww.  j  a  v  a  2  s .co m*/

        URL url = new URL("http://www.java2s.com/");
        URLConnection urlConnection = url.openConnection();
        Map<String, List<String>> headers = urlConnection.getHeaderFields();
        Set<Map.Entry<String, List<String>>> entrySet = headers.entrySet();
        for (Map.Entry<String, List<String>> entry : entrySet) {
            String headerName = entry.getKey();
            System.out.println("Header Name:" + headerName);
            List<String> headerValues = entry.getValue();
            for (String value : headerValues) {
                System.out.print("Header value:" + value);
            }
            System.out.println();
            System.out.println();
        }
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = bufferedReader.readLine();
        while (line != null) {
            System.out.println(line);
            line = bufferedReader.readLine();
        }
        bufferedReader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(final String[] args) throws IOException {
    final URL url1 = new URL("http://www.java2s.com/style/download.png");
    final URL url2 = new URL("http://www.java2s.com/style/download.png");
    final URL url3 = new URL("http://www.java2s.com/style/download.png");

    final PictureDesktop desktop = new PictureDesktop();
    desktop.addPicture(ImageIO.read(url1));
    desktop.addPicture(ImageIO.read(url2));
    desktop.addPicture(ImageIO.read(url3));

    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(BorderLayout.CENTER, desktop);
    frame.setSize(720, 480);/*w w  w  .  j  a v  a2s.  c o m*/
    frame.setVisible(true);
}