/** Test if a mouse event is inside the "Pin" that allows to change the percentage */ private boolean inPin(MouseEvent ev) { int mouseX = ev.getX(); int mouseY = ev.getY(); int centerX = this.getWidth() / 2; int centerY = this.getHeight() / 2; int radius = Math.min(getWidth() - 4, getHeight() - 4) / 2; double angle = myController.getValue() * 2 * Math.PI; int pinX = centerX + (int) (Math.cos(angle) * radius); int pinY = centerY - (int) (Math.sin(angle) * radius); Rectangle r = new Rectangle(); r.setBounds(pinX - 4, pinY - 4, 8, 8); return r.contains(mouseX, mouseY); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int centerX = this.getWidth() / 2; int centerY = this.getHeight() / 2; int radius = Math.min(getWidth() - 4, getHeight() - 4) / 2; double angle = myController.getValue() * 2 * Math.PI; g.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2); g.setColor(Color.yellow); g.fillArc( centerX - radius, centerY - radius, radius * 2, radius * 2, 0, (int) Math.toDegrees(angle)); int pinX = centerX + (int) (Math.cos(angle) * radius); int pinY = centerY - (int) (Math.sin(angle) * radius); g.setColor(Color.gray.brighter()); g.fill3DRect(pinX - 4, pinY - 4, 8, 8, true); }