Series: AWT Special

Explained AWT code for special programs.

Java Create Random Color

We know using java.awt.Color class, different colors (nearly 16 million shades) can be created and applied to graphics or components. Using java.util.Random class, various colors can be produced randomly and applied to any component. In the following program, each button click gives different color to the frame. For generating colors randomly, here we use java.util.Random …

Java Create Random Color Read More »

Mouse Multiple Clicks getClickCount()

getClickCount() of MouseEvent class returns the number of clicks done on mouse. Following is the method signature as defined in class java.awt.event.MouseEvent public int getClickCount(): Returns the number of mouse clicks associated with this event. Mouse Multiple Clicks getClickCount() program uses getClickCount() to know the number of clicks done on the button. import java.awt.*; import …

Mouse Multiple Clicks getClickCount() Read More »

Find X Y Coordinates Mouse Cursor Location

A similar program is available in frame – Finding x and y Coordinates of Mouse Position. The same frame program is converted to applet. Following is the example. The mouse cursor location in x and y Coordinates and the type of action are displayed on the applet window and also on the applet status bar. …

Find X Y Coordinates Mouse Cursor Location Read More »

Applet Mouse Event MouseAdapter Example

We have seen earlier a similar program Handling Mouse Events with MouseAdapter Example with an introduction to MouseAdapter, but the window here is frame. Let us do another program with applet window. The following program displays a message "Mouse is clicked" in the applet window and "MouseMotionAdapter is in action" at status bar when mouse …

Applet Mouse Event MouseAdapter Example Read More »

Java Centered Text with Underline

This code gives strength on AWT graphics programming. There are no predefined methods that can be used straightaway to place the text in the center of the frame and also underline the text. Some programming techniques are required to solve the task. Example on Java Centered Text with Underline The following program places the sting …

Java Centered Text with Underline Read More »

Java No Layout Manager setBounds()

We know earlier in "Java Layout Managers" that two styles of placing components in containers – pixel format and position format. Now let us discuss clearly what pixel format is and how to place a component in terms of pixels. We also know earlier, the default layout manager for Frame is BorderLayout and for Panel …

Java No Layout Manager setBounds() Read More »