17.24 HOMEWORK


17.24 HOMEWORK

  1. As an exercise in using a panel to organize components in a window, write a Java program that allows you to enter text in a JTextArea component and then to fetch the text thus entered so that it can be displayed in a terminal window. Your top-level frame should consist of two JPanel objects arranged vertically. The top JPanel object should contain a label at the very top announcing the purpose of the window, and a text-entry area below that. The text-entry area can be an object of type JTextArea. The bottom panel should consist of three buttons as follows:

    1. A button, with label "Start," that allows text to be entered in the text-area part of the window.

    2. A button, labeled "Stop," that when pressed disallows any further keyboard entry of text.

    3. A button, labeled "Get Text," that extracts the entire text entered by the user in the text window and then displays the text in the user's terminal.

  2. Design a ColorMixer applet for your web page. As depicted in Figure 17.44, the upper half of the applet should consist of a Canvas object that shows the result of mixing R, G, and B color components. The lower half of the applet should be a panel consisting of three subpanels, as depicted in greater detail in Figure 17.45. Each of these three subpanels should look like what is shown in Figure 17.46-that is, each subpanel should consist of a Canvas object at the top and a Scrollbar and a TextField objects at the bottom. The scrollbar is for altering the color value of a color component. The text field is for displaying a numerical readout of the current value of that component.

    click to expand
    Figure 17.44

    click to expand
    Figure 17.45

    click to expand
    Figure 17.46

  3. Create a simple two function (add/subtract) calculator using Qt. It should also include an all-clear (AC) button. Use QGridLayout to manage the positioning of the buttons and the display. A QLineEdit object can be used for the display, and QPushButton objects for the buttons.

  4. Design a countdown timer using Qt. A slider should control the length of time the timer is set for, an LCD display to show how much time is left, and buttons to start, stop, and reset the timer. When the timer is started, the start and reset buttons should be disabled and the stop button enabled. When the timer expires or is stopped, the stop button should be disabled and the start and reset buttons should be enabled.

  5. Write a program using GNOME/GTK+ that creates a window divided into two main parts. The top part should be an empty area where the user can click the mouse. The bottom part should be a label where the coordinates of the mouse click in the upper area are displayed. The displayed coordinates should be relative to the top left corner of the window.

  6. Write a program using GNOME/GTK+ that can display images. The program should include a menu with "Open" (open a picture), "Close" (close a picture), "Exit" (exit the program), and "About" (a short message about the author) items. The image should be displayed inside a scrolled window.

  7. Write a Java applet that allows the viewer at a client machine to see a "picture postcard" that consists of an image and a brief greetings, both as specified in the HTML file. More specifically, the applet should do the following:

    1. Display an image retrieved from a URL that is specified in the HTML file.

    2. Draw a rectangular box whose width, height, and location are specified by appropriate parameters in the HTML file.

    3. Display the greetings inside the box. The message is supplied as a string in the HTML file.

    Your applet should work with an HTML file similar to the following:

     <HTML> <TITLE> A Flexible Applet </TITLE> <BODY BGCOLOR="#000000"> <APPLET CODE="FlexiApplet.class" WIDTH=650 HEIGHT=400> <PARAM NAME=BOX_WIDTH VALUE="170"> <PARAM NAME=BOX_HEIGHT VALUE=50> <PARAM NAME=BOX_X VALUE=80> <PARAM NAME=BOX_Y VALUE=220> <PARAM NAME=MESSAGE VALUE="Greetings from the Land of Objects"> <PARAM NAME=IMAGE_URL VALUE="http://machine-name/Portrait.jpg"> </APPLET> </BODY> </HTML> 

  8. Write a Java applet that allows a remote user to draw a free-form sketch by clicking the mouse at different points in the applet window. It should also be possible to run the program as a graphical application for command-line invocation.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net