1
36
37
40
41
42 import javax.swing.*;
43 import javax.swing.event.*;
44 import javax.swing.text.*;
45 import javax.swing.border.*;
46 import javax.swing.colorchooser.*;
47 import javax.swing.filechooser.*;
48 import javax.accessibility.*;
49
50 import java.awt.*;
51 import java.awt.event.*;
52 import java.beans.*;
53 import java.util.*;
54 import java.io.*;
55 import java.applet.*;
56 import java.net.*;
57
58
64 public class ToolTipDemo extends DemoModule {
65
66
69 public static void main(String[] args) {
70 ToolTipDemo demo = new ToolTipDemo(null);
71 demo.mainImpl();
72 }
73
74
77 public ToolTipDemo(SwingSet2 swingset) {
78 super(swingset, "ToolTipDemo", "toolbar/ToolTip.gif");
81
82 JPanel p = getDemoPanel();
84 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
85 p.setBackground(Color.white);
86
87 Cow cow = new Cow();
89 cow.getAccessibleContext().setAccessibleName(getString("ToolTipDemo.accessible_cow"));
90
91 cow.setToolTipText(getString("ToolTipDemo.cow"));
94
95 p.add(Box.createRigidArea(new Dimension(1, 150)));
97 p.add(cow);
98 }
99
100
101 class Cow extends JLabel {
102 Polygon cowgon = new Polygon();
103
104 public Cow() {
105 super(createImageIcon("tooltip/cow.gif", getString("ToolTipDemo.bessie")));
106 setAlignmentX(CENTER_ALIGNMENT);
107
108 cowgon.addPoint(3,20); cowgon.addPoint(44,4);
110 cowgon.addPoint(79,15); cowgon.addPoint(130,11);
111 cowgon.addPoint(252,5); cowgon.addPoint(181,17);
112 cowgon.addPoint(301,45); cowgon.addPoint(292,214);
113 cowgon.addPoint(269,209); cowgon.addPoint(266,142);
114 cowgon.addPoint(250,161); cowgon.addPoint(235,218);
115 cowgon.addPoint(203,206); cowgon.addPoint(215,137);
116 cowgon.addPoint(195,142); cowgon.addPoint(143,132);
117 cowgon.addPoint(133,189); cowgon.addPoint(160,200);
118 cowgon.addPoint(97,196); cowgon.addPoint(107,182);
119 cowgon.addPoint(118,185); cowgon.addPoint(110,144);
120 cowgon.addPoint(59,77); cowgon.addPoint(30,82);
121 cowgon.addPoint(30,35); cowgon.addPoint(15,36);
122 }
123
124 boolean moo = false;
125 boolean milk = false;
126 boolean tail = false;
127
128 public boolean contains(int x, int y) {
131 if(!cowgon.contains(new Point(x, y))) {
132 return false;
133 }
134
135 if((x > 30) && (x < 60) && (y > 60) && (y < 85)) {
136 if(!moo) {
137 setToolTipText("<html><center><font color=blue size=+2>" +
138 getString("ToolTipDemo.moo") + "</font></center></html>");
139 moo = true;
140 milk = false;
141 tail = false;
142 }
143 } else if((x > 150) && (x < 260) && (y > 90) && (y < 145)) {
144 if(!milk) {
145 setToolTipText("<html><center><font face=AvantGarde size=+1 color=white>" +
146 getString("ToolTipDemo.got_milk") + "</font></center></html>");
147 milk = true;
148 moo = false;
149 tail = false;
150 }
151 } else if((x > 280) && (x < 300) && (y > 20) && (y < 175)) {
152 if(!tail) {
153 setToolTipText("<html><em><b>" + getString("ToolTipDemo.tail") + "</b></em></html>");
154 tail = true;
155 moo = false;
156 milk = false;
157 }
158 } else if(moo || milk || tail) {
159 setToolTipText(getString("ToolTipDemo.tooltip_features"));
160 moo = false;
161 tail = false;
162 milk = false;
163 }
164
165 return true;
166 }
167 }
168
169 }
170