When we create JDialog inside Thread's run() method it is creating problem

I have application that has feature that mainframe will be locked after three minutes and the time when it is locked it will show other locked dialog.
Now my problem is given below:
I have created one Dialog inside Threads run() method and this thread will execute when mainframe is locked.So what is happening is when mainframe is locked internally Thread is doing its job (its job is to display one dialog) and it is displaying dialog but mainframe is locked and still it is showing that dialog.This should not happen in our application when mainframe is locked nothing should come outside.
simple code sample is given below:
SwingUtilities.invokeLater(new Runnable()
JDailog dlg = new JDialog();
dlg.pack();
dlg.show();
Now when my applications mainframe is locked and thread is doing its job when mainframe is locked and it will show one dialog when its run() method will execute and it showing dialog even though mainframe is locked.This is major issue for me.please help me.
sample code may contain compile errror but this only to give understanding what i am doing actually i cant show my original code.
But show me some work around for this problem.Why dialog is coming outside when mainframe is locked?
Please help me.I cant use delay inside run() method because of performance.
Is there any way to control this behaviour?

public class BackGroundThread extends javax.swing.JFrame implements BackgroundTaskInf {
    boolean isMainWindowActive = false;
    /** Creates new form BackGroundThread */
    public BackGroundThread() {
        initComponents();
        new DBBackgroudProcess(this).start();
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
    private void initComponents() {
        jDialog1 = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel1.setText("JOB DONE");
        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(95, 95, 95)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(240, Short.MAX_VALUE))
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addContainerGap(22, Short.MAX_VALUE))
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel2.setText("Background work in progess");
        jButton1.setText("unlock");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(126, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(263, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(74, 74, 74))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabel2)
                .addGap(37, 37, 37)
                .addComponent(jButton1)
                .addContainerGap(43, Short.MAX_VALUE))
        pack();
    }// </editor-fold>                       
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        isMainWindowActive = true;
        backgroundTaskFinished();
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BackGroundThread().setVisible(true);
    public void backgroundTaskFinished(){
        if(isMainWindowActive) {
            jDialog1.setSize(200,200);
            jDialog1.setVisible(true);
            jLabel2.setText("Task is finished");
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration                  
class DBBackgroudProcess extends Thread {
    BackgroundTaskInf infObj;
    public DBBackgroudProcess(BackgroundTaskInf infObj){
        this.infObj = infObj;
    public void run(){
        try{
            // here you can do your backgroudn task
            System.out.println("In BackGroud task");
            Thread.sleep(1000);
            System.out.println("task completed");
            infObj.backgroundTaskFinished();
        }catch(Exception e){
            e.printStackTrace();
interface BackgroundTaskInf{
    public void backgroundTaskFinished();
}

Similar Messages

  • How can I create a new thread to run PulseOutput.VI

    Hi:
      I use NI-94729(cDAQ system) to generate pluse and want to output  pulse continuously and to check the pulse is 500Hz.
      In TestStand, the steps as follow:
      1: Call PulseOuput.vi to generate 500Hz pulse, VI use Finite Mode to generate pulse.
      2: Verify the pulse is 500Hz.
     Howerver, after the first step finishes, the pulse output stops, te 2nd step is failed. If a Continuous Mode is used in PulseOuput.vi to generate pluse, the 1st step can't finish.
    Thanks a lot!

    Hello MotionBoy,
    There are two ways to go about creating a new thread to run a step.  The first is to create a new sequence, into which you put the LabVIEW step you want to run and any other steps that may go along with it.  Then use a sequence call step to call this newly created sequence.  Set the Execution Options of the Sequence call step to 'Use New Thread.'  This will allow you to run a set of steps in a new thread, not just a VI.  The second method, which is only available for a LabVIEW VI, is to use the “Run VI Asynchronously” step.  This can be accessed if you right-click within your sequence and select Insert Step » LabVIEW Utility » Run VI Asynchronously.  This step will allow you to call a VI and have it automatically open in a new thread.  You can further customize this step by opening the configuration menu in the Step Settings.
    To address the current behavior of your steps I would like to know if the modules in steps 1 & 2 pass data between them or it would be desirable for them to do so?  If so you are going to need a more complex synchronization structure such as TestStand/LabVIEW queues. There is a simple example you may want to look at in the TestStand examples, under the Synchronization folder that demonstrates how to use queues. Otherwise the above solution should be all you need.
    John B.
    Applications Engineer
    National Instruments

  • How to create ApplicationModule inside Thread!

    I would like to create an ApplicationModule object inside Thread! When I create an ApplicationModule anywhere else in class it works fine with no problem.
    But when I put ApplicationModule am = Configuration.createRootApplicationModule("",""); inside Thread (...in Run() method ) It throws the error:
    oracle.jbo.JboException: JBO-33001: Cannot find the configuration file /package/model/common/bc4j.xcfg in the classpath at oracle.jbo.client.Configuration.loadFromClassPath(Configuration.java:358)
         at oracle.jbo.common.ampool.PoolMgr.createPool(PoolMgr.java:281)
         at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:482)
         at oracle.jbo.common.ampool.ContextPoolManager.findPool(ContextPoolManager.java:165)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1457)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1435)
         at hrm.edc.model.pripravaPodatkov.ZajemPodatkov.run(ZajemPodatkov.java:56)
         at java.lang.Thread.run(Thread.java:534)
    If Anyone have a solution please help!
    Thanks!

    Cannot find the configuration file /package/model/common/bc4j.xcfg in the classpath
    In the client/view project set a dependency to the BC4J project.

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • Thread's run method

    I cannot unserstand why the output of this program is:
    axa axa
    class A extends Thread
    public void run()
    System.out.print("axa ");
    public class Main
    public static void main(String[] args) throws Exception
    Thread t = new Thread(new A());
    t.run();
    t.start();

    Guestios wrote:
    Why the
    t.run();
    calls the run() method of the Class A?
    t is just an instance of class ThreadThe implementation of the run() method in the Thread class looks like this:
    public void run() {
         if (target != null) {
             target.run();
    }The 'target' variable is the Runnable you passed to the Thread in the constructor, which was an instance of A, so it's run() method was called.
    Jim S.

  • Java.lang.OutOfMemoryError: unable to create new native thread

    Hi All,
    I have installed weblogic server 8 sp4 in production environment . I am facing problems with JVM issues .
    JVM is crashing very frequently with the following errro :
    ####<Jun 18, 2009 10:58:22 AM IST> <Info> <Common> <IMM90K-21> <SalesCom> <ExecuteThread: '24' for queue: 'weblogic.kernel.Default'> <<anonymous>> <> <BEA-000628> <Created "1" resources for pool "PIConnectionPool", out of which "1" are available and "0" are unavailable.>
    ####<Jun 18, 2009 11:00:09 AM IST> <Info> <EJB> <IMM90K-21> <SalesCom> <ExecuteThread: '23' for queue: 'weblogic.kernel.Default'> <<anonymous>> <> <BEA-010051> <EJB Exception occurred during invocation from home: payoutCheck.ejb.payoutCheck_s6v3so_HomeImpl@121a735 threw exception: java.lang.OutOfMemoryError: unable to create new native thread
    java.lang.OutOfMemoryError: unable to create new native thread
         at java.lang.Thread.start(Native Method)
         at payoutCheck.classes.MyThread2.MyThreadv(PayoutCheckBOImpl.java:249)
         at payoutCheck.classes.PayoutCheckBOImpl.genSP(PayoutCheckBOImpl.java:184)
         at payoutCheck.ejb.PayoutCheckSLSB.genSP(PayoutCheckSLSB.java:191)
         at payoutCheck.ejb.payoutCheck_s6v3so_EOImpl.genSP(payoutCheck_s6v3so_EOImpl.java:315)
         at payoutCheck.ejb.payoutCheck_s6v3so_EOImpl_CBV.genSP(Unknown Source)
         at payoutCheck.deligate.PayoutCheckBD.genSP(PayoutCheckBD.java:226)
         at ui.action.SearchAction.callFilter(SearchAction.java:378)
         at sun.reflect.GeneratedMethodAccessor201.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
         at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    >
    The above mentioned is coming several times , anybody please help out to get rid of this issue.
    Thanks in advance ,
    Krikar.

    This only tells you that the JVM is running out of heap space. It doesn't tell you what is causing the problem. You likely have a memory leak, but you could also try increasing the max heap size of the JVM (-Xmx command line option). It would help to watch the % mem in use statistic, but only immediately after a garbage collection cycle (you can force a GC from the admin console). If the % mem in use after the GC is increasing over time, then that likely confirms you have a memory leak. Note that looking at that statistic during the server startup probably is irrelevant. You'd need to wait until the server finishes starting up, and likely processed a few messages (to load static data).
    If you get to the point of confirming that you have a memory leak, that requires doing detailed analysis with a Java profiler (JProfiler, JProbe, YourKit, etc.) to track down the source of the leak.

  • Thread Callable call() method question

    i am using callable interface and i need to return from call() method before process gets over.
    basically i have infinite loop in call() method which gets data from streaming services,
    and once i format the data and send back to EDT to update UI constantly.
    i am using call() method because my call() (same as run() runnable) throws exception if there is any problem in receiving data.
    i don't care for return value from call(). i only care if there is any exception.
    if i don't do task.get().... then everything works fine, but then i dont get any executionException as well, (which i really care for)
    FutureTask<String> task = new FutureTask<String>(resParser);
    Thread thread= new Thread(task);
    thread.start();
    try{
        String result = task.get();
    }catch(ExecutionException e){
        e.printStackTrace();
    }catch(InterruptedException ex){
    }any solution ??
    Thanks

    You will need to re-consider your requirements. You either call get() and block the active thread, or you let the thread continue to run and don't call get().
    Your solution would be to catch the exception someplace else and feed the exception (or message) to wherever you need it. Why do you think you need to catch the exception right here (which is apparently in your EDT)? Why not catch it in the Thread's run method and deal with it there?

  • When my thread starts running, at that time keylistener is not working.

    when my thread starts running, at that time keylistener is not working.
    plz reply me.

    //FrameShow.java
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.awt.Dimension;
    import java.awt.geom.Dimension2D;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.util.logging.Level;
    import java.awt.event.*;
    import java.util.*;
    public class FrameShow extends JFrame implements ActionListener,KeyListener
         boolean paused=false;
         JButton stop;
         JButton start;
         JButton exit;
         public IncludePanel CenterPanel;
         public FrameShow()
    CenterPanel= new IncludePanel();
              Functions fn=new Functions();
              int height=fn.getScreenHeight();
              int width=fn.getScreenWidth();
              setTitle("Game Assignment--Santanu Tripathy--MCA");
              setSize(width,height);
              setResizable(false);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              show();
              initComponents();
              DefaultColorSet();
              this.addKeyListener(this);
         this.setFocusable(true);
         public void initComponents()
              Container contentpane=getContentPane();
              //Creating Panel For Different Side
              JPanel EastPanel= new JPanel();
              JPanel WestPanel= new JPanel();
              JPanel NorthPanel= new JPanel();
              JPanel SouthPanel= new JPanel();
              //CenterPanel = new IncludePanel();
              //IncludePanel CenterPanel= new IncludePanel();
              EastPanel.setPreferredSize(new Dimension(100,10));
              WestPanel.setPreferredSize(new Dimension(100,10));
              NorthPanel.setPreferredSize(new Dimension(10,100));
              SouthPanel.setPreferredSize(new Dimension(10,100));
              //CenterPanel.setPreferredSize(new Dimension(200,200));
              //Adding Color to the Panels
              NorthPanel.setBackground(Color.green);
              SouthPanel.setBackground(Color.orange);
              CenterPanel.setBackground(Color.black);
              //Creating Border For Different Side
              Border EastBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
              Border WestBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
              Border NorthBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
              Border SouthBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
              Border CenterBr = javax.swing.BorderFactory.createEtchedBorder(Color.cyan, Color.red);
              //Creating Components For East Panel
              JLabel left= new JLabel("LEFT");
              JLabel right= new JLabel("RIGHT");
              JLabel rotate= new JLabel("ROTATE");
              left.setForeground(Color.blue);
              right.setForeground(Color.blue);
              rotate.setForeground(Color.blue);
              //Creating Components For West Panel
              ButtonGroup group = new ButtonGroup();
              JRadioButton rb1 = new JRadioButton("Pink",false);
              JRadioButton rb2 = new JRadioButton("Cyan",false);
              JRadioButton rb3 = new JRadioButton("Orange",false);
              JRadioButton _default = new JRadioButton("Black",true);
              rb1.setForeground(Color.pink);
              rb2.setForeground(Color.cyan);
              rb3.setForeground(Color.orange);
              _default.setForeground(Color.black);
              //Creating Components For North Panel
              JLabel name= new JLabel("Santanu Tripathy");
              name.setForeground(Color.blue);
              name.setFont(new Font("Serif",Font.BOLD,30));
              //Creating Components For South Panel
              start = new JButton();
              stop = new JButton();
              exit = new JButton();
              start.setToolTipText("Click this button to start the game");
              start.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
              start.setText("START");
              start.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
              start.setMaximumSize(new java.awt.Dimension(90, 35));
              start.setMinimumSize(new java.awt.Dimension(90, 35));
              start.setPreferredSize(new java.awt.Dimension(95, 35));
              if(paused)
                   stop.setToolTipText("Click this button to pause the game");
              else
                   stop.setToolTipText("Click this button to resume the game");
              stop.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
              stop.setText("PAUSE");
              stop.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
              stop.setMaximumSize(new java.awt.Dimension(90, 35));
              stop.setMinimumSize(new java.awt.Dimension(90, 35));
              stop.setPreferredSize(new java.awt.Dimension(95, 35));
              exit.setToolTipText("Click this button to exit from the game");
              exit.setFont(new java.awt.Font("Trebuchet MS", 0, 12));
              exit.setText("EXIT");
              exit.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 3, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
              exit.setMaximumSize(new java.awt.Dimension(90, 35));
              exit.setMinimumSize(new java.awt.Dimension(90, 35));
              exit.setPreferredSize(new java.awt.Dimension(95, 35));
              //Adding some extra things to the Panels
              group.add(rb1);
              group.add(rb2);
              group.add(rb3);
              group.add(_default);
              //Adding Component into the Panels
              EastPanel.add(left);
              EastPanel.add(right);
              EastPanel.add(rotate);
              WestPanel.add(rb1);
              WestPanel.add(rb2);
              WestPanel.add(rb3);
              WestPanel.add(_default);
              NorthPanel.add(name);
              SouthPanel.add(start);
              SouthPanel.add(stop);
              SouthPanel.add(exit);
              //Adding Border Into the Panels
              EastPanel.setBorder(EastBr);
              WestPanel.setBorder(WestBr);
              NorthPanel.setBorder(NorthBr);
              SouthPanel.setBorder(SouthBr);
              CenterPanel.setBorder(CenterBr);
              //Adding Panels into the Container
              EastPanel.setLayout(new GridLayout(0,1));
              contentpane.add(EastPanel,BorderLayout.EAST);
              WestPanel.setLayout(new GridLayout(0,1));
              contentpane.add(WestPanel,BorderLayout.WEST);
              contentpane.add(NorthPanel,BorderLayout.NORTH);
              contentpane.add(SouthPanel,BorderLayout.SOUTH);
              contentpane.add(CenterPanel,BorderLayout.CENTER);
              //Adding Action Listeners
              rb1.addActionListener(this);
              rb2.addActionListener(this);
              rb3.addActionListener(this);
              _default.addActionListener(this);
              exit.addActionListener(this);
              start.addActionListener(this);
    try
              start.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
                        start.setEnabled(false);
    CenterPanel.drawCircle();
    catch(Exception e)
    {System.out.println("Exception is attached with sart button exp = "+e);}
    try
              stop.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
                        paused=!paused;
                        if(paused)
                             start.setToolTipText("Click this button to resume the game");
                             stop.setText("RESUME");
                        else
                             start.setToolTipText("Click this button to pause the game");
                             stop.setText("PAUSE");
    CenterPanel.pause();
    catch(Exception e)
    {System.out.println("Exception is attached with sart button exp = "+e);}
         public void DefaultColorSet()
              getContentPane().setBackground(Color.white);
         public void actionPerformed(ActionEvent AE)
              String str=(String)AE.getActionCommand();
              if(str.equalsIgnoreCase("pink"))
                   CenterPanel.setBackground(Color.pink);
              if(str.equalsIgnoreCase("cyan"))
                   CenterPanel.setBackground(Color.cyan);
              if(str.equalsIgnoreCase("orange"))
                   CenterPanel.setBackground(Color.orange);
              if(str.equalsIgnoreCase("black"))
                   CenterPanel.setBackground(Color.black);
              if(str.equalsIgnoreCase("exit"))
                   System.exit(0);
         public void keyTyped(KeyEvent kevt)
    //repaint();
    public void keyPressed(KeyEvent e)
              System.out.println("here key pressed");
              //CenterPanel.dec();
         public void keyReleased(KeyEvent ke) {}
    }//End of FrameShow.ja
    //IncludePanel.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.Graphics.*;
    import java.awt.Dimension;
    import java.awt.geom.Dimension2D;
    import java.util.*;
    import java.util.logging.Level;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    public class IncludePanel extends JPanel implements Runnable
    int x=0,y=0;
    int color_1=0;
    int color_2=1;
    int start=0;
    Thread th;
    Image red,blue,green,yellow;
    java.util.List image;
    static boolean PAUSE=false;
         public IncludePanel()
         red= Toolkit.getDefaultToolkit().getImage("red.png");
         blue= Toolkit.getDefaultToolkit().getImage("blue.png");
         green= Toolkit.getDefaultToolkit().getImage("green.png");
         yellow= Toolkit.getDefaultToolkit().getImage("yellow.png");
    public void paintComponent(Graphics g)
              super.paintComponent(g);
              draw(g);
    public void dec()
         System.out.println("in dec method");
         x=x+30;
    public void draw(Graphics g)
              g.setColor(Color.red);
              int xx=0,yy=0;
              for (int row=0;row<=12;row++)
                   g.drawLine(xx,yy,180,yy);
                   yy=yy+30;
              xx=0;
              yy=0;
              for (int col=0;col<=6;col++)
                   g.drawLine(xx,yy,xx,360);
                   xx=xx+30;
              if(color_1==0)
                   g.drawImage(red, x, y, this);
              else if(color_1==1)
                   g.drawImage(blue,x, y, this);
              else if(color_1==2)
                   g.drawImage(green,x,y, this);
              else if(color_1==3)
                   g.drawImage(yellow,x,y, this);
    x=x+30;
              if(color_2==0)
                   g.drawImage(red, x, y, this);
              else if(color_2==1)
                   g.drawImage(blue,x,y, this);
              else if(color_2==2)
                   g.drawImage(green,x,y, this);
              else if(color_2==3)
                   g.drawImage(yellow,x,y, this);
    x=0;
    public void drawCircle( )
         th=new Thread(this);
         th.start();
         public void pause()
              if(PAUSE)
                   th.resume();
                   PAUSE=false;
                   return;
              if(!PAUSE)
              PAUSE=true;
         public synchronized void run()
              Random rand = new Random();
              Thread ani=Thread.currentThread();
              while(ani==th)
                   if(PAUSE)
                        th.suspend();
                   if(y==330)
                        color_1 = Math.abs(rand.nextInt())%4;
                        color_2 = Math.abs(rand.nextInt())%4;
                        if(color_1==color_2)
                             color_2=(color_2+1)%4;
                        y=0;
                   else
                        y=y+30;
                   repaint();
                   try
                        Thread.sleep(700);
                   catch(Exception e)
         }//End of run
    i sent two entire program

  • Is it possible to create a thread and run it in background in nokia ??

    Is it possible to create a thread and run it in background in nokia series 40 mobile phones using j2me ??

    Probably a good question for ForumNokia. If you mean start up a thread and run in the background while your MIDlet UI does other things, then sure, why not. If you mean that you want to exit your MIDlet, but leave a thread running in the background, then I don't believe you can do this on series 40. S60 is another story since it supports multiple tasks.

  • Limited subject characters count when creating a new thread in Portal 7.3 forums

    Hello,
    i was wondering if and how you can change the max. characters for the subject when creating a new thread in Portal 7.3 forums.
    It seems like the character count is limited to 75 characters for subjects.
    I didn't find any suitable property, in the forums admin console, for that issue.
    Thanks

    Hi Andrzej,
    Have faced a similar issue in EP 7.01. It was due to the missing Super Admin access - Save was clocking & timing out.
    Upgraded the Admin permissions and this issue was resolved.
    Hope this helps.

  • Does JDialog setVisible create a new threaD?

    I am having a problem with my program and it seems that it may be because my call to JDialog setVisible is creating a new thread. In my program I have a JDialog which is a creation wizard that puts some specific files in the specified directory. After this is done I try and zip up the contents and bundle the zip file with some other files. My problem is that if I don't place a dialog after my call JDialog setVisible() then not all the right files will be in the newly created zip. It seems to me this is likely happening because the call to setVisible is creating a new thread and operation is continuing before the wizard is done placing all the right files in the directory. Does this make sense? Does setVisible create its own thread?

    In the future Swing related questions should be posted in the Swing forum.
    No a new thread is not created. setVisible() displays the dialog. If the dialog is modal then statements after the setVisibile are not executed until the dialog is closed. If the dialog is not modal, then the statements execute right away.

  • Program freezes when a thread is run in another class.

    I have a class that extends Thread, and then I have a GUI that needs this thread.
    The thread class looks like this:
    public class ScoreboardCheck extends Thread
        private int clock;
        private boolean running;
        public ScoreboardCheck(int timeOnClock)
            super();
            this.clock = timeOnClock;
            running = false;
        public int getClock()
            return this.clock;
        public void toggleRunning()
            if (running == false)
                running = true;
            else
                running = false;
        public void run()
            while (Thread.currentThread() == this)
                if (running == true)
                    try
                        Thread.sleep(1000);
                        clock--;
                    catch(InterruptedException ie)
                        ie.printStackTrace();
    }This is suppose to update the clock on the GUI. I instantiate the thread in the GUI class, and call start on it. This works fine, but whenever I call run, it freezes up....Either way it never does anything.
    In the GUI class, how am I suppose to continously update the clock without this thing freezing up? I've tried implementing runnable in the GUI class, but that didn't work.

    Thanks for the replies, guys.
    When I call start it doesn't freeze. That's good. The only other problem I'm faced with, is updating the GUI probably every second. I've tried using a run method in the GUI which runs while true, but that froze things up....This is the point I'm stuck at. For now, I'm going to try what someone suggested: the Timer class. Is there another way of doing this though? Without the timer?

  • How Many Threads inside JVm while running

    Hi,
    how many threads will be there in jvm of 1.4 or higher sdk? threads i mean it includes all jvm threads also.

    How do you identify these threads?
    I can see 8 threads in my 1.5 java process (just running a main) using windows XP task manager, but when I check how many threads there are from within the code, it only looks like 4:
    java.lang.ThreadGroup[name=system,maxpri=10]
    Thread[Reference Handler,10,system]
    Thread[Finalizer,8,system]
    Thread[Signal Dispatcher,9,system]
    java.lang.ThreadGroup[name=main,maxpri=10]
    Thread[main,5,main]
    For example, using
    Thread.currentThread().getThreadGroup().getParent().list();

  • How to deal with the mouse events when the thread is running

    Hi everybody,
    I have a problem with my program.
    Now I want to present a picture for some time in the Canvas,then automatically clear the screen, but when the user press the mousebutton or keybutton, I want to stop the thread and clear the screen.
    How can I receive the mouse event when the thread is running?
    Thanks,

    I use my code in a GUI applet.
    I try to use the code tag, it's the first time.
                   Image im=sd.getStimulus(obj);
                   if(pos==null){
                        g.drawImage(im, (w-im.getWidth(null))/2,(h-im.getHeight(null))/2,null);
                   }else{
                        g.drawImage(im, pos.x,pos.y,pos.w,pos.h,null);
                   try{
                        sleep(showtime);
    //                    Thread.sleep(showtime);
                   }catch(InterruptedException e){}
                   if(pos==null){
                        g.clearRect((w-im.getWidth(null))/2,(h-im.getHeight(null))/2,im.getWidth(null),im.getHeight(null));
                   }else{
                        g.clearRect(pos.x,pos.y, pos.w, pos.h);
                   }

  • Can a thread created in an applet still run after the browser is closed?

    Dear all,
    I was able to make an applet's thread keep running even the web page changed to other page. Is it possible to make a thread spawned by an applet keep running even if the browser is close? I am using signed applet and JRE1.3.1_02. Thank for answer.
    [email protected]
    Arthur Pan

    No. A thread is part of a process and if the browser closes that process will (generally) be destroyed.

Maybe you are looking for

  • Error in Sales order, missing order reason

    Hi All,   We are trying to create a sales order in the CRM Mobile Client and we see the following error. mandatory check failed for order reason(reason for business transaction) of the business object sales transaction. Any ideas on how to resolve th

  • ABAP Objects Design/Organization Issues

    Hi, I'm trying to design and implement reusable components using ABAP Objects. I'm familliar with OO concepts and have developed a few applications using C++ and Java. I'm trying to organize my classes into separate source files (include program in A

  • Import from 20 MB powerpoint file yields gigantic 1.4 GB file!

    Hi folks, I imported a 20 MB file from powerpoint and made it a little bit prettier in keynote, then saved it, only to find that I had inadvertantly created a 1.4 GB file! There are very few transitions, no movies or audio, so I don't know why the fi

  • Idvd help

    Why won't my dvd play continuously on the idvd movie I just made? After every clip it goes back to the title menu...

  • Facebook problem in new feed

    Plz fix the problem in newfeed wont,t get new feed Plz fix it