java on the web session 15. memory upload java applets colors fonts drawing methods posting your...

27
Java On The Web Session 15

Upload: brianne-nash

Post on 30-Dec-2015

250 views

Category:

Documents


2 download

TRANSCRIPT

Java On The WebJava On The Web

Session 15

Memory UploadMemory Upload

• JAVA Applets

• Colors

• Fonts

• Drawing Methods

• Posting your Applet

AppletsApplets

• An applet is a program that runs embedded in HTML code

• They must be viewed either in Web Browser Appletviewer

GUI ElementsGUI Elements

• Applets can display GUI elements Graphical User Interface

• Colors

• Fonts

• Text-Fields, Button , Labels, etc.Button

SkeletonSkeleton

import java.awt.*;import java.applet;public class MyApplet extends Applet { public void init( ){ } public void paint(Graphics g){ //instructions go here }}

SkeletonSkeleton

import java.awt.*;import java.applet;public class MyApplet extends Applet { public void init( ){ } public void paint(Graphics g){ //instructions go here }}

ColorsColors

• Colors are made out of 3 values

• Each value goes from 0 to 255 REDRED GREENGREEN BLUEBLUE

ColorsColorsBlack Color.black 0,0,0

Blue Color.blue 0,0,255

Cyan Color.cyan 0,255,255

Gray Color.gray 128,128,128

Green Color.green 0,255,0

Magenta Color.magenta 255,0,255

Orange Color.orange 255,200,0

Pink Color.pink 255,175,175

Red Color.red 255,0,0

White Color.white 255,255,255

Yellow Color.yellow 255,255,0

ColorsColors

import java.awt.*;import java.applet;public class MyApplet extends Applet { public void init( ){ } public void paint(Graphics g){ //Your Own

Color MyColor = new Color(50, 200,150);g.setColor(MyColor);

}}

.setColor(Color).setColor(Color)

g.setColor(Color.yellow);

g.setColor(Color.red);

g.setColor(MyColor);

FontsFonts• The constructor

Font f = new Font(Type, Style, Size);

import java.awt.*;import java.applet;public class MyApplet extends Applet { public void init( ){a } public void paint(Graphics g){

Font f=new Font(“Tahoma”,Font.PLAIN, 10);

g.setFont(f); }}

MethodsMethodsvoid drawLine(int x1, int y1, int x1, int y2)

void drawRect(int x, int y, int w, int h)

void fillRect((int x, int y, int w, int h)

void drawOval(int x, int y, int w, int h)

void fillOval(int x, int y, int w, int h)

void drawString(String, int x, int y)

void drawArc(int x, int y, int w, int h,

int start angle, int arcAngle)

void fillArc(int x, int y, int w, int h,

int start angle, int arcAngle)

The coordinatesThe coordinates

0,0

xx

yy

0,0

drawLinedrawLine

g.drawLine(10,10,18,24);

10

10

24

18

0,0

drawRectdrawRect

810

10

10

g.setColor(Color.green); g.drawRect(10,10,8,10);

0,0

810

10

10

fillRectfillRect

g.setColor(Color.green); g.fillRect(10,10,8,10);

0,0

810

10

10

drawOvaldrawOval

g.setColor(Color.red);g.drawOval(10,10,8,10);

0,0

810

10

10

fillOvalfillOval

g.setColor(Color.red);g.fillOval(10,10,8,10);

0,0

810

10

10

drawArcdrawArc

g.setColor(Color.blue);g.drawArc(10,10,8,10,0,45);

0,0

810

10

10

fillArcfillArc

g.setColor(Color.blue);g.fillArc(10,10,8,10,0,45);

0,0

drawStringdrawString

g.setColor(Color.Magenta);g.setFont(“Arial”,Font.PLAIN, 30);g.drawString(“Blanca”,10,10);

10

10

Blanca

Posting Your AppletPosting Your Applet

• Write your  JAVA code

• Compile your code

• Make it available

The Applet TagThe Applet Tag<applet

CODE="YourClass.class"WIDTH=www HEIGHT=hhhIGNORE=""></applet>

•Substitute www and hhh for your own width and height.

•Substitute YourClass.class with the name of your own class.

•The Applet tag should be regarded as any other html tag inside your HTML page.

Time to Try it OutTime to Try it Out

Appletson the

Web

• Drawing Applet Skeleton

• Drawing Methods

• Colors

• Fonts

• Posting Applets in the Web

• E-mail any questions to [email protected]

Memory DefragmenterMemory Defragmenter

Task ManagerTask Manager

• Post the sample applet from webct on the web, in your website.

• Read your e-mail

• Visit WebCT, webct.hawaii.edu

Task ManagerTask Manager

• Post the sample applet from webct on the web, in your website.

• Read your e-mail

• Visit WebCT, webct.hawaii.edu