Debian Codegraph @

tests/reproducers/simple/JavawsAWTRobotUsageSample/srcs/JavawsAWTRobotUsageSample.java

raw
1 /* JavawsAWTRobotUsageSample.java
2 Copyright (C) 2012 Red Hat, Inc.
3
4 This file is part of IcedTea.
5
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37
38 import java.applet.Applet;
39 import java.awt.Graphics;
40 import java.awt.Color;
41 import java.awt.Image;
42 import java.awt.Panel;
43 import java.awt.Button;
44 import java.awt.Dimension;
45 import java.awt.event.MouseEvent;
46 import java.awt.event.MouseListener;
47 import java.awt.event.MouseMotionListener;
48
49 public class JavawsAWTRobotUsageSample extends Applet {
50
51 private static final String initStr = "JavawsAWTRobotUsageSample is ready for awt tests!";
52 public static final String iconFile = "marker.png";
53
54 public static final Color APPLET_COLOR = new Color(230, 230, 250); // lavender
55 public static final Color BUTTON_COLOR1 = new Color(32, 178, 170); // light sea green
56
57 public Image img;
58 public Panel panel;
59
60 public void init(){
61 img = getImage(getCodeBase(), iconFile);
62
63 createGUI();
64
65 writeAppletInitialized();
66 }
67
68 //this method should be called by the extending applet
69 //when the whole gui is ready
70 public void writeAppletInitialized(){
71 System.out.println(initStr);
72 }
73
74 //paint the icon in upper left corner
75 @Override public void paint(Graphics g){
76 int width = 32;
77 int height = 32;
78 int x = 0;
79 int y = 0;
80 g.drawImage(img, x, y, width, height, this);
81 super.paint(g);
82 }
83
84 private Button createButton(String label, Color color) {
85 Button b = new Button(label);
86 b.setBackground(color);
87 b.setPreferredSize(new Dimension(100, 50));
88 return b;
89 }
90
91 // sets background of the applet and adds the panel with one button
92 private void createGUI() {
93 setBackground(APPLET_COLOR);
94
95 panel = new Panel();
96 panel.setBounds(33,33,267,267);
97
98 Button b = createButton("", BUTTON_COLOR1);
99
100 b.addMouseMotionListener(new MouseMotionListener() {
101 public void mouseDragged(MouseEvent e) {
102 System.out.println("mouseDragged");
103 }
104
105 public void mouseMoved(MouseEvent e) {
106 System.out.println("mouseMoved");
107 }
108 });
109
110 b.addMouseListener(new MouseListener() {
111
112 public void mouseClicked(MouseEvent e) {
113 // figure out which mouse button is pressed
114 switch (e.getButton()) {
115 case MouseEvent.BUTTON1:
116 System.out.println("mouseClickedButton1");
117 break;
118 case MouseEvent.BUTTON2:
119 System.out.println("mouseClickedButton2");
120 break;
121 case MouseEvent.BUTTON3:
122 System.out.println("mouseClickedButton3");
123 break;
124 default:
125 break;
126 }
127 }
128
129 public void mouseEntered(MouseEvent e) {
130 System.out.println("mouseEntered");
131 }
132
133 public void mouseExited(MouseEvent e) {
134 System.out.println("mouseExited");
135 }
136
137 public void mousePressed(MouseEvent e) {
138 // figure out which mouse button is pressed
139 switch (e.getButton()) {
140 case MouseEvent.BUTTON1:
141 System.out.println("mousePressedButton1");
142 break;
143 case MouseEvent.BUTTON2:
144 System.out.println("mousePressedButton2");
145 break;
146 case MouseEvent.BUTTON3:
147 System.out.println("mousePressedButton3");
148 break;
149 default:
150 break;
151 }
152 }
153
154 public void mouseReleased(MouseEvent e) {
155 // figure out which mouse button was pressed
156 switch (e.getButton()) {
157 case MouseEvent.BUTTON1:
158 System.out.println("mouseReleasedButton1");
159 break;
160 case MouseEvent.BUTTON2:
161 System.out.println("mouseReleasedButton2");
162 break;
163 case MouseEvent.BUTTON3:
164 System.out.println("mouseReleasedButton3");
165 break;
166 default:
167 break;
168 }
169 }
170 });
171
172 panel.add(b);
173
174 this.add(panel);
175 }
176 }