Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import java.awt.Point;

public class Main {
    public static Point getPositionWithinWindow(Component component, Component parent, Point p) {
        Point[] pointCheck = new Point[] { (Point) p.clone(), (Point) p.clone(), (Point) p.clone(),
                (Point) p.clone() };
        int w = component.getWidth();
        int h = component.getHeight();
        pointCheck[0].translate(w, h);
        pointCheck[1].translate(0, h);
        pointCheck[2].translate(w, 0);
        pointCheck[3].translate(0, 0);
        for (Point p2 : pointCheck) {
            if (parent.getBounds().contains(p2)) {
                p2.translate(-w, -h);
                return p2;
            }
        }
        return p;
    }
}