home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
win95
/
sieciowe
/
hotja32.lzh
/
hotjava
/
classsrc
/
awt
/
demo
/
wrtest.java
< prev
Wrap
Text File
|
1995-08-11
|
7KB
|
278 lines
/*
* @(#)WRTest.java 1.25 95/03/20 Sami Shaio
*
* Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
package awt.demo;
import awt.*;
import java.io.*;
import java.lang.*;
import java.util.*;
class OpenItem extends MenuItem {
public OpenItem(Menu m, Window w) {
super("Open...", m);
fileDialog = new FileDialog("Open File...", w.getFrame());
}
public void selected() {
String file = fileDialog.chooseFile(null);
if (file != null) {
System.out.println("Chose file " + file);
}
}
private FileDialog fileDialog;
}
class TextItem {
public TextItem(Window p, String label, Font f, int x, int y) {
parent = p;
pLabel = label;
font = f;
px = x;
py = y;
height = f.height;
width = f.stringWidth(pLabel);
}
public void paint() {
parent.setFont(font);
parent.drawString(pLabel, px, py);
}
public void moveTo(int x, int y) {
parent.clearRect(px, py-height, width, height);
px = x;
py = y;
paint();
}
private Window parent;
private String pLabel;
private Font font;
private int px;
private int py;
private int height;
private int width;
}
class FileMenu extends Menu {
public FileMenu(MenuBar mbar, Window w) {
super("File", mbar);
MenuItem item;
new MenuItem("New", this);
new OpenItem(this, w);
item = new MenuItem("Save", this);
item.disable();
new MenuItem("Save As...", this);
new MenuItem("Quit", this);
enabled = true;
}
public void selected(int index) {
int height;
int width;
if (index == 0) {
aw = new WRTest();
}
}
private WRTest aw;
private boolean enabled;
};
class OptionsMenu extends Menu {
public OptionsMenu(MenuBar mbar) {
super("Options", mbar);
MenuItem item;
new MenuItem("Font", this);
new MenuItem("Color", this);
}
public void selected(int index) {
}
};
class NavigateMenu extends Menu {
public NavigateMenu(MenuBar mbar) {
super("Navigate", mbar);
MenuItem item;
new MenuItem("Forward", this);
new MenuItem("Back", this);
new MenuItem("Home", this);
}
public void selected(int index) {
}
};
class AnnotateMenu extends Menu {
public AnnotateMenu(MenuBar mbar) {
super("Annotate", mbar);
MenuItem item;
new MenuItem("Add Private Annotation", this);
new MenuItem("Add Public Annotation", this);
new MenuItem("Delete Annotation", this);
new MenuItem("Show Annotations", this);
new MenuItem("Hide Annotations", this);
}
public void selected(int index) {
}
};
class HelpMenu extends Menu {
public HelpMenu(MenuBar mbar) {
super("Help", mbar);
MenuItem item;
new MenuItem("About HotJava", this);
}
public void selected(int index) {
}
};
class InfoWindow extends Window {
public InfoWindow(Frame f) {
super(f, "North", f.background, 500, 100);
int h;
RowColLayout r;
Font label_font = WRTest.ws.fonts.getFont("Helvetica:bold:14");
Font input_font = WRTest.ws.fonts.getFont("DialogInput:bold:12");
r = new RowColLayout(0, 2);
r.setGaps(4,4,4,4);
setLayout(r);
docTitle = new Label("Document Title:", "docTitle", this);
//docTitle.setFont(label_font);
docTitle.setColor(WRTest.blue);
titleField = new TextField("LiveJava Home Page",
"titleField",
this,
false);
//titleField.setFont(input_font);
titleField.setColor(Color.black);
urlTitle = new Label("Document URL:", "urlTitle", this);
//urlTitle.setFont(label_font);
urlTitle.setColor(WRTest.blue);
urlField = new TextField("http://www",
"urlField",
this,
true);
urlField.setColor(Color.black);
//urlField.setFont(label_font);
}
Label docTitle;
Label urlTitle;
TextField titleField;
TextField urlField;
}
class StatusWindow extends Window {
public StatusWindow(Frame f) {
super(f, "South", f.background, 500, 30);
Label st;
fg = Color.black;
st=new Label("Data transfer complete.", "status", this);
st.setColor(WRTest.blue);
//st.setHFill(true);
new Button("Back", "",this);
new Button("Forward", "", this);
new Button("Home", "", this);
new Button("Reload", "", this);
new Button("Open...", "", this);
new Button("Save As...", "", this);
new Button("Clone...", "", this);
new Button("New Window", "", this);
new Button("Close Window", "",this);
}
Color fg;
}
class DocWindow extends Window {
public DocWindow(Frame f) {
super(f,"Center", f.background, 500, 400);
setLayout(BorderLayout.defaultLayout);
setMargin(2);
new Scrollbar(this, "",Scrollbar.VERTICAL, true);
new Window(this, "North", Color.red, 100, 100);
new Window(this, "West", Color.green, 100, 100);
new Window(this, "East", Color.yellow, 100, 100);
new Window(this, "South", Color.blue, 100, 100);
new Window(this, "Center", Color.white, 100, 100);
}
public void paint() {
}
}
class WRTest {
public WRTest() {
f = new Frame(WRTest.ws, true, null, 660, 750,
Color.lightGray);
f.setTitle("HotJava demo demo " + nFrames++);
mbar = new MenuBar(f);
infoWindow = new InfoWindow(f);
contentWindow = new DocWindow(f);
statusWindow = new StatusWindow(f);
new FileMenu(mbar, contentWindow);
new OptionsMenu(mbar);
new NavigateMenu(mbar);
new AnnotateMenu(mbar);
new HelpMenu(mbar);
//f.setMinSize();
f.layout();
f.map();
}
public static void main(String args[]) {
WRTest a1;
WRTest.nFrames = 1;
ws = new WServer();
ws.start();
blue = new Color(ws, 29,21,91);
boldFont = WRTest.ws.fonts.getFont("Helvetica:bold:14");
normalFont = WRTest.ws.fonts.getFont("DialogInput:roman:12");
a1 = new WRTest();
//ws.run();
}
public static Font boldFont;
public static Font normalFont;
public static int nFrames;
public static WServer ws;
public static Color blue;
Frame f;
MenuBar mbar;
Window infoWindow;
Window contentWindow;
Window statusWindow;
};