Java Reference
In-Depth Information
public MouseDemo()
{
super ();
setSize(600,400);
setTitle("Mouse Demo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMouseListener( this ); // Add listener for this object
}
public static void main(String[] args)
{
MouseDemo m = new MouseDemo();
m.setVisible( true );
}
}
Modify this program to create a simple drawing program. When the mouse button
is clicked, a solid circle with a radius of three pixels should be drawn in the JFrame
centered at the mouse coordinates. Draw the circle in the color of your choice.
Make sure that the drawing is correctly redrawn if the JFrame is minimized and
then displayed again.
8. Write a program that graphically displays a vertical bar chart. The input is an
array of integers. Use the index of an array entry as the label on the X axis. The
height of the bar should correspond to the value of the array entry. Scale the height
proportionally so the bar chart fits on the screen. For example, if the array values
are {3000, 4000, 5000}, then the bars should not be drawn 3,000; 4,000; and
5,000 pixels tall. Instead they should fit on the screen but remain in the correct
proportion to the original values (e.g., perhaps 300, 400, and 500 pixels tall, but
the actual values will depend upon the size of your window).
Search WWH ::




Custom Search