when i run my source code on winows xp then progress bar work fine but on linux it just stuck and not run at all,
My Code is as follows

import java.sql.Connection;
import java.sql.Statement;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.DriverManager;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Scanner;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

class StartingFrame extends JFrame
{
    private static final long serialVersionUID = 1L;
    JFrame frame;
    JLabel logo;
    Date date;
    Timer timer;
    JProgressBar progressBar;
    public StartingFrame() 
    {
        frame =new JFrame();
        try 
    {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) 
    {
      JOptionPane.showMessageDialog(null, "Error, " + e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
        
        logo=new JLabel(new ImageIcon("bankabout.png"));
        frame.setUndecorated(true);
        
        frame.setSize(440, 250);
        frame.setLocationRelativeTo(null);
        frame.add(logo);
        frame.setVisible(true);
        progressBar = new JProgressBar(0, 10);
        progressBar.setValue(0);
        ActionListener listener = new ActionListener() {
            int counter = 0;
            public void actionPerformed(ActionEvent ae) {
                counter++;
                progressBar.setValue(counter);
                if (counter>9) {
                    frame.setVisible(false);
        new bank();
                    timer.stop();
                } 
            }
        };
        Random rn = new Random();
        int ranf=rn.nextInt(1000);
        timer = new Timer(ranf, listener);
        timer.start();
       
        if(fileExist())
        {
             initialize(numDay());
        }
        else
        {
            initialize(1);
        }
        frame.add(progressBar, BorderLayout.PAGE_END);
    }
    public static void main(String args[])
    {
        SwingUtilities.invokeLater( new Runnable() {
            public void run() {
                StartingFrame startingFrame = new StartingFrame();
            }
        });
        
    }
    
     
private void initialize(long interval)
    {
        try
                {                
                    String url1="jdbc:mysql://localhost/bank";
                    Connection cn=DriverManager.getConnection(url1,"root","rushikesh");
                    Statement stmt=cn.createStatement();           
                    stmt.executeUpdate("UPDATE account SET accountBalance=accountBalance+((accountBalance*0.04)/365)*"+interval+" WHERE accTypeName='Saving'");
                    stmt.close();
                    cn.close();
                }catch(Exception er)
                {                   
                   JOptionPane.showMessageDialog(null, "Error, " + er.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                }
    }
long DateSubstract(Date d1, Date d2)
{
    long ONE_HOUR = 60 * 60 * 1000L;
    return ((d2.getTime()-d1.getTime() + ONE_HOUR) / (ONE_HOUR * 24));
}
Date appCloseDate() throws ParseException,IOException
{ 
       FileReader file = new FileReader("Data.acd");
       Scanner s=new Scanner(file);
       String d=s.nextLine();
       DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
       Date datew = dateFormat.parse(d);
     return datew;
}

Date appStartDate() throws ParseException
{
    try{
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
    Date now = new Date();
    sdfDate.format(now);
    date = sdfDate.parse(sdfDate.format(now));
       }catch(Exception e){JOptionPane.showMessageDialog(null, "Error, " + e.getMessage(), null, JOptionPane.ERROR_MESSAGE);}
    return date;
}
private long numDay()
{
    long dist=0;
    try{
        Date e=appStartDate();  
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy");
    Calendar c1 = new GregorianCalendar();
    int f=e.getDate();
    int y=e.getMonth();
     
    int t=Integer.parseInt(sdf.format(e));
   
    c1.set(t ,y ,f);
      Date r=appCloseDate();
    Calendar c2 = new GregorianCalendar();
    int f1=r.getDate();
    int y1=r.getMonth();
    int t1=Integer.parseInt(sdf.format(r));
    c2.set(t1 ,y1 ,f1);
   
         dist=DateSubstract(c2.getTime(), c1.getTime());
    }catch(Exception t){
        JOptionPane.showMessageDialog(null, "Error, " + t.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
    System.out.println("Ellapse Days : "+dist);
    return dist;
}

private boolean fileExist()
{
    File file = new File("Data.acd");  
    boolean exists = file.exists();  
                if (!exists) 
                {  
                    return false;                         
                }else
                {  
                    return true; 
                }
}
}

Dani AI

Generated

The most likely cause is blocking the Event Dispatch Thread (EDT). In ’s code the splash, a Swing Timer, and a database/file update all run while the GUI is being built on the EDT. Swing timers and repaints also run on the EDT, so long I/O or DB work prevents timer callbacks and repaints — on Linux the filesystem, permissions, or DB driver can behave slower or differently, making the progress bar appear “stuck.” ’s note about case-sensitive filenames and working-directory differences is also relevant: verify resource names and the actual working directory.

A reliable fix is to move long-running work off the EDT and only update the progress bar from the EDT. Example using SwingWorker (run DB/file work in doInBackground, publish progress to the progress bar):

SwingWorker<Void,Integer> worker = new SwingWorker<Void,Integer>() {
  protected Void doInBackground() throws Exception {
    // break the task into chunks if possible and publish progress
    for (int i = 0; i <= 10; i++) {
      Thread.sleep(100); // simulate chunked work
      publish(i);
    }
    // run actual DB / file update here (off EDT)
    performDbUpdate();
    return null;
  }
  protected void process(List<Integer> chunks) {
    progressBar.setValue(chunks.get(chunks.size()-1));
  }
  protected void done() {
    splashFrame.setVisible(false);
    new MainAppWindow();
  }
};
worker.execute();

Other practical checks and tips:

  • Add the progress bar to the frame before calling setVisible, or call revalidate()/repaint() after adding it.
  • Avoid a zero-delay timer; ensure a sensible minimum delay.
  • Check resource loading on Linux: print System.getProperty("user.dir") and prefer getResource(...) for bundled images/resources.
  • Log around the DB/file calls (start/end) to confirm where the time is spent; confirm file permissions and that the DB driver is available on the Linux JVM.

Fixing EDT blocking and verifying paths/permissions resolves this class of “works on Windows but hangs on Linux” problems in most cases.

I didn't trace thru all that code, but I notice you've ported a file name from Windows to Linux. Apart from the obvious working directory differences, you are also moving from a case-insensitive environment to a case-sensitive one. Maybe that's a problem?

ps

boolean exists = file.exists();
if (!exists)
{
  return false;
}else
{
  return true;
}

why not just

return file.exists();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.