List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void showNotificationPopup(String popupText, NotificationType type) { JPanel panel = new JPanel(new MigLayout("flowy")); panel.setBorder(BorderFactory.createLineBorder(Color.gray)); switch (type) { case WARNING: case WARNING_HTML: panel.setBackground(Color.yellow); break;/*www .ja va2 s. c om*/ case ERROR: case ERROR_HTML: panel.setBackground(Color.orange); break; default: panel.setBackground(Color.cyan); } JLabel label = new JLabel(popupText); panel.add(label); Dimension labelSize = DesktopComponentsHelper.measureHtmlText(popupText); int x = frame.getX() + frame.getWidth() - (50 + labelSize.getSize().width); int y = frame.getY() + frame.getHeight() - (50 + labelSize.getSize().height); PopupFactory factory = PopupFactory.getSharedInstance(); final Popup popup = factory.getPopup(frame, panel, x, y); popup.show(); panel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { popup.hide(); } }); PointerInfo pointerInfo = MouseInfo.getPointerInfo(); if (pointerInfo != null) { final Point location = pointerInfo.getLocation(); final Timer timer = new Timer(3000, null); timer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PointerInfo currentPointer = MouseInfo.getPointerInfo(); if (currentPointer == null) { timer.stop(); } else if (!currentPointer.getLocation().equals(location)) { popup.hide(); timer.stop(); } } }); timer.start(); } }
From source file:com.t3.client.ui.T3Frame.java
private Timer newChatTimer() { // Set up the Chat timer to listen for changes Timer tm = new Timer(500, new ActionListener() { @Override//from www .j a v a 2s .c o m public void actionPerformed(ActionEvent ae) { long currentTime = System.currentTimeMillis(); LinkedMap<String, Long> chatTimers = chatTyperTimers.getChatTypers(); List<String> removeThese = new ArrayList<String>(chatTimers.size()); Set<String> playerTimers = chatTimers.keySet(); for (String player : playerTimers) { if (currentTime - chatTimers.get(player) >= (chatNotifyDuration * 1000)) { // set up a temp place and remove them after the loop removeThese.add(player); } } for (String remove : removeThese) { chatTyperTimers.removeChatTyper(remove); } } }); tm.start(); return tm; }
From source file:ejemplo.grafica.java
public void cargarbarra() { UIDefaults defaults = new UIDefaults(); defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(Color.BLUE)); defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(Color.BLUE)); progressBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE); progressBar.putClientProperty("Nimbus.Overrides", defaults); ActionListener updateProBar = new ActionListener() { public void actionPerformed(ActionEvent ae) { int max, min, maxD; min = 0;/*from w w w . ja va 2 s .c o m*/ max = Integer.parseInt(txtMaximaAgua.getText()); maxD = Integer.parseInt(txtMaximoDetergente.getText()); progressBar.setMinimum(min); progressBar.setMaximum(max); int nivelDeseado = Integer.parseInt(txtNivelAgua.getText()); int nivelActual = progressBar.getValue(); if (nivelDeseado > nivelActual) { if (nivelDeseado == nivelActual) { timer.stop(); } progressBar.setValue(++nivelActual); } else { if (nivelDeseado < nivelActual) { if (nivelDeseado == nivelActual) { timer.stop(); } progressBar.setValue(--nivelActual); } } } }; timer = new Timer(500, updateProBar); timer.start(); }
From source file:net.rptools.maptool.client.ui.MapToolFrame.java
private Timer newChatTimer() { // Set up the Chat timer to listen for changes Timer tm = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent ae) { long currentTime = System.currentTimeMillis(); LinkedMap chatTimers = chatTyperTimers.getChatTypers(); List<String> removeThese = new ArrayList<String>(chatTimers.size()); @SuppressWarnings("unchecked") Set<String> playerTimers = chatTimers.keySet(); for (String player : playerTimers) { long playerTime = (Long) chatTimers.get(player); if (currentTime - playerTime >= (chatNotifyDuration * 1000)) { // set up a temp place and remove them after the loop removeThese.add(player); }//from ww w . java 2 s . c o m } for (String remove : removeThese) { chatTyperTimers.removeChatTyper(remove); } } }); tm.start(); return tm; }
From source file:com.farouk.projectapp.FirstGUI.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed String name = jTextField2.getText(); String pwd = jPasswordField1.getText().toString(); if (name.isEmpty() || pwd.isEmpty()) { JOptionPane.showMessageDialog(rootPane, "Please enter a valid input.", "Bad input", WIDTH); }//from w w w . j a v a2 s. c o m if (SQLConnect.Login(name, pwd) == true) { userID = SQLConnect.getUserID(name); switch (SQLConnect.getClearanceFromDB(name)) { case 0: AdminGui admin = new AdminGui(); admin.setTitle("News for '" + name + "'"); admin.setLocationRelativeTo(null); admin.setVisible(true); this.setVisible(false); admin.setDefaultCloseOperation(EXIT_ON_CLOSE); break; case 1: JOptionPane.showMessageDialog(rootPane, "Coming Soon !!", "Patience", WIDTH); break; case 2: loginState = true; jPanel7.setVisible(false); jPanel9.setVisible(true); jLabel11.setText("Welcome " + name); jLabel12.setText("Your current buy limit is :" + String.valueOf(SQLConnect.getBudgetFromDB(userID).doubleValue()) + "."); checkLoginState(loginState); timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jTable2.setEnabled(true); jLabel7.setText("Refreshing in : " + String.valueOf(counter) + "s."); counter--; if (counter == -1) { jTable2.setEnabled(false); jButton5ActionPerformed(e); AutoRunBuyAndSell(); counter = 120; actionPerformed(e); } } }); timer.start(); break; default: JOptionPane.showMessageDialog(rootPane, "Sorry not found.", "No match", WIDTH); break; } } else { JOptionPane.showMessageDialog(rootPane, "Sorry no match.\nWe suggest creating a new account", "No match", WIDTH); } }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
private void play(File file) throws BasicPlayerException, FileNotFoundException, IOException { for (ObjectBean list1 : list) { if (list1.getMpg().playControl == 1) { list1.getMpg().pause();/*ww w.jav a 2s . c o m*/ } } playControl = 1; myPlayer = new BasicPlayer(); fis = new FileInputStream(file); setProgressBar(); progressOneSecond = (fis.available() / songLengthSeconds); progressTimer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (pointerProgress < songLengthSeconds) { progressBar.setValue(Math.round(progressOneSecond * pointerProgress)); if (pointerPause == 0) { pointerProgress++; pointerDegress--; remainTimeLabel.setText(getTime(pointerProgress)); totaltimeLabel.setText(getTime(pointerDegress)); } } else { try { stop(); if (repeat_check_menuItem.isSelected()) { songPlay(); } else if (shuffle_check_menuItem.isSelected()) { shuffle(); } else { next_Song_ButtonMouseClicked(null); } } catch (BasicPlayerException | IOException ex) { System.out.println("Error in stop Method from progressTimer....." + ex); } } } }); progressTimer.start(); myPlayer.open(file); myPlayer.play(); pauseSet(); volumeTimer = new Timer(10, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { volumeSet = ((float) volume_Slider.getValue() / 100); myPlayer.setGain(volumeSet); } catch (BasicPlayerException ex) { System.out.println("Error in volumeTimer....." + ex); } } }); volumeTimer.start(); }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
private void setVolumeImg() { volumeImg = new Timer(10, new ActionListener() { @Override//from w w w .j a v a2s . c o m public void actionPerformed(ActionEvent e) { volume = volume_Slider.getValue(); try { if (volume > 60) { ima = ImageIO.read(getClass().getResource("/Images/soundMax.png")); volumeLabel.setIcon(new ImageIcon(ima)); } else if (volume < 60 && volume > 0) { ima = ImageIO.read(getClass().getResource("/Images/soundMedium.png")); volumeLabel.setIcon(new ImageIcon(ima)); } else if (volume == 0) { ima = ImageIO.read(getClass().getResource("/Images/soundMute.png")); volumeLabel.setIcon(new ImageIcon(ima)); } } catch (IOException ex) { System.out.println("Error in Timer Volume Image....." + ex); } } }); volumeImg.start(); }
From source file:ru.spbspu.viewer.DataView.java
private void setTimer() { final int maxFramePosition = seekSlider.getMaximum(); final int maxFramePositionCursor = (int) (_presenter.getFrameWidthInSeconds() * 1000); int shiftCursor = maxFramePositionCursor / 100; cursor.setMaximum(maxFramePositionCursor); System.out.println(cursor.getMaximum() + " slider Cursor max"); cursor.setMinimum(0);//from w w w. j a v a2 s . com cursor.setValue(0); this._frameTimer = new Timer((int) (_presenter.getFrameWidthInSeconds() * 10), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int currentValue = seekSlider.getValue(); int shift = Integer.valueOf(spinnerFrameWidth.getValue().toString()); int nextValue = Math.min(maxFramePosition, currentValue + shift); int currentValueCursor = cursor.getValue(); int nextValueCursor = Math.min(maxFramePositionCursor, currentValueCursor + shiftCursor); if (currentValueCursor < maxFramePositionCursor) { DataView.this.cursor.setValue(nextValueCursor); } else if (currentValue < maxFramePosition) { cursor.setValue(0); DataView.this.seekSlider.setValue(nextValue); } else { DataView.this._frameTimer.stop(); } } }); }
From source file:semaforo.Semaforo.java
public void realTime() { timer = new Timer(Controller.getSettings().getVaribable(DDBB.RATIO_REFRESCO), new RealTimeListener()); timer.start(); }
From source file:com.willwinder.universalgcodesender.MainWindow.java
private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed // Timer for updating duration labels. ActionListener actionListener = new ActionListener() { @Override/*from ww w . j av a 2s. c o m*/ public void actionPerformed(ActionEvent actionEvent) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { try { durationValueLabel.setText(Utils.formattedMillis(backend.getSendDuration())); remainingTimeValueLabel .setText(Utils.formattedMillis(backend.getSendRemainingDuration())); //sentRowsValueLabel.setText(""+sentRows); sentRowsValueLabel.setText("" + backend.getNumSentRows()); remainingRowsValueLabel.setText("" + backend.getNumRemainingRows()); if (backend.isSending()) { if (vw != null) { vw.setCompletedCommandNumber((int) backend.getNumSentRows()); } } } catch (Exception e) { e.printStackTrace(); } } }); } }; this.resetTimerLabels(); if (timer != null) { timer.stop(); } timer = new Timer(1000, actionListener); // Note: there is a divide by zero error in the timer because it uses // the rowsValueLabel that was just reset. try { this.backend.send(); this.resetSentRowLabels(backend.getNumRows()); timer.start(); } catch (Exception e) { timer.stop(); logger.log(Level.INFO, "Exception in sendButtonActionPerformed.", e); displayErrorDialog(e.getMessage()); } }