List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:org.uncommons.watchmaker.swing.evolutionmonitor.JVMView.java
JVMView() { super(new BorderLayout()); double maxMemory = (double) memoryBean.getHeapMemoryUsage().getMax() / MEGABYTE; ChartPanel heapPanel = new ChartPanel(createHeapChart(maxMemory), false, // Properties true, // Save true, // Print false, // Zoom true); // Tooltips heapPanel.setMouseZoomable(false);/*from w ww .jav a 2 s . c om*/ add(heapPanel, BorderLayout.CENTER); add(createControls(), BorderLayout.SOUTH); Timer timer = new Timer(5000, new ActionListener() { public void actionPerformed(ActionEvent e) { addMemoryDataPoint(); } }); // Plot start values. addMemoryDataPoint(); timer.start(); }
From source file:SplashScreen.java
/** * Open the splash screen and keep it open for the specified duration * or until close() is called explicitly. *//*from ww w. ja va 2s . co m*/ public void open(int nMilliseconds) { if (image_ == null) return; Timer timer = new Timer(Integer.MAX_VALUE, new ActionListener() { public void actionPerformed(ActionEvent event) { ((Timer) event.getSource()).stop(); close(); }; }); timer.setInitialDelay(nMilliseconds); timer.start(); setBounds(x_, y_, width_, height_); setVisible(true); }
From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java
protected DesktopToolTipManager() { closeTimer = new Timer(CLOSE_TIME, null); closeTimer.setRepeats(false);//from w ww . ja v a2 s .c om closeTimer.addActionListener(e -> { if (window != null) { window.hide(); window = null; tooltipShowing = false; toolTipWindow.removeMouseListener(DesktopToolTipManager.this); component.removeMouseListener(DesktopToolTipManager.this); } }); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { protected MouseEvent event; @Override public void eventDispatched(AWTEvent e) { if (!tooltipShowing) { return; } event = (MouseEvent) e; if (event.getID() == MouseEvent.MOUSE_PRESSED) { if (event.getComponent() != null && event.getComponent().isShowing()) { if (!isPointInComponent(event.getLocationOnScreen(), toolTipWindow)) hideTooltip(); } else hideTooltip(); } } }, AWTEvent.MOUSE_EVENT_MASK); }
From source file:com.view.PortfolioManagerWindow.java
/** * Creates new form MainJFrame// ww w . j a v a 2 s .co m */ public PortfolioManagerWindow() { super(); //The following line is for the exit confirmation addWindowListener(new AreYouSure()); initComponents(); //START TIMER TO UPDATE ORDERS Timer timer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ArrayList<SingleOrder> ordersDone = new ArrayList<>(); try { ordersDone = (ArrayList) CPMOrderMANIAC.updateOrders(); CPMEndOfDay.getEODData(); } catch (ExecutionException | InterruptedException | IOException | JSONException ex) { Logger.getLogger(PortfolioManagerWindow.class.getName()).log(Level.SEVERE, null, ex); } ArrayList<SingleOrder> ordersPending = new ArrayList<>(); ArrayList<SingleOrder> ordersExecuted = new ArrayList<>(); if (null != ordersDone) { for (int i = 0; i < ordersDone.size(); i++) { String currStatus = ordersDone.get(i).getStatus(); if (currStatus.equals("Pending")) { ordersPending.add(ordersDone.get(i)); } if (currStatus.equals("Executed")) { ordersExecuted.add(ordersDone.get(i)); } } CPMOrderMANIAC.setPendings(ordersPending); CPMOrderMANIAC.setExecuted(ordersExecuted); PMOrderHistoryTable.setModel(CPMOrderMANIAC.getOHTableModel()); PMPendingOrdersTable.setModel(CPMOrderMANIAC.getPRTableModel()); //System.out.println("ABOUT TO SET MODEL OF EOD TABLE"); PMEODBoughtTable.setModel(CPMEndOfDay.getBuyTableModel()); PMEODSoldTable.setModel(CPMEndOfDay.getSellTableModel()); } else { System.out.println("ERROR UPDATING ORDERS"); } } }); timer.start(); try { Thread.sleep(1000); } catch (InterruptedException e) { } timer.restart(); }
From source file:ProgressMonitorTest.java
public ProgressMonitorFrame() { setTitle("ProgressMonitorTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // this text area holds the activity output textArea = new JTextArea(); // set up a button panel JPanel panel = new JPanel(); startButton = new JButton("Start"); panel.add(startButton);/*ww w . j av a2s .c o m*/ add(new JScrollPane(textArea), BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); // set up the button action startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { startButton.setEnabled(false); final int MAX = 1000; // start activity activity = new SimulatedActivity(MAX); activity.execute(); // launch progress dialog progressDialog = new ProgressMonitor(ProgressMonitorFrame.this, "Waiting for Simulated Activity", null, 0, MAX); cancelMonitor.start(); } }); // set up the timer action cancelMonitor = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent event) { if (progressDialog.isCanceled()) { activity.cancel(true); startButton.setEnabled(true); } else if (activity.isDone()) { progressDialog.close(); startButton.setEnabled(true); } else { progressDialog.setProgress(activity.getProgress()); } } }); }
From source file:mainpackage.FrmXuatThongTin.java
public FrmXuatThongTin() throws XBeeException { initComponents();/*from w ww.j a va 2s.c om*/ zoomDistance = 15; txtaTestPacket.setEditable(false); masterNode = new MasterNode(); dateFormat = new SimpleDateFormat("EEE, dd-MM-yyyy"); timeFormat = new SimpleDateFormat("HH:mm:ss"); tblDatabase.setModel(masterNode.getModel().getTableModel()); cbbGraphSelection.setModel(masterNode.getModel().getComboBoxModel()); AddDataForGraph listenerGraph = new AddDataForGraph(); addDataGraph = new Timer(5000, listenerGraph); getDataThread = new RunThread(); outputExcelThread = new OutputExcelThread(); getData = false; getDataThread.start(); outputExcelThread.start(); frmPumpActivator = new FrmPumpActivator(); frmPumpActivator.getCbbChooseNode().setModel(masterNode.getModel().getComboBoxModel()); frmPumpActivator.getBtnActivate().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int nodeID = frmPumpActivator.getCbbChooseNode().getSelectedIndex() - 1; int nodeAddress = masterNode.getNodeList().get(nodeID).getAddress(); int pumpSpeed = Integer.parseInt(frmPumpActivator.getTxtSpeed().getText()); int pumpTime = Integer.parseInt(frmPumpActivator.getTxtTime().getText()); masterNode.activeMotor(nodeAddress, pumpSpeed, pumpTime); frmPumpActivator.dispose(); } }); btnRunMotor.setToolTipText("Run the motor manually (only for node 0)"); btnRunMotor.setEnabled(false); btnZoomIn.setEnabled(false); btnZoomOut.setEnabled(false); txtaDataInfo.setText("Press Start button to\nstart getting data"); /* Display date and time */ timeFormat = new SimpleDateFormat("HH:mm:ss"); dateFormat = new SimpleDateFormat("EEE, dd-MM-yyyy"); Thread displayTimeThread = new Thread(new Runnable() { public void run() { while (true) { String time = timeFormat.format(new Date()); String date = dateFormat.format(new Date()); lblDisplayDate.setText(date + ", " + time); try { Thread.sleep(1000); } catch (InterruptedException exc) { } } } }); displayTimeThread.start(); }
From source file:net.sf.dvstar.transmission.dialogs.SessionStatistic.java
/** Creates new form StatsDialog */ public SessionStatistic(TransmissionView parent, TransmissionWebClient webClient, boolean modal) { super(parent.getFrame(), modal); this.webClient = webClient; this.parent = parent; initComponents();//from w w w . j av a 2 s . co m int messageTimeout = 5000; this.getRootPane().setDefaultButton(btClose); new SwingWorker() { @Override protected Object doInBackground() throws Exception { fillFormData(); return null; } }.execute(); updaterTimer = new Timer(messageTimeout, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new SwingWorker() { @Override protected Object doInBackground() throws Exception { updaterTimer.stop(); fillFormData(); updaterTimer.start(); return null; } }.execute(); } }); updaterTimer.setRepeats(true); updaterTimer.start(); }
From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java
/** * Creates new form ACarControlPanelFrame *//* w ww.j av a2s . c o m*/ public ACarControlPanelFrame() { initComponents(); super.setLocation(0, 0); mousePressed = false; initImage(); timer = new Timer(50, this); timer.start(); createDevices(); }
From source file:Main.java
public Main() { super(new BorderLayout()); task = new LongTask(); //Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false);//www .j a v a2s . c om add(startButton, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); //Create a timer. timer = new Timer(ONE_SECOND, new TimerListener()); }
From source file:org.jfree.chart.demo.ChartTiming4.java
/** * Runs the test./*from w w w . ja v a 2 s.c o m*/ */ public void run() { this.finished = false; // create a dataset... populateData(); // create a fast scatter chart... final Plot plot = new FastScatterPlot(this.data, new NumberAxis("X"), new NumberAxis("Y")); final JFreeChart chart = new JFreeChart("Fast Scatter Plot Timing", JFreeChart.DEFAULT_TITLE_FONT, plot, true); final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB); final Graphics2D g2 = image.createGraphics(); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300); // set up the timer... final Timer timer = new Timer(10000, this); timer.setRepeats(false); int count = 0; timer.start(); while (!this.finished) { chart.draw(g2, chartArea, null, null); System.out.println("Charts drawn..." + count); if (!this.finished) { count++; } } System.out.println("DONE"); }