0% found this document useful (0 votes)
81 views1 page

Exercises Awt

The document provides instructions for 6 simple GUI programming exercises using Java's Abstract Window Toolkit (AWT): 1. Create an applet with buttons to change the background color to red, green, and blue. 2. Repeat the first exercise as a desktop application using Frame instead of Applet. 3. Create a subclass of Canvas that changes color when clicked and add instances to an applet or frame. 4. Make a text field to enter a color name and map names to Color values to set the background color. 5. Add button or return key handling to change the color based on the text field input. 6. Implement the entire Microsoft Windows desktop environment using only A

Uploaded by

Szabó Attila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views1 page

Exercises Awt

The document provides instructions for 6 simple GUI programming exercises using Java's Abstract Window Toolkit (AWT): 1. Create an applet with buttons to change the background color to red, green, and blue. 2. Repeat the first exercise as a desktop application using Frame instead of Applet. 3. Create a subclass of Canvas that changes color when clicked and add instances to an applet or frame. 4. Make a text field to enter a color name and map names to Color values to set the background color. 5. Add button or return key handling to change the color based on the text field input. 6. Implement the entire Microsoft Windows desktop environment using only A

Uploaded by

Szabó Attila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Customized Onsite Training: Java 7, JSF 2, PrimeFaces, Servlets/JSP, Ajax/jQuery, Android, Spring, Hibernate, Hadoop, GWT, REST, etc:

http://courses.coreservlets.com/

Simple GUIs
1.
Put three buttons in the applet. Have them labeled Red, Green, and Blue. You might want to start by grabbing Buttons.java and Buttons.html from my awt Eclipse project to use as a starting point. Then, base your code very closely on one of the button event handling example from the class notes. I personally prefer ActionExample2 (the interface approach) or ActionExample3 (the inner class approach), but use whichever approach you prefer. Have each button change the applets background color appropriately (i.e., to Color.RED, Color.GREEN, and Color.BLUE). Redo problem #2 using a desktop application instead of an applet. (I.e., use Frame instead of Applet.) In your Frame constructor, before you pop up the Frame, do setLayout(new FlowLayout()). We will explain why in the upcoming lecture on layout managers. To kill a Frame that you started from within Eclipse, click on the red square in the Console tab at the bottom of Eclipse. (Or, copy my CloseableFrame and ExitListener classes into your project, then extend CloseableFrame instead of Frame.) Create a subclass of Canvas that changes color when the user clicks on it. Drop a few in an Applet or a Frame. Make a textfield that lets the user enter a color name. Use a HashMap to map that color name to one of several predefined Color values. When the user presses a button (or, if you prefer, when they hit RETURN in the textfield), change the background color to the color given in the textfield. Use a desktop application. Rewrite Microsoft Windows in the AWT. Finish before bed time.

2. 3.

4. 5.

6.

You might also like