This commit is contained in:
beard%netscape.com 1998-12-12 01:33:27 +00:00
Родитель 8f41797878
Коммит e6968ceb71
4 изменённых файлов: 328 добавлений и 0 удалений

Двоичные данные
plugin/oji/MRJ/testing/TrivialApplet/MyApplet.mcp Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,68 @@
<HTML>
<HEAD>
<TITLE>TrivialApplet</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
var System = java.lang.System;
function writeln(text)
{
document.write("<P>", text, "</P>");
}
function println(text)
{
System.out.println(text);
}
function examineApplets()
{
var applets = document.applets;
println("applets.length = " + applets.length);
}
function examineTrivialApplet(applet)
{
applet.print("url = " + applet.urlField.getText());
// println("url = " + applet.urlField.getText());
}
</SCRIPT>
<BODY onload="examineApplets();">
<P>
<APPLET
ARCHIVE="AppletClasses.jar"
NAME="TrivialApplet"
CODE="TrivialApplet.class"
MAYSCRIPT="true"
WIDTH=200 HEIGHT=200>
<PARAM NAME="URL" VALUE="http://home.netscape.com">
</APPLET>
</P>
<HR>
<a href="TrivialApplet.java">The source.</a>
<form>
<P>
<input type=button
onclick="examineApplets();"
value="examineApplets()">
<input type=button
onclick="examineTrivialApplet(document.TrivialApplet);"
value="examineTrivialApplet()">
</P>
</form>
</BODY>
</HTML>

Просмотреть файл

@ -0,0 +1,183 @@
/*
Trivial applet that displays a string - 4/96 PNL
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.net.URL;
import java.net.MalformedURLException;
import netscape.javascript.JSObject;
class AboutBox extends Frame {
AboutBox(Menu aboutMenu, ActionListener[] actionListeners) {
super("About This Applet");
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
Button okButton = new Button("OK");
okButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
// Annoying use of flow layout managers.
Panel labelPanel = new Panel();
Panel buttonPanel = new Panel();
labelPanel.add(new Label("This applet's about box..."));
buttonPanel.add(okButton);
add(labelPanel, "North");
add(buttonPanel, "Center");
// test menu bar stuff.
MenuBar menuBar = new MenuBar();
aboutMenu = (Menu) cloneMenu(aboutMenu);
for (int i = 0; i < actionListeners.length; i++)
aboutMenu.getItem(i).addActionListener(actionListeners[i]);
menuBar.add(aboutMenu);
setMenuBar(menuBar);
pack();
show();
}
private MenuItem cloneMenu(MenuItem oldItem) {
if (oldItem instanceof Menu) {
Menu oldMenu = (Menu) oldItem;
Menu newMenu = new Menu(oldMenu.getLabel());
int count = oldMenu.getItemCount();
for (int i = 0; i < count; i++) {
newMenu.add(cloneMenu(oldMenu.getItem(i)));
}
return newMenu;
} else {
MenuItem newItem = new MenuItem(oldItem.getLabel());
return newItem;
}
}
}
class ExceptionThread extends Thread {
ExceptionThread() {
start();
}
public void run() {
throw new Error("this is an error!");
}
}
public class TrivialApplet extends Applet {
public Button goButton;
public Button aboutButton;
public TextField urlField;
public Menu aboutMenu;
public ActionListener[] actionListeners;
private static int appletCount;
public void init() {
++appletCount;
goButton = new Button("Go");
aboutButton = new Button("About");
String urlText = getParameter("URL");
if (urlText == null)
urlText = "http://www.apple.com";
urlField = new TextField(urlText);
ActionListener goListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
URL apple = new URL(urlField.getText());
getAppletContext().showDocument(apple, "Apple!");
} catch (MalformedURLException mfue) {
}
}
};
ActionListener aboutListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AboutBox(aboutMenu, actionListeners);
}
};
goButton.addActionListener(goListener);
aboutButton.addActionListener(aboutListener);
add(goButton);
add(aboutButton);
add(urlField);
// Try a pop-up menu, and a menu in the menubar.
PopupMenu contextMenu = new PopupMenu();
aboutMenu = new Menu("About");
contextMenu.add(newItem("About", aboutListener));
aboutMenu.add(newItem("About", aboutListener));
contextMenu.add(newItem("Go", goListener));
aboutMenu.add(newItem("Go", goListener));
ActionListener errorListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ExceptionThread();
}
};
contextMenu.add(newItem("Error", errorListener));
aboutMenu.add(newItem("Error", errorListener));
ActionListener[] listeners = { aboutListener, goListener, errorListener };
actionListeners = listeners;
add(contextMenu);
}
private MenuItem newItem(String title, ActionListener listener) {
MenuItem item = new MenuItem(title);
item.addActionListener(listener);
return item;
}
private Frame getFrame() {
Component p = this;
while (p != null && !(p instanceof Frame))
p = getParent();
return (Frame)p;
}
// public void paint( Graphics g ) {}
public boolean mouseEnter(Event evt, int x, int y) {
showStatus("Welcome!");
return true;
}
public boolean mouseExit(Event evt, int x, int y) {
showStatus("See you later!");
return true;
}
public void print(String message) {
JSObject window = JSObject.getWindow(this);
Object[] args = { message };
window.call("println", args);
}
public int getAppletCount() {
return appletCount;
}
}

Просмотреть файл

@ -0,0 +1,77 @@
<HTML>
<HEAD>
<TITLE>TrivialApplets</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
var System = java.lang.System;
var println = System.out.println;
function writeln(text)
{
document.write("<P>", text, "</P>");
}
function examineApplets()
{
var applets = document.applets;
println("applets.length = " + applets.length);
}
function examineTrivialApplet(applet)
{
applet.print("url = " + applet.urlField.getText());
applet.print("appletCount = " + applet.getAppletCount());
}
</SCRIPT>
<BODY>
<HR>
<APPLET
ARCHIVE="AppletClasses.jar"
NAME="TrivialApplet_0"
CODE="TrivialApplet.class"
MAYSCRIPT="true"
WIDTH=200 HEIGHT=200>
<PARAM NAME="URL" VALUE="http://home.netscape.com">
</APPLET>
<HR>
<APPLET
ARCHIVE="AppletClasses.jar"
NAME="TrivialApplet_1"
CODE="TrivialApplet.class"
MAYSCRIPT="true"
WIDTH=200 HEIGHT=200>
<PARAM NAME="URL" VALUE="http://www.apple.com">
</APPLET>
<HR>
<P>
<a href="TrivialApplet.java">The source.</a>
</P>
<FORM>
<INPUT type=button
onclick="examineApplets();"
value="examineApplets()">
<INPUT type=button
onclick="examineTrivialApplet(document.applets[0]);"
value="examineTrivialApplet(0)">
<INPUT type=button
onclick="examineTrivialApplet(document.applets[1]);"
value="examineTrivialApplet(1)">
</FORM>
</BODY>
</HTML>