Example usage for java.lang Runnable Runnable

List of usage examples for java.lang Runnable Runnable

Introduction

In this page you can find the example usage for java.lang Runnable Runnable.

Prototype

Runnable

Source Link

Usage

From source file:Main.java

public static void main(String args[]) {
    JPanel JMainPanel = new JPanel(new BorderLayout());
    JPanel jp = new JPanel();
    JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" });
    JPanel jImage = new JPanel();
    JFrame jf = new JFrame();

    jp.add(combo);/*from w ww  .ja v  a2  s. com*/
    JMainPanel.add(jp, BorderLayout.WEST);
    JMainPanel.add(jImage, BorderLayout.CENTER);
    jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK), "screenshot");
    jp.getActionMap().put("screenshot", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jf.getRootPane().paint(bf.getGraphics());
                    jImage.getGraphics().drawImage(bf, 0, 0, jImage);
                }
            });
        }
    });
    jf.getContentPane().add(JMainPanel);
    jf.setSize(500, 500);
    jf.setVisible(true);
}

From source file:CircleLayoutTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            CircleLayoutFrame frame = new CircleLayoutFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);//ww  w. jav a  2  s .  com
        }
    });
}

From source file:RadioButtonTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            RadioButtonFrame frame = new RadioButtonFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);//from w  w  w.  j a v a2  s  .co  m
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setOpaque(true);/*  w  ww  . j  a  v a  2  s . c  o  m*/
    p.setLayout(new FlowLayout());
    p.add(good);

    f.add(p, BorderLayout.CENTER);
    f.add(resultLabel, BorderLayout.SOUTH);
    good.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            good.setEnabled(false);
            Thread worker = new Thread() {
                public void run() {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            resultLabel.setText("Ready");
                            good.setEnabled(true);
                        }
                    });
                }
            };
            worker.start(); // So we don't hold up the dispatch thread.
        }
    });
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:RasterImageTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new RasterImageFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);//from www.j  av  a 2 s . c om
        }
    });
}

From source file:BorderTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            BorderFrame frame = new BorderFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);//from w  w  w.j  av  a 2  s.c  o  m
        }
    });
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 57");
    final ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH);
    Rectangle clientArea = shell.getClientArea();
    bar.setBounds(clientArea.x, clientArea.y, 200, 32);
    shell.open();//from   www.  j  a  va  2 s . com

    display.timerExec(100, new Runnable() {
        int i = 0;

        @Override
        public void run() {
            if (bar.isDisposed())
                return;
            bar.setSelection(i++);
            if (i <= bar.getMaximum())
                display.timerExec(100, this);
        }
    });

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

From source file:SwingProgressBarExample.java

public static void main(String args[]) {

    final SwingProgressBarExample it = new SwingProgressBarExample();

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(it);//  w  ww . j  a v a2 s .c  om
    frame.pack();
    frame.setVisible(true);

    for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    it.updateBar(percent);
                }
            });
            java.lang.Thread.sleep(100);
        } catch (InterruptedException e) {
            ;
        }
    }
}

From source file:ImageViewer.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new ImageViewerFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);//from w  w  w . j  a  v a  2  s .  c  o  m
        }
    });
}

From source file:ImageLoader.java

public static void main(String... args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new ImageLoader().setVisible(true);
        }//from   ww w . j  a v  a2 s  .co m
    });
}