javax.swing.timer

Perform action upon completion of barcode scanning to JTextField

血红的双手。 提交于 2019-12-11 11:58:58
问题 I have a JTextField barcodeTextField which accepts characters from the scanned barcode using a barcode scanner. From what I know, barcode scanning is like typing the characters very fast or copy-pasting the characters on the text field. barcodeTextField is also used to show suggestions and fill up others fields with information (just like searching in Google where suggestions are shown as you type). So far I implemented this using DocumentListener : barcodeTextField.getDocument()

Setting JDialog opacity by Timer

浪尽此生 提交于 2019-12-10 15:45:29
问题 I am using the following code to fade-in a JDialog with a javax.swing.Timer : float i = 0.0F; final Timer timer = new Timer(50, null); timer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (i == 0.8F){ timer.stop(); } i = i + 0.1F; setOpacity(i); } }); timer.start(); The Dialog is nicely faded-in with the desired effect but at last, an IllegalArgumentException Occurs saying that: The value of opacity should be in the range [0.0f .. 1.0f] But

How do you create a javax.swing.Timer that fires immediately, then every t milliseconds?

妖精的绣舞 提交于 2019-12-04 03:38:10
问题 Right now, I have code that looks something like this: Timer timer = new javax.swing.Timer(5000, myActionEvent); According to what I'm seeing (and the Javadocs for the Timer class), the timer will wait 5000 milliseconds (5 seconds), fire the action event, wait 5000 milliseconds, fire again, and so on. However, the behavior that I'm trying to obtain is that the timer is started, the event is fired, the timer waits 5000 milliseconds, fires again, then waits before firing again. Unless I missed

Java Swing.Timer get real time millisecond

白昼怎懂夜的黑 提交于 2019-12-02 14:59:47
问题 I'm having a problem in my program. I want to get a real time millisecond that equal to 1000 in 1 seconds. Here's my code: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; class lsen implements ActionListener{ int ms = 0; int s = 0; int m = 0; public void actionPerformed(ActionEvent e){ this.ms++; if(this.ms == 500){ this.s++; this.ms = 0; } if(this.s == 60){ this.m++; this.s = 0; } } public int getMS(){ return this.ms; } public int getSS(){

Java Swing.Timer get real time millisecond

情到浓时终转凉″ 提交于 2019-12-02 05:17:11
I'm having a problem in my program. I want to get a real time millisecond that equal to 1000 in 1 seconds. Here's my code: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; class lsen implements ActionListener{ int ms = 0; int s = 0; int m = 0; public void actionPerformed(ActionEvent e){ this.ms++; if(this.ms == 500){ this.s++; this.ms = 0; } if(this.s == 60){ this.m++; this.s = 0; } } public int getMS(){ return this.ms; } public int getSS(){ return this.s; } public int getMM(){ return this.m; } } public class stopwatch_main{ public static void

Use javax.swing.Timer to make countdown timer in Java [duplicate]

你离开我真会死。 提交于 2019-12-01 23:02:10
Possible Duplicate: Stop timer with conditional only works first time? I'm very confused as to how to make a timer using the swing and not util timer. I am making a game where users have to answer questions in a 30 second time limit. I have a PlayFrame, where the time is shown, and a method inside PlayFrame called startTimer which contains all the timer stuff. public static void startTimer() { int elapsedSeconds = 0; javax.swing.Timer myTimer = new javax.swing.Timer(1000, new MyTimerActionListener()); elapsedSeconds++; if (elapsedSeconds == 30) { myTimer.stop(); timerLabel.setText("0"); wrong(

How do you create a javax.swing.Timer that fires immediately, then every t milliseconds?

故事扮演 提交于 2019-12-01 19:48:47
Right now, I have code that looks something like this: Timer timer = new javax.swing.Timer(5000, myActionEvent); According to what I'm seeing (and the Javadocs for the Timer class ), the timer will wait 5000 milliseconds (5 seconds), fire the action event, wait 5000 milliseconds, fire again, and so on. However, the behavior that I'm trying to obtain is that the timer is started, the event is fired, the timer waits 5000 milliseconds, fires again, then waits before firing again. Unless I missed something, I don't see a way to create a timer that doesn't wait before firing. Is there a good, clean

Using SwingWorker and Timer to display time on a label?

本小妞迷上赌 提交于 2019-11-30 21:06:53
I want to have a clock showing current time and refreshes every second. The code I am using is: int timeDelay = 1000; ActionListener time; time = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { timeLabel.setText(DateTimeUtil.getTime()); /*timeLabel is a JLabel to display time, getTime() is samll static methos to return formatted String of current time */ } }; SwingWorker timeWorker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { new Timer(timeDelay, time).start(); return null; } }; timeWorker.execute(); What I want to refresh

Javax.swing timer repeats fine, but ActionListener doesn't do anything

独自空忆成欢 提交于 2019-11-26 00:38:32
问题 I am trying to flash the background colour in a textfield. My timer setup is as follows: Flash flash = new Flash(); //set up timer tmr = new javax.swing.Timer(1000, new Flash()); tmr.addActionListener(flash); tmr.setInitialDelay(0); tmr.setRepeats(true); tmr.start(); My actionListener is as follows: static class Flash implements ActionListener { public void actionPerformed(ActionEvent evt) { if (flasher) { SpreademPanel.historyPnl.NameTxt.setBackground(Color.white); } else { SpreademPanel