Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

In this page you can find the example usage for java.awt Toolkit getDefaultToolkit.

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:Main.java

public static void setCenter(Component component, Component component1) {
    Point point;// w ww. j  av a 2s .c om
    Dimension dimension;
    if (component != null) {
        point = component.getLocation();
        dimension = component.getSize();
    } else {
        dimension = Toolkit.getDefaultToolkit().getScreenSize();
        point = new Point(0, 0);
    }
    Dimension dimension1 = Toolkit.getDefaultToolkit().getScreenSize();
    point.setLocation((double) point.x + dimension.getWidth() / 2D,
            (double) point.y + dimension.getHeight() / 2D);
    Point point1 = new Point(point.x - component1.getWidth() / 2, point.y - component1.getHeight() / 2);
    if (point1.y < 0)
        point1.y = 0;
    if (point1.x < 0)
        point1.y = 0;
    if (point1.x + component1.getWidth() > dimension1.width)
        point1.x = dimension1.width - component1.getWidth();
    if (point1.y + component1.getHeight() > dimension1.height)
        point1.y = dimension1.height - component1.getHeight();
    component1.setLocation(point1);
}

From source file:MyCanvas.java

public void paint(Graphics g) {
    Image img1 = Toolkit.getDefaultToolkit().getImage("yourFile.gif");

    int width = img1.getWidth(this);
    int height = img1.getHeight(this);

    int scale = 2;
    int w = scale * width;
    int h = scale * height;
    // explicitly specify width (w) and height (h)
    g.drawImage(img1, 10, 10, (int) w, (int) h, this);

}

From source file:Main.java

/**
 * @return the windowYCenter/* w ww . jav a2 s. c o  m*/
 */
public static int getWindowYCenter() {
    if (windowYCenter == -1) {
        windowYCenter = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2;
    }
    return windowYCenter;
}

From source file:Main.java

public static void setClipboard(String text) {
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), clipboardOwner);
}

From source file:Main.java

public static void centerFrameOnScreen(JFrame frame) {

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//  w  w w  . j  a va 2  s  .c  o  m
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    Point p = new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    frame.setLocation(p);
}

From source file:ButtonListener.java

public void actionPerformed(ActionEvent ae) {
    Toolkit.getDefaultToolkit().beep();

}

From source file:Main.java

/**
 * Gets the window actual size.//from   w  ww .  j a  va2s . co m
 *
 * @param window
 *            the window
 * @return the window actual size
 */
public static Dimension getWindowActualSize(final Window window) {
    if (window.isVisible()) {
        return window.getSize();
    }
    if (window instanceof Frame) {
        final Frame frame = (Frame) window;
        if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
            return Toolkit.getDefaultToolkit().getScreenSize();
        }
    }
    return window.getSize();
}

From source file:MyCanvas.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Image img1 = Toolkit.getDefaultToolkit().getImage("yourFile.gif");
    g2.drawImage(img1, 10, 10, this);
    g2.finalize();//from w  w w .j a v a2s  .  c  o  m
}

From source file:Main.java

public void componentMoved(ComponentEvent evt) {
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    int x = evt.getComponent().getX();
    int y = evt.getComponent().getY();
    if (y < 0) {
        y = 0;/*  w ww .j  a  va  2 s  . c  o m*/
    }
    if (x < 0) {
        x = 0;
    }
    if (x > size.getWidth() - evt.getComponent().getWidth()) {
        x = (int) size.getWidth() - evt.getComponent().getWidth();
    }
    if (y > size.getHeight() - evt.getComponent().getHeight()) {
        y = (int) size.getHeight() - evt.getComponent().getHeight();
    }
    evt.getComponent().setLocation(x, y);
}

From source file:Main.java

public static void setPreferredGeometry(JFrame frame) {

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension frameSize = frame.getPreferredSize();
    Dimension screenSize = tk.getScreenSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//w w  w  .  j  av a2  s  . co  m

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    Point p = new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    Rectangle rect = new Rectangle(p, frameSize);
    frame.setBounds(rect);
}