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:FrameIcon.java

/** Demo main program, showing two ways to use it.
 * Create a small MemImage and set it as this Frame's iconImage. 
 * Also display a larger version of the same image in the Frame.
 *//*  w ww .ja  v a  2 s .  c  om*/
public static void main(String[] av) {
    Frame f = new Frame("FrameIcon");
    Image im = Toolkit.getDefaultToolkit().getImage("java2s.gif");
    f.setIconImage(im);
    f.setSize(100, 100);
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:org.eclipse.swt.snippets.Snippet361.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 361");
    shell.setText("Translate and Rotate an AWT Image in an SWT GUI");
    shell.setLayout(new GridLayout(8, false));

    Button fileButton = new Button(shell, SWT.PUSH);
    fileButton.setText("&Open Image File");
    fileButton.addSelectionListener(widgetSelectedAdapter(e -> {
        String filename = new FileDialog(shell).open();
        if (filename != null) {
            image = Toolkit.getDefaultToolkit().getImage(filename);
            canvas.repaint();/*w w  w  . j  a va2  s .co  m*/
        }
    }));

    new Label(shell, SWT.NONE).setText("Translate &X by:");
    final Combo translateXCombo = new Combo(shell, SWT.NONE);
    translateXCombo.setItems("0", "image width", "image height", "100", "200");
    translateXCombo.select(0);
    translateXCombo.addModifyListener(e -> {
        translateX = numericValue(translateXCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("Translate &Y by:");
    final Combo translateYCombo = new Combo(shell, SWT.NONE);
    translateYCombo.setItems("0", "image width", "image height", "100", "200");
    translateYCombo.select(0);
    translateYCombo.addModifyListener(e -> {
        translateY = numericValue(translateYCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("&Rotate by:");
    final Combo rotateCombo = new Combo(shell, SWT.NONE);
    rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8");
    rotateCombo.select(0);
    rotateCombo.addModifyListener(e -> {
        rotate = numericValue(rotateCombo);
        canvas.repaint();
    });

    Button printButton = new Button(shell, SWT.PUSH);
    printButton.setText("&Print Image");
    printButton.addSelectionListener(widgetSelectedAdapter(e -> {
        performPrintAction(display, shell);
    }));

    composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1);
    data.widthHint = 640;
    data.heightHint = 480;
    composite.setLayoutData(data);
    Frame frame = SWT_AWT.new_Frame(composite);
    canvas = new Canvas() {
        @Override
        public void paint(Graphics g) {
            if (image != null) {
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

                /* Use Java2D here to modify the image as desired. */
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform t = new AffineTransform();
                t.translate(translateX, translateY);
                t.rotate(rotate);
                g2d.setTransform(t);
                /*------------*/

                g.drawImage(image, 0, 0, this);
            }
        }
    };
    frame.add(canvas);
    composite.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "Image drawn in AWT Canvas";
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:groovesquid.Main.java

public static void main(String[] args) {

    System.setSecurityManager(null);

    log.log(Level.INFO, "Groovesquid v{0} running on {1} {2} ({3}) in {4}",
            new Object[] { version, System.getProperty("java.vm.name"),
                    System.getProperty("java.runtime.version"), System.getProperty("java.vm.vendor"),
                    System.getProperty("java.home") });

    // show gui/*from   w  ww . ja v  a 2 s .  c  om*/

    // apple os x
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Groovesquid");
    // antialising
    System.setProperty("awt.useSystemAAFontSettings", "lcd");
    System.setProperty("swing.aatext", "true");
    // flackering bg fix
    System.setProperty("sun.awt.noerasebackground", "true");
    System.setProperty("sun.java2d.noddraw", "true");
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    try {
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        log.log(Level.SEVERE, null, ex);
    }

    // load languages
    languages = loadLanguages();

    // Load config
    config = loadConfig();

    // GUI
    try {
        gui = (GUI) config.getGuiClass().newInstance();
    } catch (InstantiationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    settings = new Settings();
    about = new About();

    // Update Checker
    new UpdateCheckThread().start();

    // init grooveshark (every 25min)
    new InitThread().start();

}

From source file:Main.java

public static void main(String[] a) {
    final JFrame jf = new JFrame("JIFrameDemo Main Window");

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.width -= 42;/* w  w  w  .  ja  va2s .c o m*/
    screenSize.height -= 42;
    jf.setSize(screenSize);
    jf.setLocation(20, 20);

    JMenuBar mb = new JMenuBar();
    jf.setJMenuBar(mb);
    JMenu fm = new JMenu("File");
    mb.add(fm);
    JMenuItem mi;
    fm.add(mi = new JMenuItem("Exit"));
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    JDesktopPane dtp = new JDesktopPane();
    //dtp.setBackground(Color.GREEN);
    jf.setContentPane(dtp);

    JInternalFrame mboxFrame = new JInternalFrame("Mail Reader", true, true, true, true);
    JLabel reader = new JLabel("Mail Reader Would Be Here");
    mboxFrame.setContentPane(reader);
    mboxFrame.setSize(400, 300);
    mboxFrame.setLocation(50, 50);
    mboxFrame.setVisible(true);
    dtp.add(mboxFrame);

    JInternalFrame compFrame = new JInternalFrame("Compose Mail", true, true, true, true);
    JLabel composer = new JLabel("Mail Compose Would Be Here");
    compFrame.setContentPane(composer);
    compFrame.setSize(300, 200);
    compFrame.setLocation(200, 200);
    compFrame.setVisible(true);
    dtp.add(compFrame);

    JInternalFrame listFrame = new JInternalFrame("Users", true, true, true, true);
    JLabel list = new JLabel("List of Users Would Be Here");
    listFrame.setContentPane(list);
    listFrame.setLocation(400, 400);
    listFrame.setSize(500, 200);
    listFrame.setVisible(true);
    dtp.add(listFrame);

    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            jf.setVisible(false);
            jf.dispose();
            System.exit(0);
        }
    });
}

From source file:dbmods.InsertTemplateName.java

/**
* Auto-generated main method to display this JFrame
*//*from w  ww. j  a v a2 s  . c  o m*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            InsertTemplateName inst = new InsertTemplateName();
            inst.setLocationRelativeTo(null);
            inst.setTitle("Insert Into parse_template");
            Image icon = Toolkit.getDefaultToolkit().getImage("gf.png");
            inst.setIconImage(icon);
            inst.setVisible(true);
        }
    });
}

From source file:aurelienribon.texturepackergui.Main.java

public static void main(String[] args) {
    Parameters params = new Parameters(args);
    Project project = params.project;/*from  www  . j  a  va  2 s .  co m*/

    if (project == null) {
        String str = "";
        str += "input=" + params.input + "\n";
        str += "output=" + params.output + "\n";
        str += params.settings;
        project = Project.fromString(str);
    }

    if (params.silent) {
        if (project.input.equals("") || project.output.equals("")) {
            System.err.println("Input and output directories have to be set");
        } else {
            try {
                project.pack();
            } catch (GdxRuntimeException ex) {
                System.err.println("Packing unsuccessful. " + ex.getMessage());
            }
        }
        return;
    }

    final Project prj = project;
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException ex) {
            } catch (InstantiationException ex) {
            } catch (IllegalAccessException ex) {
            } catch (UnsupportedLookAndFeelException ex) {
            }

            Canvas canvas = new Canvas();
            LwjglCanvas glCanvas = new LwjglCanvas(canvas, true);

            MainWindow mw = new MainWindow(prj, canvas, glCanvas.getCanvas());
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            mw.setSize(Math.min(1100, screenSize.width - 100), Math.min(670, screenSize.height - 100));
            mw.setLocationRelativeTo(null);
            mw.setVisible(true);
        }
    });
}

