List of usage examples for java.lang Runnable Runnable
Runnable
From source file:misc.ModalityDemo.java
public static void main(String[] args) { /* Use an appropriate Look and Feel */ try {//w w w . j a v a 2s . c om //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: //creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { ModalityDemo md = new ModalityDemo(); md.createAndShowGUI(); md.start(); } }); }
From source file:accumulo.AccumuloStuff.java
public static void main(String[] args) throws Exception { File tmp = new File(System.getProperty("user.dir") + "/target/mac-test"); if (tmp.exists()) { FileUtils.deleteDirectory(tmp);/* w w w .j a va2s .c o m*/ } tmp.mkdirs(); String passwd = "password"; MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(tmp, passwd); cfg.setNumTservers(1); // cfg.useMiniDFS(true); final MiniAccumuloClusterImpl cluster = cfg.build(); setCoreSite(cluster); cluster.start(); ExecutorService svc = Executors.newFixedThreadPool(2); try { Connector conn = cluster.getConnector("root", passwd); String table = "table"; conn.tableOperations().create(table); final BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig()); final AtomicBoolean flushed = new AtomicBoolean(false); Runnable writer = new Runnable() { @Override public void run() { try { Mutation m = new Mutation("row"); m.put("colf", "colq", "value"); bw.addMutation(m); bw.flush(); flushed.set(true); } catch (Exception e) { log.error("Got exception trying to flush mutation", e); } log.info("Exiting batchwriter thread"); } }; Runnable restarter = new Runnable() { @Override public void run() { try { for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) { cluster.killProcess(ServerType.TABLET_SERVER, proc); } cluster.exec(TabletServer.class); } catch (Exception e) { log.error("Caught exception restarting tabletserver", e); } log.info("Exiting restart thread"); } }; svc.execute(writer); svc.execute(restarter); log.info("Waiting for shutdown"); svc.shutdown(); if (!svc.awaitTermination(120, TimeUnit.SECONDS)) { log.info("Timeout on shutdown exceeded"); svc.shutdownNow(); } else { log.info("Cleanly shutdown"); log.info("Threadpool is terminated? " + svc.isTerminated()); } if (flushed.get()) { log.info("****** BatchWriter was flushed *********"); } else { log.info("****** BatchWriter was NOT flushed *********"); } bw.close(); log.info("Got record {}", Iterables.getOnlyElement(conn.createScanner(table, Authorizations.EMPTY))); } finally { cluster.stop(); } }
From source file:TwoStopsGradient.java
public static void main(String... args) { try {/* w w w .j a v a 2 s . c om*/ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } SwingUtilities.invokeLater(new Runnable() { public void run() { new TwoStopsGradient().setVisible(true); } }); }
From source file:com.yosanai.java.swing.config.ConfigDialogTest.java
/** * @param args/*from w ww. jav a 2s. com*/ * the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { ConfigDialogTest frame = new ConfigDialogTest(); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.pack(); frame.setVisible(true); } }); }
From source file:inout.ChartFrame.java
/** * @param args the command line arguments *///from w ww. jav a 2 s. c om 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(ChartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ChartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ChartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ChartFrame.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 ChartFrame().setVisible(true); } }); }
From source file:business.management.system.TeamStatistics.java
/** * @param args the command line arguments *///from w w w .ja va 2 s.c om 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(TeamStatistics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(TeamStatistics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(TeamStatistics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(TeamStatistics.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() { try { new TeamStatistics().setVisible(true); } catch (SQLException ex) { Logger.getLogger(TeamStatistics.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:org.eclipse.swt.snippets.Snippet195.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true;// w ww. ja va 2s . co m final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setCurrent(); GL.createCapabilities(); canvas.addListener(SWT.Resize, event -> { Rectangle bounds = canvas.getBounds(); float fAspect = (float) bounds.width / (float) bounds.height; canvas.setCurrent(); GL.createCapabilities(); GL11.glViewport(0, 0, bounds.width, bounds.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float near = 0.5f; float bottom = -near * (float) Math.tan(45.f / 2); float left = fAspect * bottom; GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glClearDepth(1.0); GL11.glLineWidth(2); GL11.glEnable(GL11.GL_DEPTH_TEST); shell.setText("SWT/LWJGL Example"); shell.setSize(640, 480); shell.open(); final Runnable run = new Runnable() { int rot = 0; @Override public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); GL.createCapabilities(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.3f, .5f, .8f, 1.0f); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -10.0f); float frot = rot; GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f); GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f); rot++; GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); GL11.glColor3f(0.9f, 0.9f, 0.9f); drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15); canvas.swapBuffers(); display.asyncExec(this); } } }; canvas.addListener(SWT.Paint, event -> run.run()); display.asyncExec(run); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:gui.statistics.PieChartTest.java
/** * @param args the command line arguments *///from ww w . ja va 2 s . 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(PieChartTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PieChartTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PieChartTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PieChartTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { PieChartTest dialog = new PieChartTest(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); }
From source file:App.java
/** * Launch the application.// ww w . j a v a 2 s .c o m */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { App window = new App(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:io.s4.zeno.SiteTest.java
public static void main(String[] arg) throws JSONException, KeeperException, IOException, InterruptedException { PropertyConfigurator.configure("log4j.properties"); String name = arg[0];/*from www . j a v a 2s .com*/ String zkaddr = arg[1]; String zkbase = arg[2]; String specStr = arg[3]; ConfigMap spec = new JSONConfigMap(specStr); ZooKeeper zk = new ZooKeeper(zkaddr, 3000, zkhandler); zookeeper = new ZooKeeperHelper(zk, 5, 5000); zkpath = new ZKPaths(zkbase); ZooKeeperInfo zkinfo = new ZooKeeperInfo(); zkinfo.zookeeper = zookeeper; zkinfo.zkpath = zkpath; zkinfo.taskHolder = new NonblockingLockset(zookeeper, zkpath.taskBase); zkinfo.partsHolder = new NonblockingLockset(zookeeper, zkpath.partsBase); zkinfo.standbySequence = new DistributedSequence(zookeeper, zkpath.standbyBase); final Site site = new Site(name, spec); ZKCluster cluster = new ZKCluster(zookeeper, zkpath); ZKJobList jobList = new ZKJobList(site, zkinfo); ZKPartList partList = new ZKPartList(site, zkinfo); SiteInitializer init = new SiteInitializer(); site.setCluster(cluster); site.setJobList(jobList); site.setPartList(partList); site.setInitializer(init); class ZenoThreadGroup extends ThreadGroup { public ZenoThreadGroup() { super("ZenoThreadGroup"); } public void uncaughtException(Thread t, Throwable e) { System.out.println("ZENOTHREADGROUP CAUGHT AND EXCEPTION FROM THREAD " + t + ". SO EXITING. DETAILS:" + e + "\nCAUSED BY: " + e.getCause() + "\n"); e.printStackTrace(); System.exit(1); } } Thread t = new Thread(new ZenoThreadGroup(), new Runnable() { public void run() { site.start(); } }, "zenorunthread"); t.start(); System.out.println(); t.join(); }