Search in sources :

Example 41 with Toolkit

use of java.awt.Toolkit in project yyl_example by Relucent.

the class TankGame method initBounds.

private void initBounds(JFrame frame) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int fw = Constant.Canvas_WIDTH + 8;
    int fh = Constant.Canvas_HEIGHT + 34;
    int fx = (screenSize.width - fw) / 2;
    int fy = (screenSize.height - fh) / 2;
    frame.setBounds(fx, fy, fw, fh);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 42 with Toolkit

use of java.awt.Toolkit in project yyl_example by Relucent.

the class TakePictures method initBounds.

private void initBounds(JFrame frame) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int fw = 800;
    int fh = 600;
    int fx = (screenSize.width - fw) / 2;
    int fy = (screenSize.height - fh) / 2;
    frame.setBounds(fx, fy, fw, fh);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 43 with Toolkit

use of java.awt.Toolkit in project jadx by skylot.

the class MainWindow method registerMouseNavigationButtons.

private void registerMouseNavigationButtons() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    toolkit.addAWTEventListener(event -> {
        if (event instanceof MouseEvent) {
            MouseEvent mouseEvent = (MouseEvent) event;
            if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
                int rawButton = mouseEvent.getButton();
                if (rawButton <= 3) {
                    return;
                }
                int button = remapMouseButton(rawButton);
                switch(button) {
                    case 4:
                        tabbedPane.navBack();
                        break;
                    case 5:
                        tabbedPane.navForward();
                        break;
                }
            }
        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}
Also used : MouseEvent(java.awt.event.MouseEvent) Toolkit(java.awt.Toolkit)

Example 44 with Toolkit

use of java.awt.Toolkit in project binnavi by google.

the class GuiHelper method centerChildToParent.

/**
 * Centers the child component relative to it's parent component
 *
 * @param parent
 * @param child
 * @param bStayOnScreen
 */
public static final void centerChildToParent(final Component parent, final Component child, final boolean bStayOnScreen) {
    int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
    int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
    if (bStayOnScreen) {
        final Toolkit tk = Toolkit.getDefaultToolkit();
        final Dimension ss = new Dimension(tk.getScreenSize());
        if ((x + child.getWidth()) > ss.getWidth()) {
            x = (int) (ss.getWidth() - child.getWidth());
        }
        if ((y + child.getHeight()) > ss.getHeight()) {
            y = (int) (ss.getHeight() - child.getHeight());
        }
        if (x < 0) {
            x = 0;
        }
        if (y < 0) {
            y = 0;
        }
    }
    child.setLocation(x, y);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 45 with Toolkit

use of java.awt.Toolkit in project binnavi by google.

the class GuiHelper method centerChildToParent.

/**
 * Centers the child component relative to its parent component.
 */
public static final void centerChildToParent(final Component parent, final Component child, final boolean bStayOnScreen) {
    int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
    int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
    if (bStayOnScreen) {
        final Toolkit tk = Toolkit.getDefaultToolkit();
        final Dimension ss = new Dimension(tk.getScreenSize());
        if ((x + child.getWidth()) > ss.getWidth()) {
            x = (int) (ss.getWidth() - child.getWidth());
        }
        if ((y + child.getHeight()) > ss.getHeight()) {
            y = (int) (ss.getHeight() - child.getHeight());
        }
        if (x < 0) {
            x = 0;
        }
        if (y < 0) {
            y = 0;
        }
    }
    child.setLocation(x, y);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Point(java.awt.Point)

Aggregations

Toolkit (java.awt.Toolkit)93 Dimension (java.awt.Dimension)27 Point (java.awt.Point)20 Image (java.awt.Image)19 BufferedImage (java.awt.image.BufferedImage)14 URL (java.net.URL)14 GraphicsDevice (java.awt.GraphicsDevice)8 GraphicsEnvironment (java.awt.GraphicsEnvironment)7 Insets (java.awt.Insets)7 Rectangle (java.awt.Rectangle)6 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 MediaTracker (java.awt.MediaTracker)5 ImageIcon (javax.swing.ImageIcon)5 Frame (java.awt.Frame)4 Clipboard (java.awt.datatransfer.Clipboard)4 Font (java.awt.Font)3 Graphics (java.awt.Graphics)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)3 Method (java.lang.reflect.Method)3