final Point topLeftPoint = new Point( viewportOffset + BORDER, viewportOffset + BORDER_TOP); final Point topCenterPoint = new Point( viewportOffset + viewportBounds.width / 2, viewportOffset + BORDER ); final Point topRightPoint = new Point( viewportOffset + viewportBounds.width - BORDER, topCenterPoint.y); final Point bottomLeftPoint = new Point( topLeftPoint.x, viewportOffset + viewportBounds.height - BORDER); final Point bottomRightPoint = new Point( topRightPoint.x, bottomLeftPoint.y); final Point rightChatboxPoint = isResizeable ? new Point( viewportOffset + chatboxBounds.width - BORDER, bottomLeftPoint.y) : bottomRightPoint; final Point canvasTopRightPoint = isResizeable ? new Point( (int)client.getRealDimensions().getWidth(), 0) : topRightPoint;
* Fetches angle relative to screen centre point * where 3 O'Clock is 0 and 12 O'Clock is 270 degrees * * @param screenPoint * @return angle in degress from 0-360. */ public double getAngle(Point screenPoint) { double dx = screenPoint.getX() - mCentreX; // Minus to correct for coord re-mapping double dy = -(screenPoint.getY() - mCentreY); double inRads = Math.atan2(dy,dx); // We need to map to coord system when 0 degree is at 3 O'clock, 270 at 12 O'clock if (inRads < 0) inRads = Math.abs(inRads); else inRads = 2*Math.PI - inRads; return Math.toDegrees(inRads); }
private final Point pp = new Point(); private JLabel image; Point cp = e.getPoint(); Point vp = vport.getViewPosition(); vp.translate(pp.x-cp.x, pp.y-cp.y); image.scrollRectToVisible(new Rectangle(vp, vport.getSize())); pp.setLocation(cp); image.setCursor(hndCursor); pp.setLocation(e.getPoint()); image.setCursor(defCursor); image.repaint();
Point myPoint = new Point( 0, 0 ); System.out.println( myPoint ); myPoint.setLocation( 1.0, 0.0 ); System.out.println( myPoint ); String myString = new String( "old String" ); System.out.println( myString ); myString.replaceAll( "old", "new" ); System.out.println( myString );
private Point dragLocation = new Point(); setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); setPreferredSize(new Dimension(500, 500)); final JFrame f = new JFrame("Test"); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { if (drag) { if (dragLocation.getX()> getWidth()-10 && dragLocation.getY()>getHeight()-10) { System.err.println("in"); setSize((int)(getWidth()+(e.getPoint().getX()-dragLocation.getX())), (int)(getHeight()+(e.getPoint().getY()-dragLocation.getY()))); dragLocation = e.getPoint(); f.getContentPane().setLayout(new BorderLayout()); f.getContentPane().add(this,BorderLayout.CENTER); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true);
Point point = e.getPoint(); int width = getWidth(); int height = getHeight(); selectedCell = new Point(column, row); repaint(); addMouseMotionListener(mouseHandler); Graphics2D g2d = (Graphics2D) g.create(); int width = getWidth(); int height = getHeight(); for (int row = 0; row < rowCount; row++) { for (int col = 0; col < columnCount; col++) { Rectangle cell = new Rectangle( xOffset + (col * cellWidth), yOffset + (row * cellHeight),
basePanel.setLayout(new BorderLayout()); if (useSlideButton) { final JPanel statusPanel = new JPanel(); basePanel.add(statusPanel, BorderLayout.SOUTH); statusPanel.add(new JButton("Slide Left") { private static final long serialVersionUID = 9204819004142223529L; if (w instanceof JFrame) { final JFrame j = (JFrame) w; if (j.getContentPane().getComponents().length > 0) { throw new RuntimeException("ProgramCheck: Parent already contains content."); j.getContentPane().add(basePanel); ((JFrame) w).getGlassPane().setVisible(false); ((JWindow) w).setGlassPane(glassPane); glassPane.setVisible(true); final Point p2 = new Point(0, 0); if (slideType == LEFT) { p2.x += w; basePanel.revalidate(); if (useLoop) { final int max = (slideType == LEFT) || (slideType == RIGHT) ? w : h;
final JFrame frame = new JFrame("Image zoom"); frame.getContentPane().add(zoomPanel); final Ticker t = new Ticker(zoomPanel); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { t.done(); frame.dispose(); frame.setLocation(new Point(640, 0)); frame.pack(); frame.setVisible(true); setSize(new Dimension(400, 400)); setMinimumSize(new Dimension(400, 400)); setPreferredSize(new Dimension(400, 400)); setOpaque(true); repaint(40 + x * STEP, 45 + y * STEP, 40 + (x * STEP) - 3, 45 + (y * STEP) - 3); g2.setColor(getBackground()); try { Rectangle rect = new Rectangle(p.x - 4, p.y - 4, 8, 8); final BufferedImage capture = robot.createScreenCapture(rect);
JFrame frame = new JFrame("FX"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); // do the layout manually frame.add(jButton); frame.add(fxPanel); frame.setVisible(true); jButton.setSize(new Dimension(200, 27)); fxPanel.setSize(new Dimension(300, 300)); fxPanel.setLocation(new Point(0, 27)); frame.getContentPane().setPreferredSize(new Dimension(300, 327)); frame.pack(); frame.setResizable(false);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double xScale = ((double) getWidth() - (2 * padding) - labelPadding) / (scores.size() - 1); double yScale = ((double) getHeight() - 2 * padding - labelPadding) / (getMaxScore() - getMinScore()); int x1 = (int) (i * xScale + padding + labelPadding); int y1 = (int) ((getMaxScore() - scores.get(i)) * yScale + padding); graphPoints.add(new Point(x1, y1)); g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding); g2.setColor(Color.BLACK); invalidate(); this.repaint(); mainPanel.setPreferredSize(new Dimension(800, 600)); JFrame frame = new JFrame("DrawGraph"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
JFrame frame = new JFrame(); final JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); + "Blabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\n"); textArea.setSelectionColor(Color.RED); frame.add(pane); frame.setSize(300, 120); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); pos2 + turnToString2.length(), new DefaultHighlighter.DefaultHighlightPainter(Color.yellow)); int y = startIndex.y + (pane.getHeight() - 10); System.out.println("Pane Height : " + pane.getHeight()); System.out.println("X : " + startIndex.x); System.out.println("Y : " + y); System.out.println("Y (pos2) : " + startIndex.y); textArea.setCaretPosition(textArea.viewToModel(new Point(startIndex.x, y))); pane.scrollRectToVisible(new Rectangle(startIndex.x, y));
this.add(map, BorderLayout.CENTER); private final DecimalFormat df = new DecimalFormat(format); private JLabel name = new JLabel("", JLabel.CENTER); private Point point = new Point(); private JLabel position = new JLabel(toString(point), JLabel.CENTER); private int blocks; super(new GridLayout(1, 0)); name.setText(s); this.setBackground(hue.getColor()); point.setLocation(0, 0); blocks = 0; update(); position.setText(CabPanel.this.toString(point)); odometer.setText(df.format(blocks)); map.repaint(); this.setPreferredSize(new Dimension(32 * SIZE, 32 * SIZE)); JFrame f = new JFrame("Dispatch"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double xScale = ((double) getWidth() - 2 * BORDER_GAP) / (scores.size() - 1); double yScale = ((double) getHeight() - 2 * BORDER_GAP) / (MAX_SCORE - 1); int x1 = (int) (i * xScale + BORDER_GAP); int y1 = (int) ((MAX_SCORE - scores.get(i)) * yScale + BORDER_GAP); graphPoints.add(new Point(x1, y1)); g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, BORDER_GAP, BORDER_GAP); g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, getWidth() - BORDER_GAP, getHeight() - BORDER_GAP); JFrame frame = new JFrame("DrawGraph"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
final JFrame frame = new JFrame("Gradient JButton Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new FlowLayout()); frame.add(JGradientButton.newInstance()); frame.setSize(new Dimension(300, 150)); // used for demonstration frame.setLocationRelativeTo(null); frame.setVisible(true); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new GradientPaint( new Point(0, 0), Color.WHITE, new Point(0, getHeight()), Color.PINK.darker())); g2.fillRect(0, 0, getWidth(), getHeight()); g2.dispose();
private Point startPoint = new Point(0, 0); private Point rectLocale = new Point(); private Dimension rectSize = new Dimension(); private int zoom = 80; raw = new Robot().createScreenCapture(new Rectangle( Toolkit.getDefaultToolkit().getScreenSize())); MouseBehavior behavior = new MouseBehavior(); g2d.drawRect(x2, y2, width2, height2); } else { g2d.draw(new Rectangle(rectLocale, rectSize)); b.addMouseMotionListener(behavior); b.addMouseListener(behavior); b.addMouseWheelListener(behavior); JFrame f = new JFrame(); f.setLocation(10, 10); f.setDefaultCloseOperation(3); f.add(b); f.pack(); f.setVisible(true); public void mousePressed(MouseEvent e) { startPoint = e.getPoint(); rectLocale = new Point(); rectSize = new Dimension(); capture = null;
int n = 6; //Number of labels int radius = 100; Point centre = new Point(200,200); int dx = (int)(radius * Math.sin(theta)); int dy = (int)(-radius * Math.cos(theta)); Point p = new Point(centre.x + dx, centre.y + dy); points.add(p); JFrame frame = new JFrame("Labels in a circle"); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for (Point point : points) { JLabel label = new JLabel("Point " + count); panel.add(label); count++; layout.putConstraint(SpringLayout.WEST, label, point.x, SpringLayout.WEST, panel); panel.setLayout(layout); frame.add(panel); frame.setVisible(true);
private Point p1 = new Point(100, 100); private Point p2 = new Point(540, 380); private boolean drawing; this.setPreferredSize(new Dimension(640, 480)); this.addMouseListener(mouseHandler); this.addMouseMotionListener(mouseHandler); p1 = e.getPoint(); p2 = p1; repaint(); this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0)); this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA)); this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0)); this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA)); LinePanel.this.p1.translate(dx, dy); LinePanel.this.p2.translate(dx, dy); LinePanel.this.repaint(); ControlPanel.this.getInputMap(WHEN_IN_FOCUSED_WINDOW) .put(k, k.toString()); ControlPanel.this.getActionMap() .put(k.toString(), new AbstractAction() {
public JComponent makeUI() { DragPanel p1 = new DragPanel(); p1.setBorder(BorderFactory.createLineBorder(Color.BLACK)); p1.add(new JLabel(UIManager.getIcon("OptionPane.warningIcon"))); p1.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon"))); p1.add(new JLabel("Label1")); p1.addMouseListener(handler); LabelTransferHandler th = new LabelTransferHandler(); p1.setTransferHandler(th); p2.setBorder(BorderFactory.createLineBorder(Color.BLACK)); p2.addMouseListener(handler); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new DragTest3().makeUI()); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); @Override public void dragMouseMoved(DragSourceDragEvent dsde) { Point pt = dsde.getLocation(); pt.translate(5, 5); // offset Point pt = p.draggingLabel.getLocation();
fillCells.add(new Point(x, y)); repaint(); JFrame window = new JFrame(); window.setSize(840, 560); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.add(grid); window.setVisible(true); grid.fillCell(0, 0); grid.fillCell(79, 0);
private static final int W = 640; private static final int H = 480; private Point textPt = new Point(W / 2, H / 2); private Point mousePt; this.setFont(new Font("Serif", Font.ITALIC + Font.BOLD, 32)); this.addMouseListener(new MouseAdapter() { repaint(); this.addMouseMotionListener(new MouseMotionAdapter() { int dx = e.getX() - mousePt.x; int dy = e.getY() - mousePt.y; textPt.setLocation(textPt.x + dx, textPt.y + dy); mousePt = e.getPoint(); repaint(); JFrame f = new JFrame(TITLE); f.add(new MouseDragTest()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);