From source file:MouseDrag.java

public static void main(String[] av) {
    JFrame f = new JFrame("Mouse Dragger");
    Container cp = f.getContentPane();

    if (av.length < 1) {
        System.err.println("Usage: MouseDrag imagefile");
        System.exit(1);/*from  w  w w . j  a v a 2  s.  c o  m*/
    }
    Image im = Toolkit.getDefaultToolkit().getImage(av[0]);

    // create a MouseDrag object
    MouseDrag j = new MouseDrag(im);

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java"));
    cp.add(BorderLayout.CENTER, j);
    cp.add(BorderLayout.SOUTH, status = new Label());
    status.setSize(f.getSize().width, status.getSize().height);
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:MouseDragClip.java

public static void main(String[] av) {
    JFrame f = new JFrame("Mouse Dragger");
    Container cp = f.getContentPane();

    if (av.length < 1) {
        System.err.println("Usage: MouseDragClip imagefile");
        System.exit(1);/*from   w  w w.  ja  v  a 2s . c  o m*/
    }
    Image im = Toolkit.getDefaultToolkit().getImage(av[0]);

    // create a MouseDragClip object
    MouseDragClip j = new MouseDragClip(im);

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java"));
    cp.add(BorderLayout.CENTER, j);
    cp.add(BorderLayout.SOUTH, status = new Label());
    status.setSize(f.getSize().width, status.getSize().height);
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:net.redstonelamp.gui.RedstoneLampGUI.java

public static void main(String[] args) {
    JFrame frame = new JFrame("RedstoneLamp");
    frame.setLayout(new GridLayout(2, 1));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JLabel label = new JLabel("RedstoneLamp");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    frame.add(label);/*  ww  w .ja v  a  2  s.c om*/
    JPanel lowPanel = new JPanel();
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    lowPanel.add(left);
    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    lowPanel.add(right);
    JButton openButton = new JButton("Open server at...");
    openButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(new File("."));
        chooser.setDialogTitle("Select RedstoneLamp server home");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showOpenDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (!jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. "
                        + "Would you like to install RedstoneLamp there?");
                if (result == JOptionPane.YES_OPTION) {
                    installCallback(frame, selected);
                }
                return;
            }
            frame.dispose();
            addHistory(selected);
            currentRoot = new ServerActivity(selected);
        }
    });
    right.add(openButton);
    JButton installButton = new JButton("Install server at...");
    installButton.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(".");
        chooser.setDialogTitle("Select directory to install server in");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        int action = chooser.showSaveDialog(frame);
        if (action == JFileChooser.APPROVE_OPTION) {
            File selected = chooser.getSelectedFile();
            File jar = new File("RedstoneLamp.jar");
            if (jar.isFile()) {
                int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. "
                        + "Are you sure you want to reinstall RedstoneLamp there?");
                if (result == JOptionPane.NO_OPTION) {
                    frame.dispose();
                    addHistory(selected);
                    currentRoot = new ServerActivity(selected);
                    return;
                }
            }
            installCallback(frame, selected);
        }
    });
    frame.add(lowPanel);
    frame.pack();
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dimension.width / 2 - frame.getSize().width / 2,
            dimension.height / 2 - frame.getSize().height / 2);
    frame.setVisible(true);
}

From source file:QueueMonitor.java

/** Main program entry point. */
public static void main(String[] args) {
    // There should be no arguments to this program.
    if (args.length > 0) {
        printUsage();/*from   w w  w  . jav  a  2  s.  c  o  m*/
        System.exit(1);
    }

    QueueMonitor queueMonitor = new QueueMonitor();

    queueMonitor.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    queueMonitor.setSize(screenSize);
    queueMonitor.setVisible(true);

}