Questions tagged [javax.swing.timer]

34 questions
5
votes
1 answer

Using SwingWorker and Timer to display time on a label?

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) { …
Asif
  • 4,980
  • 8
  • 38
  • 53
5
votes
1 answer

Setting JDialog opacity by Timer

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…
Asif
  • 4,980
  • 8
  • 38
  • 53
4
votes
1 answer

Timer is trying to convert to String

Can someone please tell me why the Timer is trying to Convert an int into a String. Here is the error that keeps coming up. CurrentTimePrinter.java:48: error: incompatible types: int cannot be converted to String time = new…
Dustin
  • 185
  • 3
  • 12
4
votes
4 answers

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

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); …
John R Doner
  • 2,242
  • 8
  • 30
  • 36
4
votes
4 answers

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

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…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
3
votes
3 answers

JFrame that has multiple layers

I have a window that has two layers: a static background and a foreground that contains moving objects. My idea is to draw the background just once (because it's not going to change), so I make the changing panel transparent and add it on top of the…
phunehehe
  • 8,618
  • 7
  • 49
  • 79
3
votes
2 answers

DocumentListener with Thread.sleep

I want to know when I am writing and when I am deleting, but, after a 0.5 second delay, it will tell me "You stopped writing/deleting" However, it only shows that message and it delete or write after a half second delay. How could I use…
DavidM
  • 570
  • 4
  • 21
3
votes
1 answer

How to use Timer isRunning?

I am creating a program that is creating gates(AND, OR etc.), but when I want to create an SR latch, I need to use a timer. So when this method(inputChanged) is called it should check if the timer is running. If it is running it should do nothing. …
Oreex0
  • 324
  • 3
  • 15
2
votes
2 answers

Make a Swing Timer execute N times?

How can I adjust this Timer code so that it executes four times and then stops? timer = new Timer(1250, new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { …
JaLe29
  • 57
  • 1
  • 9
2
votes
1 answer

Use javax.swing.Timer to make countdown timer in Java

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…
CodeAddict
  • 194
  • 2
  • 5
  • 19
1
vote
0 answers

How can I better implement my Key Bindings and Swing Timer?

Hey thanks for looking at my post. I've been working on a passion project over the summer and this issue has risen. First off this may count as a duplicate question but I've been looking around this site and Oracle for a fix and couldn't find one,…
1
vote
1 answer

Timer creates a new Window on Start

My timer is creating a new window with non-working buttons when I hit the start button. The change in display only happens in the new window but the start/stop functionality only works in the old window. I'm not sure what's going on here. Can…
Kendra
  • 125
  • 2
  • 12
1
vote
1 answer

Perform action upon completion of barcode scanning to JTextField

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.…
Neigyl R. Noval
  • 6,018
  • 4
  • 27
  • 45
1
vote
1 answer

Java Swing.Timer get real time millisecond

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…
1
vote
1 answer

Unable to execute timer in [java]

I've been trying to get down the basics of using a timer so that I can create a bouncing ball program, but I can't seem to implement a timer correctly. This program should in theory just continuously print the display, but instead the program simply…
1
2 3