MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / main

Method main

src/demoJS/CursorTest2.java:98–196  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

96 static boolean clickToggle, dragging, pressed, inside;
97
98 public static void main(String[] args) {
99 JFrame frame = new JFrame("Custom Cursor Example");
100 frame.setLayout(new BorderLayout());
101 JPanel panel = new JPanel();
102 panel.setLayout(new FlowLayout());
103 JLabel label = new JLabel("JavaScript Cursor");
104 panel.add(label);
105
106 JPanel drawingPanel = new JPanel() {
107 @Override
108 protected void paintComponent(Graphics g) {
109 super.paintComponent(g);
110 // Get the dimensions of the panel
111 int width = getWidth();
112 int height = getHeight();
113 // Calculate the coordinates for the center of the panel
114 int centerX = width / 2;
115 int centerY = height / 2;
116 // Define the radius of the circle
117 int radius = Math.min(width, height) / 4;
118 // Set the color to red
119 // Draw the circle
120 g.setColor(clickToggle ? Color.BLUE : Color.RED);
121 g.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
122 }
123 };
124
125 drawingPanel.setName("drawingPanel");
126
127 drawingPanel.addMouseListener( new MouseListener() {
128
129 @Override
130 public void mouseClicked(MouseEvent e) {
131 if (dragging) {
132 dragging = false;
133 return;
134 }
135 // flash blue circle
136 System.out.print("clickcount=" + e.getClickCount());
137 clickToggle = !clickToggle;
138 drawingPanel.repaint();
139 }
140
141 @Override
142 public void mousePressed(MouseEvent e) {
143 if (pressed) // multitouch will press multiple times before release
144 return;
145 dragging = false;
146 pressed = true;
147 jsCustomCursor("pressed", e);
148 }
149
150 @Override
151 public void mouseReleased(MouseEvent e) {
152 pressed = false;
153 dragging = false;
154 jsCustomCursor("released", e);
155 }

Callers

nothing calls this directly

Calls 6

addMouseListenerMethod · 0.80
setNameMethod · 0.65
setSizeMethod · 0.65
setVisibleMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected