From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/URLLaden.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java new file mode 100644 index 0000000..ca55ceb --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/URLLaden.java @@ -0,0 +1,82 @@ +/* URLLaden.java */ + +import java.applet.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.net.*; + +class URLButton +extends Button +{ + private URL url; + + public URLButton(String label, URL url) + { + super(label); + this.url = url; + } + + public URL getURL() + { + return url; + } +} + +public class URLLaden +extends Applet +implements ActionListener +{ + Vector buttons; + + public void init() + { + super.init(); + setLayout(new FlowLayout()); + addNotify(); + buttons = new Vector(); + for (int i=1; ; ++i) { + String s = getParameter("button"+i); + if (s == null) { + break; + } + try { + StringTokenizer st = new StringTokenizer(s,","); + String label = st.nextToken(); + String urlstring = st.nextToken(); + URL url; + if (urlstring.charAt(0) == '=') { + urlstring = urlstring.substring(1); + url = new URL(getDocumentBase(),urlstring); + } else { + url = new URL(urlstring); + } + URLButton button = new URLButton(label,url); + button.addActionListener(this); + add(button); + buttons.addElement(button); + } catch (NoSuchElementException e) { + System.out.println("Button"+i+": "+e.toString()); + break; + } catch (MalformedURLException e) { + System.out.println("Button"+i+": "+e.toString()); + break; + } + } + } + + public void actionPerformed(ActionEvent event) + { + URLButton source = (URLButton)event.getSource(); + Enumeration en = buttons.elements(); + while (en.hasMoreElements()) { + URLButton button = (URLButton)en.nextElement(); + if (button == source) { + System.out.println( + "showDocument("+button.getURL().toString()+")" + ); + getAppletContext().showDocument(button.getURL()); + } + } + } +} \ No newline at end of file -- cgit v1.2.3