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

public static void main(String[] args) {
    try {//from   w  w w.jav a2  s.  c  o m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new JFrame("Styles Example 7");

    // Create the StyleContext, the document and the pane
    final StyleContext sc = new StyleContext();
    final DefaultStyledDocument doc = new DefaultStyledDocument(sc);
    final JTextPane pane = new JTextPane(doc);

    // Build the styles
    createDocumentStyles(sc);

    try {
        // Add the text and apply the styles
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                // Add the text
                addText(pane, sc, sc.getStyle(mainStyleName), content);
            }
        });
    } 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:com.boxupp.init.Boxupp.java

public static void main(String[] args) throws Exception {
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();//from w ww . j  a va2s. c om

    Utilities.getInstance().createRequiredFoldersIfNotExists();
    ToolConfigurationReader toolConfig = new ToolConfigurationReader();
    Config conf = toolConfig.getConfiguration();
    AppContextBuilder appContextBuilder = new AppContextBuilder();
    DBConnectionManager connectionManager = DBConnectionManager.getInstance();
    if (connectionManager != null) {
        connectionManager.checkForProviderEntries();
    }

    String jettyPort = conf.getSetting().getPortNumber();

    final JettyServer jettyServer;
    jettyServer = (jettyPort != null) ? new JettyServer(Integer.parseInt(jettyPort)) : new JettyServer();

    HandlerCollection contexts = new HandlerCollection();

    HandlerList list = new HandlerList();
    WebSocketHandler wsHandler = new WebSocketHandler() {
        @Override
        public void configure(WebSocketServletFactory webSocketServletFactory) {
            webSocketServletFactory.register(VagrantConsole.class);
        }
    };
    ContextHandler handler = new ContextHandler();
    handler.setHandler(wsHandler);
    handler.setContextPath("/vagrantConsole/");

    list.setHandlers(new Handler[] { appContextBuilder.getStaticResourceHandler(),
            appContextBuilder.getWebAppHandler(), wsHandler });

    contexts.setHandlers(new Handler[] { list });

    jettyServer.setHandler(contexts);
    Runnable runner = new Runnable() {
        @Override
        public void run() {
            try {
                jettyServer.start();
            } catch (Exception e) {
            }
        }
    };
    EventQueue.invokeLater(runner);
    System.out.println("Boxupp Server is up at \"http://localhost:" + jettyPort);
}

From source file:example.ReceiveNumbers.java

/**
 * @param args//from  ww w. j  av a2 s  .c  om
 * @throws MalformedURLException
 * @throws JSONException
 */
public static void main(String[] args) throws MalformedURLException, JSONException {
    // TODO Auto-generated method stub

    JSONObject previousSub = new JSONObject(
            "{'id':'test-java-666','desc':'test-java-666', 'subkey':'GPS-71454020-queu'}");

    MyAEONCallbacks myCallBack = new MyAEONCallbacks();
    final AEONSDK sdk = new AEONSDK(Config.SUB_URL, Config.YOUR_ID, Config.YOUR_DESC);
    //final AEONSDK sdk = new AEONSDK(Config.SUB_URL, previousSub);
    JSONObject subscription = sdk.subscribe(myCallBack);

    if (subscription == null) {
        System.out.println("Something went wrong I dont have a subscription");
        return;
    }
    System.out.println("subscription received " + subscription.toString());

    try {
        TimeUnit.SECONDS.sleep(3);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    /*   
          sdk.deleteSubscription();
                  
          System.out.println("Deleted subscription: if some one is publish in the channel you will lost it for ever.");
                  
          try {
             TimeUnit.SECONDS.sleep(3);
          } catch (InterruptedException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }
                  
          System.out.println("Ok, lets have another new subscription.");
                  
          subscription = sdk.subscribe(myCallBack);      */

    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
    exec.scheduleAtFixedRate(new Runnable() {
        boolean paused = false;

        @Override
        public void run() {

            System.out.println("Ok lets make a little break of 5 seconds. After that the subscription"
                    + " will continue. And messages published while our break will be delivered inmediatly");
            if (!paused) {
                sdk.pauseSusbscription();
                paused = true;
            } else {
                sdk.continueSubscription();
                paused = false;
            }

        }
    }, 1, 5, TimeUnit.SECONDS);

}

From source file:ListProperties.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("List Properties");

    final CustomTableModel model = new CustomTableModel();
    model.uiDefaultsUpdate(UIManager.getDefaults());
    TableSorter sorter = new TableSorter(model);

    JTable table = new JTable(sorter);
    TableHeaderSorter.install(sorter, table);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final String lafClassName = actionEvent.getActionCommand();
            Runnable runnable = new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel(lafClassName);
                        SwingUtilities.updateComponentTreeUI(frame);
                        // Added
                        model.uiDefaultsUpdate(UIManager.getDefaults());
                    } catch (Exception exception) {
                        JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                                JOptionPane.ERROR_MESSAGE);
                    }//from   w ww  .  ja v a2 s .  co  m
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    };

    JToolBar toolbar = new JToolBar();
    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        toolbar.add(button);
    }

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:svacee.form.Grafico.java

