| 1 |
|
| 2 |
import java.applet.Applet; |
| 3 |
import java.net.MalformedURLException; |
| 4 |
import java.net.URL; |
| 5 |
import javax.jnlp.BasicService; |
| 6 |
import javax.jnlp.ServiceManager; |
| 7 |
import javax.jnlp.UnavailableServiceException; |
| 8 |
|
| 9 |
|
| 10 |
/* SimpleTest2.java |
| 11 |
Copyright (C) 2011 Red Hat, Inc. |
| 12 |
|
| 13 |
This file is part of IcedTea. |
| 14 |
|
| 15 |
IcedTea is free software; you can redistribute it and/or |
| 16 |
modify it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation, version 2. |
| 18 |
|
| 19 |
IcedTea is distributed in the hope that it will be useful, |
| 20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 |
General Public License for more details. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public License |
| 25 |
along with IcedTea; see the file COPYING. If not, write to |
| 26 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 27 |
02110-1301 USA. |
| 28 |
|
| 29 |
Linking this library statically or dynamically with other modules is |
| 30 |
making a combined work based on this library. Thus, the terms and |
| 31 |
conditions of the GNU General Public License cover the whole |
| 32 |
combination. |
| 33 |
|
| 34 |
As a special exception, the copyright holders of this library give you |
| 35 |
permission to link this library with independent modules to produce an |
| 36 |
executable, regardless of the license terms of these independent |
| 37 |
modules, and to copy and distribute the resulting executable under |
| 38 |
terms of your choice, provided that you also meet, for each linked |
| 39 |
independent module, the terms and conditions of the license of that |
| 40 |
module. An independent module is a module which is not derived from |
| 41 |
or based on this library. If you modify this library, you may extend |
| 42 |
this exception to your version of the library, but you are not |
| 43 |
obligated to do so. If you do not wish to do so, delete this |
| 44 |
exception statement from your version. |
| 45 |
*/ |
| 46 |
public class ShowDocument extends Applet { |
| 47 |
|
| 48 |
//this is the only reason why it is isgned |
| 49 |
private static String url = System.getProperty("durl", "http://www-eng-x.llnl.gov/documents/a_document.txt"); |
| 50 |
|
| 51 |
private static class Killer extends Thread { |
| 52 |
|
| 53 |
public static final int n = 2000; |
| 54 |
|
| 55 |
@Override |
| 56 |
public void run() { |
| 57 |
try { |
| 58 |
Thread.sleep(n); |
| 59 |
System.out.println("Applet killing himself after " + n + " ms of life"); |
| 60 |
System.exit(0); |
| 61 |
} catch (Exception ex) { |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
private Killer killer; |
| 66 |
|
| 67 |
public static void main(String[] args) throws MalformedURLException, UnavailableServiceException { |
| 68 |
// Lookup the javax.jnlp.BasicService object |
| 69 |
BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService"); |
| 70 |
// Invoke the showDocument method |
| 71 |
bs.showDocument(new URL(url)); |
| 72 |
} |
| 73 |
|
| 74 |
public void work1() { |
| 75 |
try { |
| 76 |
boolean ok = true; |
| 77 |
this.getAppletContext().showDocument(new URL(url)); |
| 78 |
if (!ok) { |
| 79 |
throw new RuntimeException("document should show"); |
| 80 |
} |
| 81 |
} catch (Exception e) { |
| 82 |
throw new RuntimeException(e); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
public void work2() { |
| 87 |
try { |
| 88 |
boolean ok = true; |
| 89 |
this.getAppletContext().showDocument(new URL(url), ""); |
| 90 |
if (!ok) { |
| 91 |
throw new RuntimeException("document should show"); |
| 92 |
} |
| 93 |
} catch (Exception e) { |
| 94 |
throw new RuntimeException(e); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public void init() { |
| 100 |
System.out.println("applet was initialised"); |
| 101 |
killer = new Killer(); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
public void start() { |
| 106 |
System.out.println("applet was started"); |
| 107 |
work1(); |
| 108 |
work2(); |
| 109 |
killer.start(); |
| 110 |
} |
| 111 |
|
| 112 |
@Override |
| 113 |
public void stop() { |
| 114 |
System.out.println("applet was stopped"); |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public void destroy() { |
| 119 |
System.out.println("applet will be destroyed"); |
| 120 |
} |
| 121 |
|
| 122 |
} |