37
38 public class PaintSetEnabledDeadlock extends Frame {
39
40 final TestPanel panel;
41 final Button button;
42
43 public static void main(String[] args) {
44 PaintSetEnabledDeadlock frame = new PaintSetEnabledDeadlock();
45 frame.setSize(200, 200);
46 frame.setVisible(true);
47
48 Robot robot = Util.createRobot();
49 robot.setAutoDelay(100);
50 robot.setAutoWaitForIdle(true);
51
52 for (int i = 0; i < 20; ++i) {
53 Util.clickOnComp(frame.panel, robot);
54 Util.clickOnComp(frame.button, robot);
55 }
56
57 frame.panel.stop();
58 frame.dispose();
59
60 System.out.println("Test passed.");
61 }
62
63 public PaintSetEnabledDeadlock() {
64 super("7108598 test");
65 setLayout(new GridLayout(1, 2));
66 addWindowListener(new WindowAdapter() {
67
68 @Override
69 public void windowClosing(WindowEvent e) {
70 panel.stop();
71 System.exit(0);
72 }
73 });
74 panel = new TestPanel();
75 add(panel);
76 button = new Button("Enable");
77 button.addMouseListener(new MouseAdapter() {
78
79 @Override
123 paramGraphics.drawImage(image, 0, 0, this);
124 }
125 }
126 }
127
128 @Override
129 public void run() {
130 while (active) {
131 try {
132 synchronized (sync) {
133 sync.wait();
134 }
135 } catch (InterruptedException ex) {
136 }
137 if (active) {
138 draw();
139 }
140 }
141 }
142
143 public void stop() {
144 active = false;
145 try {
146 synchronized (sync) {
147 sync.notify();
148 }
149 synchronized (thread) {
150 thread.wait();
151 }
152 } catch (InterruptedException ex) {
153 }
154 }
155
156 public void draw() {
157 synchronized (getTreeLock()) {
158 if (image != null) {
159 Graphics localGraphics = image.getGraphics();
160 Dimension size = getSize();
161 localGraphics.setColor(isEnabled() ? Color.green : Color.red);
162 localGraphics.fillRect(0, 0, size.width, size.height);
163 super.paint(localGraphics);
164 localGraphics.dispose();
165 getTreeLock().notifyAll();
166 }
167 }
168 }
169
170 public void sync() {
171 synchronized (sync) {
172 sync.notify();
173 }
|
37
38 public class PaintSetEnabledDeadlock extends Frame {
39
40 final TestPanel panel;
41 final Button button;
42
43 public static void main(String[] args) {
44 PaintSetEnabledDeadlock frame = new PaintSetEnabledDeadlock();
45 frame.setSize(200, 200);
46 frame.setVisible(true);
47
48 Robot robot = Util.createRobot();
49 robot.setAutoDelay(100);
50 robot.setAutoWaitForIdle(true);
51
52 for (int i = 0; i < 20; ++i) {
53 Util.clickOnComp(frame.panel, robot);
54 Util.clickOnComp(frame.button, robot);
55 }
56
57 boolean ret = frame.panel.stop();
58 frame.dispose();
59
60 if (!ret) {
61 throw new RuntimeException("Test failed!");
62 }
63 System.out.println("Test passed.");
64 }
65
66 public PaintSetEnabledDeadlock() {
67 super("7108598 test");
68 setLayout(new GridLayout(1, 2));
69 addWindowListener(new WindowAdapter() {
70
71 @Override
72 public void windowClosing(WindowEvent e) {
73 panel.stop();
74 System.exit(0);
75 }
76 });
77 panel = new TestPanel();
78 add(panel);
79 button = new Button("Enable");
80 button.addMouseListener(new MouseAdapter() {
81
82 @Override
126 paramGraphics.drawImage(image, 0, 0, this);
127 }
128 }
129 }
130
131 @Override
132 public void run() {
133 while (active) {
134 try {
135 synchronized (sync) {
136 sync.wait();
137 }
138 } catch (InterruptedException ex) {
139 }
140 if (active) {
141 draw();
142 }
143 }
144 }
145
146 public boolean stop() {
147 active = false;
148 try {
149 sync();
150 thread.join(1000);
151 if (thread.isAlive()) {
152 thread.interrupt();
153 return false;
154 }
155 } catch (InterruptedException ex) {
156 return false;
157 }
158 return true;
159 }
160
161 public void draw() {
162 synchronized (getTreeLock()) {
163 if (image != null) {
164 Graphics localGraphics = image.getGraphics();
165 Dimension size = getSize();
166 localGraphics.setColor(isEnabled() ? Color.green : Color.red);
167 localGraphics.fillRect(0, 0, size.width, size.height);
168 super.paint(localGraphics);
169 localGraphics.dispose();
170 getTreeLock().notifyAll();
171 }
172 }
173 }
174
175 public void sync() {
176 synchronized (sync) {
177 sync.notify();
178 }
|