/**
 * @param args the command line arguments
 *//*from   ww  w  . java  2 s.co  m*/
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(TabelaDados.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(TabelaDados.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(TabelaDados.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(TabelaDados.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            //new TabelaDados().setVisible(true);

        }
    });
}

From source file:io.alicorn.device.client.DeviceClient.java

public static void main(String[] args) {
    logger.info("Starting Alicorn Client System");

    // Prepare Display Color.
    transform3xWrite(DisplayTools.commandForColor(0, 204, 255));

    // Setup text information.
    //        transform3xWrite(DisplayTools.commandForText("Sup Fam"));

    class StringWrapper {
        public String string = "";
    }// www  . j a v  a 2 s . c o m
    final StringWrapper string = new StringWrapper();

    // Text Handler.
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            String latestString = "";
            String outputStringLine1Complete = "";
            long outputStringLine1Cursor = 1;
            int outputStringLine1Mask = 0;
            String outputStringLine2 = "";

            while (true) {
                if (!latestString.equals(string.string)) {
                    latestString = string.string;
                    String[] latestStrings = latestString.split("::");
                    outputStringLine1Complete = latestStrings[0];
                    outputStringLine1Mask = outputStringLine1Complete.length();
                    outputStringLine1Cursor = 0;

                    // Trim second line to a length of sixteen.
                    outputStringLine2 = latestStrings.length > 1 ? latestStrings[1] : "";
                    if (outputStringLine2.length() > 16) {
                        outputStringLine2 = outputStringLine2.substring(0, 16);
                    }
                }

                StringBuilder outputStringLine1 = new StringBuilder();
                if (outputStringLine1Complete.length() > 0) {
                    long cursor = outputStringLine1Cursor;
                    for (int i = 0; i < 16; i++) {
                        outputStringLine1.append(
                                outputStringLine1Complete.charAt((int) (cursor % outputStringLine1Mask)));
                        cursor += 1;
                    }
                    outputStringLine1Cursor += 1;
                } else {
                    outputStringLine1.append("                ");
                }

                try {
                    transform3xWrite(
                            DisplayTools.commandForText(outputStringLine1.toString() + outputStringLine2));
                    Thread.sleep(400);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
    thread.start();

    // Event Handler
    while (true) {
        try {
            String url = "http://169.254.90.174:9789/api/iot/narwhalText";
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet(url);
            HttpResponse response = client.execute(request);
            string.string = apacheHttpEntityToString(response.getEntity());

            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.sjsu.uidesign.iScheduleFrame.java

/**
 * @param args the command line arguments
 *///  w w w .  j  ava2s  . c o  m
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(iScheduleFrame.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(iScheduleFrame.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(iScheduleFrame.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(iScheduleFrame.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new iScheduleFrame().setVisible(true);
        }
    });
}

From source file:gtu._work.etc._3DSMovieRenamer.java

/**
 * Auto-generated main method to display this JFrame
 *//*from w ww.j ava  2s . c  o  m*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            _3DSMovieRenamer inst = new _3DSMovieRenamer();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:misc.GradientTranslucentWindowDemo.java

public static void main(String[] args) {
    // Determine what the GraphicsDevice can support.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    boolean isPerPixelTranslucencySupported = gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);

    //If translucent windows aren't supported, exit.
    if (!isPerPixelTranslucencySupported) {
        System.out.println("Per-pixel translucency is not supported");
        System.exit(0);/*from  w  w  w  .j  ava 2 s. co m*/
    }

    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create the GUI on the event-dispatching thread
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            GradientTranslucentWindowDemo gtw = new GradientTranslucentWindowDemo();

            // Display the window.
            gtw.setVisible(true);
        }
    });
}

From source file:DefaultsDisplay.java

public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame("UIDefaults Display");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new DefaultsDisplay());
            frame.pack();/*from   w  w w  . j  av  a2s.  c  o  m*/
            frame.setVisible(true);
        }
    });
}