Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘getGraphics’

FreeHand Drawing: AWT Drawing – Part 4

FreeHand Drawing: Chaining of P1 and P2 between Reported Drag Events

But for Free-Hand drawing, we should not wait till mouse release. We should draw while the mouse is dragged. This means we need to arrange the points P1 and P2 on each reported drag event. In the first part of the below picture, the Red Cross line shows the MouseEvent which AWT reports to the listener. We can still use the drawLine API and connect the currently reported point with the previous one. The net effect is a smooth curve even-though what we draw is a straight line in small chunks. Note, AWT reports the drag events so quickly and hence user will not see the straight inter-connected lines.

Continue Reading →

Graphics Basic – AWT Drawing Part 0

Graphics paint and repaint methods

In Java, Graphics objects take care of drawing works. The Graphics object draws the components of AWT components. In other words, all the AWT Components are linked with an AWT Graphics object which takes care of how to draw them. Note, java containers like Frame and Dialogs are also a component and hence they also contain the Graphics object.

The Graphics object holds the drawing factors like Color, Font, Line Thickness. It also exposes methods to do drawings like Line, rectangle, Circle. When the program coder invokes the drawing methods on the Graphics objects, it applies the properties like Color, Fonts etc. to the drawing.

Continue Reading →