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:misc.TranslucentWindowDemo.java

public static void main(String[] args) {
    // Determine if the GraphicsDevice supports translucency.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();

    //If translucent windows aren't supported, exit.
    if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) {
        System.err.println("Translucency is not supported");
        System.exit(0);//  w  ww  .  j av  a2 s. co  m
    }

    JFrame.setDefaultLookAndFeelDecorated(true);

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

            // Set the window to 55% opaque (45% translucent).
            tw.setOpacity(0.55f);

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

From source file:gtu._work.ui.SaveFileToPropertiesUI.java

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

From source file:misc.TrayIconDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {/* w  w w  .ja  va2 s . c  o  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    /* Turn off metal's use of bold fonts */
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    //Schedule a job for the event-dispatching thread:
    //adding TrayIcon.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java

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

From source file:edu.mit.fss.tutorial.part4.ElementGUI.java

/**
 * The main method./*from  ww  w .  ja  va 2  s.  c om*/
 *
 * @param args the arguments
 * @throws RTIexception the RTI exception
 */
public static void main(String[] args) throws RTIexception {
    // Configure the logger and set it to display info messages.
    BasicConfigurator.configure();
    logger.setLevel(Level.INFO);

    // Use an input dialog to request the element's name.
    String name = null;
    while (name == null || name.isEmpty()) {
        name = JOptionPane.showInputDialog("Enter element name:");
    }

    // Create a MobileElement object instance. The "final" keyword allows 
    // it to be referenced in the GUI thread below.
    final MobileElement element = new MobileElement(name, new Vector3D(0, 0, 0));

    // Create an OnlineTutorialFederate object instance. The "final" 
    // keyword allows it to be referenced in the GUI thread below.
    final OnlineTutorialFederate fed = new OnlineTutorialFederate(element);

    // Create the graphical user interface using the Event Dispatch Thread.
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                // Create a new ControlPanel object instance.
                ControlPanel controlPanel = new ControlPanel();

                // Bind it to the element above.
                controlPanel.setBoundElement(element);

                // Add the control panel as an object change listener.
                fed.addObjectChangeListener(controlPanel);

                // Create a new frame to display the panel. Add the panel
                // as the content, pack it, and make it visible.
                JFrame frame = new JFrame();
                frame.setContentPane(controlPanel);
                frame.pack();
                frame.setVisible(true);

                // Add a new WindowAdapter object instance to exit the
                // federate when the window is closing.
                frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                        fed.exit();
                    }
                });
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        logger.error(e);
    }

    // Execute the federate.
    fed.execute(0, Long.MAX_VALUE, 1000);
}

From source file:PinotThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    final int numQueries = QUERIES.length;
    final Random random = new Random(RANDOM_SEED);
    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS);

    for (int i = 0; i < NUM_CLIENTS; i++) {
        executorService.submit(new Runnable() {
            @Override//from w  w w . j a  va  2 s. co m
            public void run() {
                try (CloseableHttpClient client = HttpClients.createDefault()) {
                    HttpPost post = new HttpPost("http://localhost:8099/query");
                    CloseableHttpResponse res;
                    while (true) {
                        String query = QUERIES[random.nextInt(numQueries)];
                        post.setEntity(new StringEntity("{\"pql\":\"" + query + "\"}"));
                        long start = System.currentTimeMillis();
                        res = client.execute(post);
                        res.close();
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(System.currentTimeMillis() - start);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    long startTime = System.currentTimeMillis();
    while (true) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:gtu._work.ui.RegexCatchReplacer.java

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

From source file:gtu._work.ui.CheckJavaClassPathUI.java

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

From source file:gtu._work.ui.EstoreCodeGenerateUI.java

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

From source file:com.mebigfatguy.roomstore.RoomStore.java

public static void main(String[] args) {
    Options options = createOptions();/*  w  ww  .ja va2  s  .  com*/

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmdLine = parser.parse(options, args);
        String nickname = cmdLine.getOptionValue(NICK_NAME);
        String server = cmdLine.getOptionValue(IRCSERVER);
        String[] channels = cmdLine.getOptionValues(CHANNELS);
        String[] endPoints = cmdLine.getOptionValues(ENDPOINTS);
        String rf = cmdLine.getOptionValue(RF);

        if ((endPoints == null) || (endPoints.length == 0)) {
            endPoints = new String[] { "127.0.0.1" };
        }

        int replicationFactor;
        try {
            replicationFactor = Integer.parseInt(rf);
        } catch (Exception e) {
            replicationFactor = 1;
        }

        final IRCConnector connector = new IRCConnector(nickname, server, channels);

        Cluster cluster = new Cluster.Builder().addContactPoints(endPoints).build();
        final Session session = cluster.connect();

        CassandraWriter writer = new CassandraWriter(session, replicationFactor);
        connector.setWriter(writer);

        connector.startRecording();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                connector.stopRecording();
                session.close();
            }
        }));

    } catch (ParseException pe) {
        System.out.println("Parse Error on command line options:");
        System.out.println(commandLineRepresentation(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("roomstore", options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}