M
marpauser
Hello,
I would like your comment about synchronized and
SwingUtilities.invokeLater in this example with javax.swing.Timer:
/*
* First
*/
import java.awt.event.*;
import javax.swing.*;
public class MyTimer{
private Timer timer;
public MyTimer(){
initTimer();
}
public void startTimer(){
timer.start();
}
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
private void initTimer(){
timer = new Timer( 5000, new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
doAction();
}
} );
}
private void doAction(){
System.out.println("Hello!");
}
}
///////////////////////////////////////////////////////////////////////
/*
* Second
*/
.....
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
......
private synchronized void doAction(){
System.out.println("Hello!");
}
/////////////////////////////////////////////////////////////
/*
* Third
*/
.......
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
});
}
........
private void doAction(){
System.out.println("Hello!");
}
//////////////////////////////////////////////////////////////
/*
* Fourth
*/
.......
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
});
}
........
private synchronized void doAction(){
System.out.println("Hello!");
}
Thanks,
Paolo
I would like your comment about synchronized and
SwingUtilities.invokeLater in this example with javax.swing.Timer:
/*
* First
*/
import java.awt.event.*;
import javax.swing.*;
public class MyTimer{
private Timer timer;
public MyTimer(){
initTimer();
}
public void startTimer(){
timer.start();
}
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
private void initTimer(){
timer = new Timer( 5000, new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
doAction();
}
} );
}
private void doAction(){
System.out.println("Hello!");
}
}
///////////////////////////////////////////////////////////////////////
/*
* Second
*/
.....
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
......
private synchronized void doAction(){
System.out.println("Hello!");
}
/////////////////////////////////////////////////////////////
/*
* Third
*/
.......
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
});
}
........
private void doAction(){
System.out.println("Hello!");
}
//////////////////////////////////////////////////////////////
/*
* Fourth
*/
.......
public static void main(String[] args) {
MyTimer myTimer = new MyTimer();
myTimer.startTimer();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog( null, "Wait...","MyTimer" ,
JOptionPane.WARNING_MESSAGE);
}
});
}
........
private synchronized void doAction(){
System.out.println("Hello!");
}
Thanks,
Paolo