// CS111 Lecture 9, February 27, 1998 // Simple Graphical User Interface (GUI) Layout examples. // For details on the contracts of interface objects, see the Application // Programming Interface (API) for the Java Abstract Window Toolkit (java.awt), // which is accessible from the CS111 Documentation page. import java.awt.*; import java.applet.*; public class LayoutTest extends Applet { public void init() { // Code to lay out the components of the applet goes here: this.setFont(new Font("TimesRoman", Font.BOLD, 24)); // Font to use in applet // Create some user interface componenets. Label nameLabel = new Label("Name:"); TextField nameField = new TextField(15); Label courseLabel = new Label("Course:"); Choice courseChoice = new Choice(); courseChoice.addItem("CS110"); courseChoice.addItem("CS111"); courseChoice.addItem("CS230"); Checkbox creditBox = new Checkbox("Credit/Non"); Button registerButton = new Button("Register"); /* // Can change the colors of the applet ... this.setBackground(Color.yellow); this.setForeground(Color.blue); */ /* // ... and of the individual components nameLabel.setBackground(Color.gray); nameField.setBackground(Color.white); courseLabel.setBackground(Color.cyan); courseChoice.setBackground(Color.magenta); creditBox.setBackground(Color.green); registerButton.setBackground(Color.red); */ // Add components to the applet. this.add(nameLabel); this.add(nameField); this.add(courseLabel); this.add(courseChoice); this.add(creditBox); this.add(registerButton); } }