//java architect /
LISTING 6
Figure 2
Figure 3
It doesn’t represent a large part of your
app, so it won’t show up in the taskbar
and it doesn’t have decorations. On Mac
OS X, it won’t show up in the Expose view
either. A JWindow is used for transient
things, such as drop-down menus and
combo boxes. Because our keyboard
overlay is not a large, functional part of
the app, using a JWindow is perfect.
Figure 2 shows what the final app looks
like. As I type into any text field or press
menu shortcut keys, the most recent keystroke appears in the overlay window.
Fancy Pop-Down Menus
In the old days of windowing interfaces,
we had a fairly small number of UI
controls: buttons, sliders, checkboxes,
scroll bars, and menus. That was pretty
much it. Today we have many, many
kinds of custom controls that behave in
lots of different ways.
private static class Popup TabComponent extends JComponent {
}
@Override
protected void paintComponent(Graphics gfx) {
Graphics2D g = (Graphics2D) gfx;
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.
VALUE_ANTIALIAS_ON);
COMMUNITY
JAVA IN ACTION
Color[] colors = new Color[]{
new Color(0.6f,.6f,.6f,0.9f)
,new Color(0.9f,0.9f,0.9f,1f)
,new Color(0.9f,0.9f,0.9f,1f)
,new Color(0.6f,0.6f,0.6f,0.9f)};
float[] stops = new float[]{0.2f,0.4f,0.9f,1f};
LinearGradientPaint paint = new LinearGradientPaint(
new Point(0,0), new Point(0,getHeight()),
stops,colors);
// g.setPaint(new Color(255,255,255,120));
g.setPaint(paint);
Path2D.Double path = new Path2D.Double();
path.move To(get Width()/2, 0);
path.line To(get Width()/2+ 20, 30);
path.line To(get Width()/2-20, 30);
path.closePath();
Area area = new Area(path);
RoundRectangle2D.Double rect = new RoundRectangle2D.
Double(0, 30,getWidth()- 1,getHeight()- 30-1, 30, 30);
area.add(new Area(rect));
ABOUT US
g.fill(area);
g.setPaint(new Color( 50, 50, 50,120));
g.draw(area);
}
blog
Download all listings in this issue as text
37
ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////////// MAY/JUNE 2012