Java Reference
In-Depth Information
private void createAppletGUI() {
// Set layout for content pane
getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT, 20,
30));
JButton button;
// Stores
a button
Font[] fonts = { new Font("Serif", Font.ITALIC, 10),
// Two
fonts
new Font("Dialog", Font.PLAIN, 14)
};
BevelBorder edge = new BevelBorder(BevelBorder.RAISED); //
Bevelled border
// Add the buttons using alternate fonts
for(int i = 1; i <= 6; ++i) {
add(button = new JButton("Press " + i));
// Add
the button
button.setFont(fonts[i%2]);
// One of
our own fonts
button.setBorder(edge);
// Set
the button border
}
}
}
Directory "TryApplet"
Of course, to run the applet you need an .html file containing the following:
<html> <head> </head>
<body bgcolor="000000">
<center>
<applet
code = "TryApplet.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
This specifies the width and height of the applet — you can use your own values here if you want. You
can save the file as TryApplet.htm .
After you have compiled the applet source code using javac , you can execute it with the appletviewer
program by entering the following command from the folder containing the . htm file and the .class file:
appletviewer TryApplet.html
Search WWH ::




Custom Search