

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Instructions for two java programming exercises on day-04. The exercises cover creating and modifying applets, adding buttons and labels, handling button events, and creating a simple calculator using checkboxes and text fields. Students will learn how to import packages, declare and create components, and write action methods.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Java-Programming Day-04 Taking Turn
public boolean action(Event event,Object action){ String s; s=(String)action; //getting label of the button clicked label1.setText(s); return true; }
Add following code in your action method to avoid exceptions
if(event.target instanceof Button){
s=(String)action; label1.setText(s); }
a. Write an applet for a super store and do the following i. Create a String array “Items” for 10 strings ii. Create a String variable “customerName”
iii. Set the layout to FlowLayout aligned to left iv. Add a text filed with label “Customer Name”
v. Add 10 Check boxes with labels, each label is the name of an item in the superstore vi. Add a text area with the label “Your Item List” vii. Add a button with label “Show List”
b. Write code in the action method for the “Show List” button for the following action when this button is pressed
i. Check the state of each checkbox ii. If a checkbox is checked get the label associated with the checkbox and save it to the “Item” array
iii. Get the text from the text field (the customer name) and save to the variable “customerName” (if text field is empty save “Anonymous” in the variable)
iv. Display customer name in the text area v. Display the contents of the array in the Text area
b. Add a button “Check All” to your super store applet, the button when pressed should check all the checkboxes
c. Add a button “New Customer” to your super store applet, the button when pressed should i. Uncheck all the checkboxes ii. Clear the text field
iii. Clear the text area
a. Try super store applet using some different layout