can we exit from Java application automatically ?

[nobr]HI friends,

i have a requirement that is........

program controller should exit from the application, when u run this program at command prompt.

And user must not use System.exit(1) method in the loop

OR the user shouldnt give any DOS command like CTRL+C,

becoz the controller must exit automatically.

plz help me if any body can do this.

code is here..........

\\

import java.awt.*;

import javax.swing.*;

import java.util.*;

publicclass CustomDialogextends JPanel{

JFrame frame;

public JDialog dialog;

java.util.Timer schedulerTimer;

public CustomDialog(){

dialog =new JDialog(frame,"");

JLabel label =new JLabel("<html><p align=center>"

+"High Speed Transmission is .<br>"

+"going to take place ");

label.setHorizontalAlignment(JLabel.CENTER);

Font font = label.getFont();

label.setFont(label.getFont().deriveFont(font.PLAIN,14.0f));

label.setForeground(Color.black);

JPanel contentPane =new JPanel(new BorderLayout());

contentPane.add(label, BorderLayout.CENTER);

contentPane.setOpaque(true);

dialog.setContentPane(contentPane);

dialog.setSize(new Dimension(300, 150));

dialog.setLocationRelativeTo(frame);

dialog.setVisible(true);

schedulerTimer =new java.util.Timer();

schedulerTimer.schedule(new SchedulerTask(),5*1000, 10*1000);

}

publicstaticvoid main(String args[]){

new CustomDialog().m2();

}

void m2(){

for(int i=0;i<=50000;i++){

System.out.println("success"+i);

}

}

class SchedulerTaskextends TimerTask{

publicvoid run(){

schedulerTimer.cancel();

dialog.setVisible(false);

dialog=null;

frame=null;

}

}

}

[/nobr]

[3410 byte] By [HamsRajasa] at [2007-11-26 22:15:41]
# 1

That code is bonkers.

What are you trying to do? You're extending JPanel for seemingly no purpose, using a JFrame reference you never assign, dumping 50000 lines of text to the console, running nothing on the EDT, using a dialog without a frame, not disposing the dialog, and just sweeping the UI away after a delay.

Are you trying to write something usable or can you do the decency of copying out whatever bizarre homework assignment it is you're trying to do?

itchyscratchya at 2007-7-10 11:08:11 > top of Java-index,Desktop,Core GUI APIs...
# 2

HI friend,

actually the code is part of my project,

i should come out from the application when the condition is false inloop.

actually this part of code is linked with one module, iam unable to send the whole code,could u help me to solve this probelm.

Run this code @ command prompt, and see the application didn't exit automatically, user sholud exit from the application by giving DOS command like CTRL+C. OR in the loop we can put System.exit(1).

with out user interference, the application should exit automatically.

Thanx in advance

HamsRajasa at 2007-7-10 11:08:11 > top of Java-index,Desktop,Core GUI APIs...