List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:com.github.pemapmodder.pocketminegui.gui.server.ConsolePanel.java
public ConsolePanel(ServerMainActivity activity) { this.activity = activity; setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10)); title = new JLabel("PocketMine-MP"); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0.1;// www . ja v a 2s.c o m add(title, c); stdout = new JEditorPane(); stdout.setContentType("text/html"); stdout.setText("<html><body style='font-family: monospace; color: #FFFFFF;'><p id='p'></p></body></html>"); doc = (HTMLDocument) stdout.getDocument(); para = doc.getElement("p"); // stdout.setEditable(false); // People NEED to see this to feel happy stdout.setForeground(Color.WHITE); stdout.setBackground(Color.BLACK); Style style = doc.getStyleSheet().addStyle(null, null); // style.addAttribute(StyleConstants.Foreground, Color.WHITE); // style.addAttribute(StyleConstants.Background, Color.RED); doc.setParagraphAttributes(para.getStartOffset(), 1, style, true); stdout.setBorder(BorderFactory.createDashedBorder(new Color(0x80, 0x80, 0x80))); c.gridy = 1; c.weightx = 0.9; c.weighty = 0.9; c.weighty = 0.6; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTH; add(stdout, c); Timer timer = new Timer(50, e -> updateConsole()); timer.start(); }
From source file:ProgressMonitorDemo.java
public ProgressMonitorDemo() { 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);/*from w w w .java 2 s .c o m*/ 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:com.view.TradeWindow.java
/** * Creates new form TradeWindow//from w w w .j a va 2 s . com */ public TradeWindow() { super(); //The following line is for the exit confirmation addWindowListener(new AreYouSure()); initComponents(); //START TIMER TO UPDATE ORDERS Timer timer = new Timer(10000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ArrayList<SingleOrder> ordersDone = new ArrayList<>(); ArrayList<SingleOrder> pendingOrders = new ArrayList<>(); ArrayList<Block> blockHistory = new ArrayList<>(); //MAKE PENDING ORDERS FROM PM UPDATE try { ordersDone = (ArrayList) CTraderOrderMANIAC.updateOrders(); } catch (InterruptedException | IOException | JSONException | ExecutionException ex) { Logger.getLogger(TradeWindow.class.getName()).log(Level.SEVERE, null, ex); } //MAKE BLOCK ORDER HISTORY UPDATE try { blockHistory = (ArrayList) CTraderOrderMANIAC.updateBlockOrderHistory(); } catch (InterruptedException | ExecutionException | IOException | JSONException ex) { Logger.getLogger(TradeWindow.class.getName()).log(Level.SEVERE, null, ex); } if (null != ordersDone) { for (SingleOrder o : ordersDone) { if (o.getStatus().equals("Pending")) { pendingOrders.add(o); } } int currentlyInPendings = CTraderOrderMANIAC.getPendings().size(); int updatedPendings = pendingOrders.size(); System.out.println( "Size of currentPend = " + currentlyInPendings + " and of updated: " + updatedPendings); CTraderOrderMANIAC.setPendings(pendingOrders); TraderIncomingRequestsTable.setModel(CTraderOrderMANIAC.getPRTableModel()); if (currentlyInPendings < updatedPendings) { showMessageDialog(null, "You have received new orders."); } } else { System.out.println("ERROR UPDATING ORDERS"); } if (null != blockHistory) { CTraderOrderMANIAC.setBlockHistory(blockHistory); TraderBlockHistoryTable.setModel(CTraderOrderMANIAC.getBlockHistoryTableModel()); } else { System.out.println("ERROR UPDATING BLOCKS"); } } }); timer.start(); try { Thread.sleep(5000); } catch (InterruptedException e) { } timer.restart(); }
From source file:org.jfree.chart.demo.ChartTiming2.java
/** * Runs the test.//from www .j a v a2 s . c o m */ public void run() { this.finished = false; // create a dataset... final XYDataset data = new SampleXYDataset2(1, 1440); // create a scatter chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data, PlotOrientation.VERTICAL, withLegend, false, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); 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"); }
From source file:com.ctsim.dmi.MainFrame.java
/** * Creates new form MainFrame/* w ww.java2 s . co m*/ */ public MainFrame() { initComponents(); timer = new Timer(30, this); timer.start(); t1 = Calendar.getInstance(); try { brake_indicator_yellow = ImageIO.read(FileUtils .toFile(this.getClass().getClassLoader().getResource("img/brake_indicator_yellow.png"))); brake_indicator_red = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/brake_indicator_red.png"))); speedoDial = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/speedo_dial.png"))); speedoPinWhite = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/speedo_pin_white.png"))); speedoPinYellow = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/speedo_pin_yellow.png"))); speedoPinRed = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/speedo_pin_red.png"))); targetDestination = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/target_destination.png"))); atp_status_auto = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_auto.png"))); atp_status_mcs = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_mcs.png"))); atp_status_atb = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_atb.png"))); atp_status_yard_sr = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_yard_sr.png"))); atp_status_yard_eoa = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_yard_eoa.png"))); atp_status_line_sr = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_line_sr.png"))); atp_status_rv = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_status_rv.png"))); atp_blank = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atp_blank.png"))); atenna_yellow = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atena_yellow.png"))); atenna_green = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atena_green.png"))); atenna_fail = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/atena_fail.png"))); ato_status_ok = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/ato_status_ok.png"))); ato_status_fail = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/ato_status_fail.png"))); door_indicator_both = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/door_indicator_both.png"))); door_indicator_left = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/door_indicator_left.png"))); door_indicator_right = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/door_indicator_right.png"))); door_status_close = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/door_status_close.png"))); door_status_open = ImageIO.read( FileUtils.toFile(this.getClass().getClassLoader().getResource("img/door_status_open.png"))); scroll_arrow = ImageIO .read(FileUtils.toFile(this.getClass().getClassLoader().getResource("img/scroll_arrow.png"))); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:llc.rockford.webcast.EC2Driver.java
public EC2Driver(String[] args) { parseCommandLine(args);/*from w ww .j a v a 2 s .c o m*/ createAndShowGUI(); applicationState = new ApplicationState(this); new InitializeWorker(ec2Handle.getEc2Handle(), applicationState).execute(); Timer timer = new Timer(5000, this); timer.setInitialDelay(3000); timer.start(); broadcaster = new StreamBroadcaster(amazonProperties); // add shut down hooks to terminate amazon EC2 instance // to prevent over billing Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { new TerminateInstanceWorker(ec2Handle.getEc2Handle(), applicationState, amazonProperties).execute(); } }); }
From source file:networkmonitor.MainIBMApplicationForm.java
public MainIBMApplicationForm() { setSize(850, 320); //set size setTitle("Network Monitor");//Setting the title setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Setting the action close to the close button //............menu........... /* JMenuBar menuBar = new JMenuBar(); /*from ww w.j a v a2 s . c om*/ // Add the menubar to the frame setJMenuBar(menuBar); // Define and add two drop down menu to the menubar JMenu about = new JMenu(""); menuBar.add(about); menuBar.add(Box.createHorizontalGlue()); JMenu version = new JMenu(""); menuBar.add(version);*/ //.................. series1 = new XYSeries("b/w usage in KBps"); dataset = createDataset(); chart = createChart(dataset); chartPanel = new ChartPanel(chart); //chartPanel.setPreferredSize(new java.awt.Dimension(850, 320)); // chartPanel.setLayout(); chartPanel.add(current_bandwidth_label); setContentPane(chartPanel); pmt = new PacketMonitoringThread(); pmt.start(); Action updateCursorAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int current_bandwidth = new Integer((int) TcpPacketCapturer.getPacketSizeTillNowAndResetSize()); qe.add(current_bandwidth); current_bandwidth_label.setText("" + current_bandwidth); if (qe.size() > 20) { System.out.println(qe.poll()); } dataset = createDataset(); chart = createChart(dataset); chartPanel = new ChartPanel(chart); // getContentPane().repaint(); // SwingUtilities.updateComponentTreeUI(chartPanel); } }; // its timer, it works like sleep, and in this apps its give you Internet speed KB/sec. new Timer(1000, updateCursorAction).start(); }
From source file:org.jfree.chart.demo.ChartTiming1.java
/** * Runs the timing.// w w w. ja v a 2 s . co m */ public void run() { this.finished = false; // create a dataset... final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("One", new Double(10.3)); data.setValue("Two", new Double(8.5)); data.setValue("Three", new Double(3.9)); data.setValue("Four", new Double(3.9)); data.setValue("Five", new Double(3.9)); data.setValue("Six", new Double(3.9)); // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart("Testing", data, withLegend, true, false); 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"); }
From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java
/** * A standalone demo charting load averages. *///from w ww . j a va 2 s. co m public JLoadChart() { super("JLoadChart"); jkstat = new NativeJKstat(); int maxage = 600000; String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT"); ts1 = new TimeSeries("1min " + lavetext); ts1.setMaximumItemAge(maxage); ts5 = new TimeSeries("5min " + lavetext); ts5.setMaximumItemAge(maxage); ts15 = new TimeSeries("15min " + lavetext); ts15.setMaximumItemAge(maxage); updateAccessory(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(ts1); dataset.addSeries(ts5); dataset.addSeries(ts15); JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"), KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false); XYPlot xyplot = chart.getXYPlot(); NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT")); loadaxis.setAutoRange(true); loadaxis.setAutoRangeIncludesZero(true); xyplot.setRangeAxis(loadaxis); DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME")); daxis.setAutoRange(true); daxis.setFixedAutoRange(maxage); xyplot.setDomainAxis(daxis); addWindowListener(new winExit()); setContentPane(new ChartPanel(chart)); JMenuBar jm = new JMenuBar(); JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X); exitItem.addActionListener(this); jme.add(exitItem); jm.add(jme); setJMenuBar(jm); pack(); setVisible(true); Timer timer = new Timer(5000, this); timer.start(); }
From source file:QandE.Beeper2.java
private void startBeeping(int numBeeps) { Toolkit.getDefaultToolkit().beep(); if (numBeeps > 1) { if (timer == null) { timer = new Timer(500, this); }//from w w w .j ava2s .c om beepsRemaining = numBeeps - 1; timer.start(); } }