java on the web

27
Java On The Web Session 15

Upload: tim

Post on 14-Feb-2016

44 views

Category:

Documents


9 download

DESCRIPTION

Java On The Web. Session 15. 0. Memory Upload. JAVA Applets Colors Fonts Drawing Methods Posting your Applet. Applets. An applet is a program that runs embedded in HTML code They must be viewed either in Web Browser Appletviewer. 0. GUI Elements. Applets can display GUI elements - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Java On The Web

Java On The Web

Session 15

Page 2: Java On The Web

Memory Upload

• JAVA Applets• Colors• Fonts• Drawing Methods• Posting your Applet

Page 3: Java On The Web

Applets

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

• They must be viewed either in Web Browser Appletviewer

Page 4: Java On The Web

GUI Elements

• Applets can display GUI elements Graphical User Interface

• Colors• Fonts• Text-Fields, Button , Labels, etc.Butt

on

Page 5: Java On The Web

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

Page 6: Java On The Web

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

Page 7: Java On The Web

Colors

• Colors are made out of 3 values• Each value goes from 0 to 255

REDRED GREENGREEN BLUEBLUE

Page 8: Java On The Web

ColorsBlack Color.black 0,0,0Blue Color.blue 0,0,255Cyan Color.cyan 0,255,255Gray Color.gray 128,128,128Green Color.green 0,255,0Magenta Color.magenta 255,0,255Orange Color.orange 255,200,0Pink Color.pink 255,175,175Red Color.red 255,0,0White Color.white 255,255,255Yellow Color.yellow 255,255,0

Page 9: Java On The Web

Colorsimport 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);

}}

Page 10: Java On The Web

.setColor(Color)

g.setColor(Color.yellow);

g.setColor(Color.red);

g.setColor(MyColor);

Page 11: Java On The Web

Fonts• 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); }}

Page 12: Java On The Web

Methodsvoid 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)

Page 13: Java On The Web

The coordinates0,0

xx

yy

Page 14: Java On The Web

0,0

drawLine

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

10

10

24

18

Page 15: Java On The Web

0,0

drawRect

810

10

10

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

Page 16: Java On The Web

0,0

810

10

10

fillRect

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

Page 17: Java On The Web

0,0

810

10

10

drawOval

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

Page 18: Java On The Web

0,0

810

10

10

fillOval

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

Page 19: Java On The Web

0,0

810

10

10

drawArc

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

Page 20: Java On The Web

0,0

810

10

10

fillArc

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

Page 21: Java On The Web

0,0

drawString

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

10

10

Blanca

Page 22: Java On The Web

Posting Your Applet

• Write your  JAVA code• Compile your code• Make it available

Page 23: Java On The Web

The 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.

Page 24: Java On The Web

Time to Try it Out

Appletson the

Web

Page 25: Java On The Web

• Drawing Applet Skeleton• Drawing Methods• Colors• Fonts• Posting Applets in the Web• E-mail any questions to

[email protected]

Memory Defragmenter

Page 26: Java On The Web

Task Manager

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

• Read your e-mail• Visit WebCT, webct.hawaii.edu

Page 27: Java On The Web

Task Manager

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

• Read your e-mail• Visit WebCT, webct.hawaii.edu