, Internet, , , HTML. , .
HelloWorld, :
import java.awt.*;
import java.applet.*;
public class HelloWorldApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 20, 20);
} }
, java.applet java.awt. paint, Applet. , Graphics. . drawString,
Graphics, (20,20) Hello World., , html-.
<applet code="HelloWorldApplet" width=200 height=40>
</applet>
html-, appletviewer .
HTML <Applet>
<applet> HTML-, appletviewer. appletviewer <applet> , . <APPL
ET> :<APPLET
CODE = appletFile
OBJECT = appletSerialFile
WIDTH = pixels
HEIGHT = pixels
[ARCHIVE = jarFiles]
[CODEBASE = codebaseURL]
[ALT = alternateText]
[NAME = appletInstanceName]
[ALIGN = alignment]
[VSPACE = pixels]
[HSPACE = pixels]
>
[< PARAM NAME = AttributeNamel VALUE = AttributeValuel >]
[< PARAM NAME = AttributeName2 VALUE = AttributeValue2 >]
[HTML-,
Java]
</APPLET>
CODE = appletClassFile
CODE
, , . codebase, , , CODEBASE. Java 1.1 OBJECT.OBJECT = appletClassSerialFile
, , . init(), start(). CODE, OBJECT, .
WIDTH = pixels
HEIGHT = pixels
WIDTH HEIGHT , .
ARCHIVE = jarFiles
jar- ( ), Web-. , , , . JAR, TAR Unix (
1):c:\> jar cf soundmap.jar *.class image.gif sound.wav
, jar- . (Lotus JavaBeans, Borland JBuilder) jar-.
CODEBASE = codebaseURL
CODEBASE
, URL , , ( CODE). , HTML-. CODEBASE , HTML-.ALT = alternateAppletText
ALT , , , <applet>, . , HTML-, <applet> </applet> , .
NAME = appletInstanceName
NAME
, . , . , MyApplet Applet Duke, :MyApplet a = getAppletContext().getApplet("Duke");
, , , .
ALIGN = alignment
ALIGN
, . , IMG, LEFT, RIGHT, TOP, TEXTTOP, MIDDLE, ABSMIDDLE, BASELINE, BOTTOM, ABSBOTTOM.VSPACE = pixels
HSPACE = PIXELS
(VSPACE), (HSPACE). , IMG.
PARAM NAME = appletAttribute1 VALUE = value1
HTML- . , getParameter(), .
getParameter(String)
getParameter String, . - , - . getParameter :
<applet code=Testing width=40 height=40>
<param name=fontName value=Univers>
<param name=fontSize value=14>
<param name=leading value=2>
<param name=accountEnabled value=true>
, :
String FontName = getParameter("fontName");
String FontSize = Integer.parseInt(getParameter("fontSize"));
String Leading = Float.valueOf(getParameter("leading"));
String PaidUp = Boolean.valueOf(getParameter("accountEnabled"));
getDocument
Base getCodeBase, , . Java , HTML-, ( - getDocumentBase), , class- ( - getCodeBase).
AppletContext showDocument
AppletContext , . showDocument , .
: . , , :
System.out.println(Hello there, welcome to Java);
, , . Netscape Java Options, Show Java Console.
showStatus pletviewer Java. .
, Applet, , .
init
init . .
start
start init. , . , init , start HTML-, , . , , WWW-, , start.
paint
paint . AWT , , , . , , , paint.
update
update Applet , paint. paint , update
, , . , update. update, paint, AWT, update.stop
stop , HTML-, . stop . , . , , start.
destroy
destroy , (, Netscape) , . , .
HelloWorldApplet. paint, . Applet , . , update . update repaint.
repaint
repaint . , , update. , , update . AWT, update . , repaint(time) , .
repaint(time)
repaint, ( repaint).
repaint(x, y, w, h)
, , .
repaint(time, x, , w, h)
.
.
, , . size, Dimension. Dimension, width height:
Dimension d = size();
System.out.println(d. width + "," + d.height);
Graphics
Graphics . , . drawRect, drawOval, fillRect fillOval : int x, int y, int width int height. , width height .
drawLine
drawline(int x1, int 1, int 2, int 2)
(1,1) (2,2). 1 . .
drawArc fillArc
drawArc fillArc :
drawArc(int x, int , int width, int height, int startAngle, int sweepAngle)
(fillArc ) , (x,y,width, height), startAngle sweepAngle. 3 , (, 90 12 , 180 9 , ).
drawPolyson fillPolyson
:
drawPolygon(int[], int[], int)
fillPolygon(int[], int[], int)
drawPolygon ( ), , , . drawPolygon . , , .
AWT , . , , Java , . , , , , . Color.black - - black, white, red, green, blue, cyan, yellow, magenta, orange, pink, gray, darkGray lightGray.
.
Color(int, int, int)
0 255 , .
Color(int)
, , . 16-23, 8-15, 0-7.
Color(float, float, float)
, Color(float, float, float), float ( 0.0 1.0) , .
Color
HSBtoRGB(float, float, float)
RGBtoHSB(int, int, int, float[1)
HSBtoRGB , , (HSB), RGB, Color(int). RGBtoHSB , , float HSB, .
HSB (Hue-Saturation-Brightness, --) Red-Green-Blue . ( 0.0 1.0, , , , , , , , ). ( 0.0 1.0) - , . - 0.0 1.0, , - .
getRedQ, getGreenO, setBlue()
.
getRGB()
, ,
red = Oxff & (getRGB() >> 16);
green = Oxff & (getRGB() >> 8);
blue = Oxff & getRGB();
setPaintMode() set
XORMode(Color)paint , . XOR , XOR ( ) ( ).
AWT . , Java .
/*
* <applet code="WhatFontsAreHere" width=100 height=40>
* </applet>
*
*/
import java.applet.*;
import java.awt.*;
public class WhatFontsAreHere extends Applet {
public void init() {
String FontList[];
FontList = getToolkit().getFontList();
for (int i=0; i < FontList.length; i++) {
System.out.println(i + ": " + FontList[i]);
}
} }
drawString
drawString(String, x, ). . (,) , , . , , , .
Font , :
Font StrongFont = new Font("Helvetica", Font.BOLD|Font.ITALIC, 24);
: Dialog, Helvetica, TimesRoman, Courier Symbol. . Font.PLAIN, Font.BOLD Font.ITALIC, , .
.
getFamily getName
getFamily . getName .
getSize
, .
getStyle
, . Font: PLAIN, BOLD ITALIC.
isBold, isItalic, isPlain
true , (bold), (italic) (plain), .
: FontMetrics
Java , FontMetrics . - , :
FontMetrics
FontMetrics:
stringWidth
.
bytesWidth, charsWidth
.
getAscent, getDescent, getHeight
, . . g . ..
getMaxAscent getMaxDescent
.
FontMetrics , , , .
/*
* <applet code="HelloWorld" width=200 height=100> * </applet> * */ import java.applet.*; import java.awt.*; public class HelloWorld extends Applet { final Font f = new Font("Helvetica", Font.BOLD, 18); public void paint(Graphics g) { Dimension d = this.size(); g.setColor(Color.white); g.fillRect(0,0,d.width,d.height); g.setColor(Color.black); g.setFont(f); drawCenteredString("Hello World!", d.width, d.height, g); g.drawRect(0,0,d.width-1,d.height-1); } public void drawCenteredString(String s, int w, int h, Graphics g) { FontMetrics fm = g.getFontMetrics(); int x = (w - fm.stringWidth(s)) / 2; int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent()))/2); g.drawString(s, x, y); } }
10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _. 10.11.2021 - 12:36: - Conscience -> . ? - _. 10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _. 10.11.2021 - 12:35: - Ecology -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> . - _. 10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _. 10.11.2021 - 09:18: - New Technologies -> , 5G- - _. 10.11.2021 - 09:18: - Ecology -> - _. 10.11.2021 - 09:16: - Ecology -> - _. 10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _. 10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _. |