public class WelcomeApplet extends JApplet
1: //WelcomeApplet.java
2: //Displays a one-line welcome in a browser window.
4: import java.awt.Color;
5: import java.awt.Font;
6: import java.awt.Graphics;
7: import javax.swing.JApplet;
9: public class WelcomeApplet extends JApplet
10: {
11: private String welcomeText;
12: private Font font;
14: public void init()
15: {
16: //Set background color, then foreground (text) color:
17: setBackground(Color.CYAN);
18: setForeground(Color.RED);
20: //Create the desired font:
21: font = new Font("Serif", Font.BOLD, 48);
23: //Start building the welcome text message:
24: welcomeText = "Welcome";
25: }
27: public void start()
28: {
29: //Continue building the welcome text message:
30: welcomeText += " to the ";
31: }
33: public void paint(Graphics g)
34: {
35: //Finish building the welcome text message:
36: welcomeText += "Java Workshop!";
38: //Set previously-created font as the one to use:
39: g.setFont(font);
41: //Display now-complete welcome message,
42: //using the chosen colors and font:
43: g.drawString(welcomeText, 70, 150);
45: }
46: }
48: /*
49: The three methods shown are called automatically by the browser.
50: The order in which they are called is: init(), start(), paint().
51: The paint method displays the local "Graphics object".
52: */