270 likes | 419 Vues
This guide provides an overview of using Java applets that run embedded in HTML code. Discover how to create your applet using Java's AWT library, incorporating colors, fonts, and graphics through various drawing methods. Learn to post your applet using the HTML `<applet>` tag, ensuring it is viewable in web browsers or applet viewers. Whether you’re creating GUI elements or drawing, this resource supports you in developing interactive web applications.
E N D
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 • Graphical User Interface • Colors • Fonts • Text-Fields, Button , Labels, etc. Button
0 Skeleton • import java.awt.*; • import java.applet; • public class MyApplet extends Applet { • public void init( ){ • } • public void paint(Graphics g){ • //instructions go here • } • }
0 Skeleton • import java.awt.*; • import java.applet; • public class MyApplet extends Applet { • public void init( ){ • } • public void paint(Graphics g){ • //instructions go here • } • }
Colors • Colors are made out of 3 values • Each value goes from 0 to 255 • RED • GREEN • BLUE
0 Colors
Colors • 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) • g.setColor(Color.yellow); • g.setColor(Color.red); • g.setColor(MyColor);
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); • } • }
The coordinates 0,0 x y
0,0 0 drawLine 10 10 24 18 g.drawLine(10,10,18,24);
0,0 0 drawRect 10 10 8 10 g.setColor(Color.green); g.drawRect(10,10,8,10);
0,0 0 fillRect 10 10 8 10 g.setColor(Color.green); g.fillRect(10,10,8,10);
0,0 0 drawOval 10 10 8 10 g.setColor(Color.red); g.drawOval(10,10,8,10);
0,0 0 fillOval 10 10 8 10 g.setColor(Color.red); g.fillOval(10,10,8,10);
0,0 0 drawArc 10 10 8 10 g.setColor(Color.blue); g.drawArc(10,10,8,10,0,45);
0,0 0 fillArc 10 10 8 10 g.setColor(Color.blue); g.fillArc(10,10,8,10,0,45);
0,0 0 drawString 10 Blanca 10 g.setColor(Color.Magenta); g.setFont(“Arial”,Font.PLAIN, 30); g.drawString(“Blanca”,10,10);
Posting Your Applet • Write your JAVA code • Compile your code • Make it available
The Applet Tag • <applet • CODE="YourClass.class" • WIDTH=www HEIGHT=hhh • IGNORE=""></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 Out Applets on the Web
Memory Defragmenter • Drawing Applet Skeleton • Drawing Methods • Colors • Fonts • Posting Applets in the Web • E-mail any questions to blanca@hawaii.edu
Task Manager • Post the sample applet from webct on the web, in your website. • Read your e-mail • Visit WebCT, webct.hawaii.edu
Task Manager • Post the sample applet from webct on the web, in your website. • Read your e-mail • Visit WebCT, webct.hawaii.edu