List of usage examples for java.lang Runnable Runnable
Runnable
From source file:TwoObjects.java
public static void main(String[] args) { final TwoObjects obj1 = new TwoObjects("obj1"); final TwoObjects obj2 = new TwoObjects("obj2"); Runnable runA = new Runnable() { public void run() { obj1.synchronizedMethod(3);//from www . j a v a 2 s . co m } }; Thread threadA = new Thread(runA, "threadA"); threadA.start(); try { Thread.sleep(200); } catch (InterruptedException x) { } Runnable runB = new Runnable() { public void run() { obj2.synchronizedMethod(7); } }; Thread threadB = new Thread(runB, "threadB"); threadB.start(); }
From source file:MainClass.java
public static void main(String args[]) { final MainClass it = new MainClass(); JFrame frame = new JFrame("Progress Bar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(it);/*ww w .j ava2 s . co m*/ frame.pack(); frame.setVisible(true); for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) { final int percent = i; try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { it.updateBar(percent); } }); java.lang.Thread.sleep(100); } catch (Exception e) { ; } } }
From source file:SimpleFrameTest.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { SimpleFrame frame = new SimpleFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);//from w ww . j a v a 2 s . co m } }); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL urlImage1 = new URL("http://www.java2s.com/style/download.png"); final Image fgImage = ImageIO.read(urlImage1); int w = fgImage.getWidth(null); int h = fgImage.getHeight(null); final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = finalImage.createGraphics(); g.drawImage(bgImage, 0, 0, null);// w ww . j ava2s . com g.drawImage(fgImage, 0, 0, null); g.dispose(); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5)); gui.add(new JLabel(new ImageIcon(bgImage))); gui.add(new JLabel(new ImageIcon(fgImage))); gui.add(new JLabel(new ImageIcon(finalImage))); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] arguments) { JPanel panel = new JPanel(new BorderLayout()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel);//from w w w . j ava 2 s . c o m frame.setBounds(20, 20, 200, 200); frame.setVisible(true); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setVisible(false); JButton loadButton = new JButton("Load memberlist"); loadButton.setEnabled(true); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new Thread(new Runnable() { @Override public void run() { progressBar.setVisible(true); // do my stuff here... try { Thread.sleep(2000); } catch (Exception e) { e.printStackTrace(); } progressBar.setVisible(false); } }).start(); } }); JPanel container = new JPanel(new FlowLayout()); container.add(loadButton); container.add(progressBar); panel.add(container); }
From source file:Main.java
public static void main(String[] args) throws AWTException { Runnable r = new Runnable() { @Override// w ww.jav a 2s . c o m public void run() { try { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage bi = ImageIO.read(url); JPanel gui = new JPanel(new GridLayout(1, 2, 2, 2)); gui.add(new JLabel(new ImageIcon(bi))); gui.add(new JLabel(new ImageIcon(getFlippedImage(bi)))); JOptionPane.showMessageDialog(null, gui); } catch (Exception e) { e.printStackTrace(); } } }; SwingUtilities.invokeLater(r); }
From source file:SizedFrameTest.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { SizedFrame frame = new SizedFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);//w ww . j av a 2 s . c o m } }); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); JTextPane pane = new JTextPane(doc); final Style heading2Style = sc.addStyle("Heading2", null); heading2Style.addAttribute(StyleConstants.Foreground, Color.red); heading2Style.addAttribute(StyleConstants.FontSize, new Integer(16)); heading2Style.addAttribute(StyleConstants.FontFamily, "serif"); heading2Style.addAttribute(StyleConstants.Bold, new Boolean(true)); try {/* ww w . ja va 2 s .co m*/ SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { doc.insertString(0, text, null); doc.setParagraphAttributes(0, 1, heading2Style, false); } catch (BadLocationException e) { } } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:NotHelloWorld.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { NotHelloWorldFrame frame = new NotHelloWorldFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);/*from w w w . j ava2s. co m*/ } }); }
From source file:Main.java
public static void main(String[] args) { int maximum = 100; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Integer[] oneRow = { 0, 0, 0, 0 }; String[] headers = { "A", "B", "C", "D" }; Integer[][] data = { oneRow, oneRow, oneRow, oneRow, oneRow, }; DefaultTableModel model = new DefaultTableModel(data, headers); JTable table = new JTable(model); table.setDefaultRenderer(Object.class, new ProgressRenderer(0, maximum)); table.setPreferredScrollableViewportSize(table.getPreferredSize()); frame.add(new JScrollPane(table)); frame.pack();/* w ww. j a va 2 s . c o m*/ frame.setVisible(true); new Thread(new Runnable() { @Override public void run() { Object waiter = new Object(); synchronized (waiter) { int rows = model.getRowCount(); int columns = model.getColumnCount(); Random random = new Random(System.currentTimeMillis()); boolean done = false; while (!done) { int row = random.nextInt(rows); int column = random.nextInt(columns); Integer value = (Integer) model.getValueAt(row, column); value++; if (value <= maximum) { model.setValueAt(value, row, column); try { waiter.wait(15); } catch (InterruptedException e) { e.printStackTrace(); } } done = true; for (row = 0; row < rows; row++) { for (column = 0; column < columns; column++) { if (!model.getValueAt(row, column).equals(maximum)) { done = false; break; } } if (!done) { break; } } } } } }).start(); }