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

ContentPanel() {
    MediaTracker mt = new MediaTracker(this);
    bgimage = Toolkit.getDefaultToolkit().getImage("a.jpg");
    mt.addImage(bgimage, 0);//from w ww  .ja  va 2s . com
    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:SwingResourceManager.java

/**
 * Returns an image encoded by the specified input stream
 * @param is InputStream The input stream encoding the image data
 * @return Image The image encoded by the specified input stream
 *///from w w  w  .  j  a  v  a  2s .  c o m
private static Image getImage(InputStream is) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte buf[] = new byte[1024 * 4];
        while (true) {
            int n = is.read(buf);
            if (n == -1)
                break;
            baos.write(buf, 0, n);
        }
        baos.close();
        return Toolkit.getDefaultToolkit().createImage(baos.toByteArray());
    } catch (Throwable e) {
        return null;
    }
}

From source file:Main.java

/**
 * Returns system shortcut modifier./*  w ww  . jav  a 2  s.  co m*/
 *
 * @return system shortcut modifier
 */
public static int getSystemShortcutModifier() {
    if (systemShortcutModifier == null) {
        systemShortcutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    }
    return systemShortcutModifier;
}

From source file:Main.java

public static void centerFrame(Window frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    size.height = size.height / 2;/*from  w w w  .  ja va 2 s  .com*/
    size.width = size.width / 2;
    int y = screenSize.height - size.height;
    int x = screenSize.width - size.width;

    frame.setLocation(x, y);
}

From source file:Main.java

public Main() {
    int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    KeyStroke exitKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, MASK);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    JMenu fileMenu = new JMenu("File");
    JMenuItem fileExit = new JMenuItem(exitAction);
    fileMenu.add(fileExit);//from  w  w w .j av  a 2s  . c  o  m
    JMenuBar menu = new JMenuBar();
    menu.add(fileMenu);

    JDialog d = new JDialog(this, "Dialog");
    JPanel p = new JPanel();
    p.getInputMap().put(exitKey, exitName);
    p.getActionMap().put(exitName, exitAction);
    p.add(new JButton(exitAction));
    d.add(p);
    d.pack();
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    this.setJMenuBar(menu);
    this.pack();
    this.setSize(new Dimension(320, 240));
    this.setVisible(true);
    d.setLocation(this.getRootPane().getContentPane().getLocationOnScreen());
    d.setVisible(true);
}

From source file:Main.java

/**
 * Center window on screen./*from ww w.  ja  v a  2 s  .c  o  m*/
 *
 * @param window    window to be centered.
 * @param packFrame if <code>true</code> call window's <code>pack()</code>
 *                  method before centering.
 */
public static void centerOnScreen(Window window, boolean packFrame) {
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame) {
        window.pack();
    } else {
        window.validate();
    }

    //Center the frame window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();

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

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

    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:PrintSampleApp.java

public PrintSampleApp() {
    add("Center", canvas);
    setSize(500, 500);//from ww w  .  ja  v  a2s  . c o m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    String name = "Test print job";
    Properties properties = new Properties();
    PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(PrintSampleApp.this, name, properties);
    if (pj != null) {
        canvas.printAll(pj.getGraphics());
        pj.end();
    }
}

From source file:AppPackage.HumidityGraph.java

/**
 *
 *///w  ww. j a  va  2s.  c o  m
public HumidityGraph() {
    try {

        JFrame window = new JFrame();
        window.setSize(1000, 615);
        window.setBackground(Color.blue);

        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((dimension.getWidth() - window.getWidth()) / 2);
        int y = (int) ((dimension.getHeight() - window.getHeight()) / 2);
        window.setLocation(x, y);

        XYSeries series = new XYSeries("Humidity ");
        XYSeriesCollection dataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createXYLineChart("Humidity against Time", "Time(seconds)",
                "Humidity(percentage)", dataset);
        window.add(new ChartPanel(chart), BorderLayout.CENTER);
        window.setVisible(true);

    } catch (Exception e) {
        System.out.print("Chart exception:" + e);
    }
    initComponents();
}

From source file:Main.java

public Main() {
    image = Toolkit.getDefaultToolkit().getImage("A.jpg");
    theta = 0;/* ww  w  .ja  va2 s .co m*/
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            theta = (theta + 15) % 360;
            repaint();
        }
    });
}

From source file:Main.java

public ImagePanel() {
    image = Toolkit.getDefaultToolkit().createImage("e:/java/spin.gif");
}