Preventing System.exit()
I've written a class loader that executes .jar files across a network from a central application. Works great - except when one of those jar files calls a System.exit().
Since the purpose of this application is to have several applications "executing" across a network, having one of them call System.exit() kills all of them. Are there any methods of scanning the class files as they are being loaded and having code replaced? For example, searching for System.exit(someInt) or even JFrame.EXIT_ON_CLOSE and then replacing this bytecode with some more acceptable bytecode that instructs the parent program the child wishes to terminate?
Rewriting all of the programs to be loaded so that they don't call System.exit() or its variations isn't an option here, so I'm open to any suggestions.
BTW: Overriding system libraries is against
standards, but does work.
http://java.sun.com/j2se/1.4.2/docs/guide/standards/
In java.lang.Runtime
public void exit(int status) {
throw new Error("Exit called with
led with status="+status);
}Create a jar and copy it to <java_home>/lib/endorsed
The run the following
public class Main {
public static void main(String[] args) {
System.exit(1);
}And you will get the follow when run with this
"modified" JRE
"C:\Program Files\Java\jre1.6.0\bin"\java -cp .Main
Exception in thread "main" java.lang.Error: Exit
called with status=1
at java.lang.Runtime.exit(Runtime.java:86)
at java.lang.System.exit(Unknown Source)
at Main.main(Main.java:11)
Yes, but then it works only on your machine.
Similar Messages
-
Prevent System.exit(0)
Hi Everybody!
I have the following problem.
I am developing an web-application running on a Tomcat server.
Furthermore I am using some additional libraries, from which I only have the class-files. Nevertheless I decompiled them and found, that one method calls a System.exit(0) in its catch block, and this is horrible, because the server always shuts down in case of failure.
What shall i do to prevent this? Altering the library will not be possible. Any ideas?
I created a small example to point out my problem:
public class Testing {
private void methodA(String s) {
try {
int i = Integer.parseInt(s);
System.out.println("Value of i: " +i);
Thread.sleep(1000);
catch (Exception e) {
e.printStackTrace();
System.exit(0);
} //methodA
public static void main(String[] args) {
Testing t = new Testing();
for (int i = 0; i < 10; i++) {
if (i == 5)
t.methodA("a");
else
t.methodA(String.valueOf(i));
} //for
}Just think of methodA() as an method that can not be altered... How can I force the for-loop to continue when methodA() fails?
(This is not my actual problem, but it points out my problem... ;)
Thanks in Advance!
StefI was able to solve the problem by using the following code :-
final SecurityManager securityManager = new SecurityManager()
public void checkPermission(Permission permission)
//This Prevents the shutting down of JVM.(in case of System.exit())
if ("exitVM".equals(permission.getName()))
throw new SecurityException("System.exit attempted and blocked.");
System.setSecurityManager(securityManager);
Hope it helps some one ..................... ;) -
Catch/Prevent System.exit call in other thread
Wasn't sure where to put this so apologies if this is in the wrong section.
I have an application that runs a particular method contained in a JAR that is written/provided by somebody else (they implement an interface I provide). They have complete free range as to what their application does. I then run this application in a separate thread, the idea being that when it completes my original application is still running.
What I have provided so far is ok PROVIDED that the given JAR does not perform a System.exit call which is very possible. I want to prevent them from doing this but I don't want to contacting the author asking them to remove all invokations of System.exit.
I found this article: https://www.securecoding.cert.org/confluence/display/java/EXC04-J.+Prevent+against+inadvertent+calls+to+System.exit%28%29+or+forced+shutdown and so I tried to create my own SecurityManager. Unfortunately though despite explicitly putting the running of the applicaiton in a catch block for AccessControlException it doesn't catch it and fails. Does anybody have an idea of how to overcome this.
In summary: how can I prevent a call to System.exit being invoked (or when it is invoked, catch it and prevent it from actually happening) inside another thread?batterj2 wrote:
I was unable to do any File I/O afterwards which seems strange as its extending the original SecurityManager so I thought it wouldn't have any difference.No, that code isn't "extending the original SecurityManager". It's creating a SecurityManager which overrides some SecurityManager which may or may not be the same as the actual SecurityManager which was in place when you applied it. From what you say, it's not the same.
Remember you don't extend objects, you extend classes.
You could write something which gets a link to the current security manager, then delegates all calls to that security manager except the ones you don't want to delegate. -
How to track System.exit(0) call
hi there,
how can i trace the System.exit(0) function call in my program.
i.e as we know which class is being loaded into the jvm by overriding
the classloader, can we similarly know when is our jvm going to be
destroyed. here iam invoking jvm from my windows program using invocation api.
any help is mostly appreciated.
thanks in advance
bye
ramanaNot sure I know what you are asking.
You could create a security manager which prevents exit() from being called.
You could replace System using the bootstrap command line option. Although if you do that you can not distribute it due to the license agreement. Once replaced you can do anything you want in the application.
You could use Runtime.addShutdownHook() if you just want to do something when the application exits. -
Is System.exit() a good call to use?
I have a program that checks for updates in the db. If there are no updates in the database I want the program to stop. There are also many other conditions that would cause the program to stop. None of them are "Errors" so I wasn't using Exceptions to end the program The program runs from a command line or from chron job. Is it safe / OK to use System.exit() to do this?
As you describe it, I'd say yes. System.exit() is the way to end your program.
The danger of System.exit() is if a class you write will be reused in some other system. In that case, System.exit() could be entirely inappropriate in that context, thus preventing your class from being reusable.
If you only call System.exit() in your main() method, you'll probably be OK. -
Hi
Has anyone come across how Opera handles Java?
I am suffering an issue to prevent frequent-refreshing pages, every time when quits a page, the applet will call System.exit.
It works fine in IE and FF but in Opera, the browser shuts down!
What happen? Due to cross browser development, need it to work in Opera!
Thanks for kind suggestionAn applet should never call System.exit because this method terminates the currently running Java Virtual Machine but an Applet can't do that. You should use stop or destroy method. Take a look at this:
http://java.sun.com/javase/6/docs/api/java/applet/Applet.html#destroy()Regards -
To trap System.exit(0)
Hi All,
In one of our code we are saying System.exit(0),System.exit(1),System.exit(-1) based on certain condition that occur in the program. Could any one let us know how to trap the integer returned to the OS when System.exit(x) is called.
Regards,
VinodramuNot sure I know what you are asking.
You could create a security manager which prevents exit() from being called.
You could replace System using the bootstrap command line option. Although if you do that you can not distribute it due to the license agreement. Once replaced you can do anything you want in the application.
You could use Runtime.addShutdownHook() if you just want to do something when the application exits. -
Denying Thread calling System.exit() successfully
Hi all,
i start another java app from within my code by calling it's main()-method in an own thread.
As i don't have any access to the code of the java app i can't prevent it from calling System.exit() when the corresponding window is closed.
How can i prevent the "threaded" java app from also closing my wrapping application when it is finished?
Greetings,
BernhardYou can install a security manager (your own) in your application and override the method checkExit(int status) in order to handle the event:
class OwnSecurityManager extends SecurityManager{
public void checkExit(int code){
if(code == 1){
super.checkExit(code);
throw new SecurityException("Not allowed here"); //or your handling code
}else{
//other codes
//in your app you install the manager like this
SecurityManager s = new OwnManager();
System.setSecurityManager(s); -
Trapping System.exit() calls
Hey folks. I'm wondering if anyone has a best practice for trapping System.exit() calls in managed applications that are running in a a single MBeanServer. In our design, there is a single VM that runs the MBeanServer and any loaded applications. If any loaded application (MBean) uses a System.exit() call, this will bring down the entire agent. We've put some preventative code into a custom SecurityManger to at least catch the exit call and automatically restart the agent, but I'm figuring there is a better way to do this.
We're making it a best practice to NOT use System.exit() in any JMX-managed applications that will run inside our agent and rather use Thread termination code. Has anyone run into these same issues? If you look at the JMX Server example in the Sun JMX tutorial, if I throw a System.exit() call into one of the sample MBeans, the server will die.
As I was perusing a local bookstore, I thumbed through a JMX book that had some example code in it, and in their "Server" example code, they have a shutdown and a startup method. In the shutdown method there is a System.exit() call, which, in my understanding, will bring down the agent. How, then, could you call startup() on an agent that isn't running?
Are these designs assuming that the MBean server is running under J2EE application server like WebLogic or WebSphere?
Any thoughts would be much appreciated. Thanks.
-Philthe int you pass to System.exit is returned by the JVM...... (I think, I forget........)
Generally use 0 to signify "normal" exit
Generally use 1 to signify an "abnormal" exit (so you terminated the program (using exit) becuase you couldn't handle the exception nicely)
So you can use the return value to "monitor" your program...... it's an old concept, C programmers use it all the time.... -
Why in COM, set smth true, stays true even after System.exit?
I am using "Jacob" to do COM calls. When I alter the "ShowAll" property of Word.Application and I set it to true, it will then forever be true even if I exit the application AND quit the word application. If I set it to false, the same thing happens, it will always be so. The code to call/set this is:
(NOTE: This uses classes I made to wrap the Dispatch calls)
Word wordApp = new Word();
Documents docs = wordApp.getDocuments();
Document doc = docs.open("D:\\JavaProjects\\Test.doc");
//GET VIEW
View wordView = wordApp.getActiveWindow().getView();
//PRINT THE VIEW PROPERTIES
System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
//SET THE VIEW PROPERTIES
wordView.setShowAll(false);
wordView.setShowParagraphs(true);
//PRINT THEM AGAIN
System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
doc.close(Document.DO_NOT_SAVE);
wordApp.quit(new Variant[] {});
System.exit(0);The actual Dispatch calls are:
//NO IDEA WHY THIS IS, BUT SHOWALL = TRUE IS -1, AND FALSE IS 0
private final static int SHOW_ALL_TRUE = -1;
private final static int SHOW_ALL_FALSE = 0;
/** SETSHOWPARAGRAPHS **
* Sets the property (boolean) ShowParagraphs.
public void setShowParagraphs(boolean showParagraphs)
Dispatch.put(this, "ShowParagraphs", new Boolean(showParagraphs));
/** ISSHOWPARAGRAPHS **
* Returns Boolean of whether or not this is set to show paragraphs.
public boolean isShowParagraphs()
return getBooleanValue(Dispatch.get(this, "ShowParagraphs"));
private boolean getBooleanValue(Variant variantBoolean)
//MAKE IT AN INTEGER AND GET ITS int VALUE
int intVariant = new Integer(variantBoolean.toString()).intValue();
//RETURN IF IS SHOW ALL
return (intVariant == View.SHOW_ALL_TRUE);
}I'm wondering if the problem is that I get back either -1 or 0 and if maybe that means something else?1: Properties persistence is not a DEFECT but a FEATURE . It was implemented in MS Word so users could change MS word WITHOUT HAVING TO DO IT EACH TIME THEY START IT UP.
2: Don't you intialise all your variables in your code after you instanciated them ? I am sure you do so and therefore the persitence feature you described should not be annoying you at all. It is not necessary to intialise variables in the BASIC langage but that does not mean you should not do it.
3: (-1) was chosen arbitrary by Microsoft as the TRUE value for Boolean datatype and 0 the value for FALSE when they designed Visual Basic. This is not a problem if you write code properly
I recommend you test bool variable in any langages using the following test:
(myBool <> 0)
HAVE A THINK ABOUT IT
Finally,
you need to understand what you are working with before you complain about it.
Argument for Argument sake is not good and if you think MS word is a bad program just don't use it. go and write your own word processor in JAVA.
GOOD LUCK
I WISH TO APOLOGISE FOR ANY POSSIBLE SPELLING OR GRAMMATICAL MISTAKES I COULD HAVE MADE IN THIS REPLY. ENGLISH NOT BEING MY FIRST LANGUAGE. -
Denying system.exit in java code
My objective is to nullifying the system.exit programmed. By goggling i learn t that this can be done by adding permission in policy file. But as far my google search i dont understand how to deny a permission. Most of them says about granting a permission. Can anyone clarify how to deny a permission.
Steps i tried.
Sample program: which does nothing other than calling system.exit(0) as the first line in main method.
added the following line to java.policy file in my JAVA_HOME/jre/lib/security
grant {
permission java.lang.RuntimePermission "exitVM";
Also tried adding only
permission java.lang.RuntimePermission "exitVM";
to the already available grant block.
Also commented out
//grant codeBase "file:${java.home}/lib/ext/*" {
// permission java.security.AllPermission;
After that i understood that the default java policy file is java.home\lib\security\java.policy. So made all the change above mentioned there too.
But i could not achieve it. Can any one help me on this.
Win 2000/ Java1.4.2_12/no command line arguments while running the program.Welcome to the Forums.
Please go through the FAQ of the Forum.
You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
Please try {forum:id=1050}.
Regards, -
The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL
Hi
We are using SRM 5.0. We are facing a strange problem. We are able to see the initial screen of SRM EBP in the browser. But once the user name and password are provided the system goes for a dump with the following error:
The following error text was processed in the system SS0 : System error
The error occurred on the application server <Server Name> and in the work process 0 .
The termination type was: ABORT_MESSAGE_STATE
The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL
<b>SM21 Log:</b>
Short Text
Transaction Canceled &9&9&5 ( &a &b &c &d &e &f &g &h &i )
The transaction has been terminated. This may be caused by a
termination message from the application (MESSAGE Axxx) or by an error
detected by the SAP System due to which it makes no sense to proceed
with the transaction. The actual reason for the termination is
indicated by the T100 message and the parameters.
Transaction Canceled ITS_P 001 ( )
Message Id: ITS_P
Message No: 001
I just checked these threads but did not help much,
RABAX_STATE error after loggin into BBPSTART service in SRM 4.
ITS_TEMPLATE_NOT_FOUND error
Besides I tried this note: 790727 as well, still I get the same error.
Any help would be highly appreciated.
Thanks in advance
Kathirvel BalakrishnanHi
<u>Please do the following steps.</u>
<b>When you are using the Internal ITS,you need not run the report W3_PUBLISH_SERVICES.(only SIAC_PUBLISH_ALL_INT )
ALso pls check the foll:
-->activate the services through SICF tcode.
> Go to SICF transaction and activate the whole tree under the node Default host>sap>bc>gui>sap>its.
>Also maintain the settings in SE80>utilities>settings>internet transaction server-->test service/Publish. (BBPSTART , BBPGLOBAL etc)
Table TWPURLSVR should have entries for the / SRM server line as well as gui and web server.
Could you please review again the following steps ?
Did you check that ICM was working correctly (Transaction - SMICM) ?
1-Activate the necessary ICF services
With transaction SICF and locate the
services by path
/sap/public/bc/its/mimes
/sap/bc/gui/sap/its/webgui
2- Publish the IAC Services
With Transaction SE80 locate from
the menu Utilities -> Settings ->
Internet Transaction Server (Tab) ->
Publish (Tab) and set On Selected
Site = INTERNAL.
3- Locate the Internet Services SYSTEM and WEBGUI.
Publish these services with the Context
Menu -> Publish -> Complete Service
4- Browse to http://<server>:<icmport>/sap/bc/gui/
sap/its/webgui/! and login to the
webgui.</b>
Hope this will help.
Please reward suitable points.
Regards
- Atul -
System.exit doesnt work on Sun OS 5.7 ??
Hi, I have encountered a kind of wierd problem. I have a small application that uses System.exit when the user wants to shut down the application.
That works fine in Windows but in Sun OS 5.7 the application just freeze.
Im using java version:
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
Would be greatful if someone could help me.
This code is an small example of my application.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ExitTest extends JFrame implements ActionListener {
JButton jButton1 = new JButton();
public ExitTest() {
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
public static void main(String[] args) {
new ExitTest().setVisible(true);
private void jbInit() throws Exception {
jButton1.setText("Exit");
jButton1.addActionListener(this);
addWindowListener(this);
this.getContentPane().add(jButton1, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e) {
this.setVisible(false);
System.out.println("Exiting");
try {
System.exit(0);
} catch(SecurityException ex) {
ex.printStackTrace();
---------------------------------------------------------------------------------------------------------Hmm, sorry about that, my misstake, that line is still there from an erlier attempt to use windowlisteners instead ... that line should not be there ...
-
System.exit(0) closing both JFrames
hey, ive got a problem with a JFrame
Ive got 1 JFrame that currently holds a JMenuBar, 2 JMenus and in the 1st JMenu there are 4 JMenuItems.
One of the JMenuItems uses an ActionListener to lauch another JFrame, but when the 2nd JFrame is finished (and System.exit(0) launches), the first JFrame closes as well. What is going on??
code follows:
THE MAIN JFRAME
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class realframe extends JFrame
protected JMenuItem[] m_fontMenus;
protected JCheckBoxMenuItem m_showPatList;
protected JCheckBoxMenuItem m_showPatData;
protected JCheckBoxMenuItem m_showHRGraph;
protected JCheckBoxMenuItem m_showBPGraph;
protected JCheckBoxMenuItem m_showTempGraph;
public realframe(){
super("PMS Menu GUI");
setSize(450, 350);
JMenuBar menuBar = createMenuBar();
setJMenuBar(menuBar);
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
addWindowListener(wndCloser);
setVisible(true);
//start Menus
protected JMenuBar createMenuBar()
final JMenuBar menuBar = new JMenuBar();
//creates File
JMenu mFile = new JMenu("File");
//Menu 1 item 1 : : : Add Patient
JMenuItem item = new JMenuItem("Add Patient");
ActionListener lst = new ActionListener() //ActionListener for Add Patient
public void actionPerformed(ActionEvent e)
new realgui( new JFrame() );
item.addActionListener(lst);
mFile.add(item);
//Menu 1 item 2 : : : Delete Patient
item = new JMenuItem("Delete Patient");
lst = new ActionListener()
public void actionPerformed(ActionEvent e) { }
item.addActionListener(lst);
mFile.add(item);
//Menu 1 item 3 : : : Search
item = new JMenuItem("Search");
lst = new ActionListener()
public void actionPerformed(ActionEvent e) { }
item.addActionListener(lst);
mFile.add(item);
//Divider
mFile.addSeparator();
//Menu 1 item 4 : : : Exit
item = new JMenuItem("Exit");
item.setMnemonic('x');
lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
item.addActionListener(lst);
mFile.add(item);
menuBar.add(mFile);
//end menu item 1
ActionListener viewListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateMonitor();
JMenu mView = new JMenu("View");
mView.setMnemonic('V');
//Menu 2 item 1 : : : Patient List Toggle
m_showPatList = new JCheckBoxMenuItem("Patient List");
m_showPatList.setMnemonic('L');
m_showPatList.setSelected(true);
m_showPatList.addActionListener(viewListener);
mView.add(m_showPatList);
//Menu 2 item 2 : : : Data box Toggle
m_showPatData = new JCheckBoxMenuItem("Patient Data");
m_showPatData.setMnemonic('D');
m_showPatData.setSelected(true);
m_showPatData.addActionListener(viewListener);
mView.add(m_showPatData);
//Divider
mView.addSeparator();
//Menu 2 item 3 : : : HR Graph toggle
m_showHRGraph = new JCheckBoxMenuItem("Show HR Graph");
m_showHRGraph.setMnemonic('H');
m_showHRGraph.setSelected(true);
m_showHRGraph.addActionListener(viewListener);
mView.add(m_showHRGraph);
//menu 2 item 4 : : : BP Graph Toggle
m_showBPGraph = new JCheckBoxMenuItem("Show BP Graph");
m_showBPGraph.setMnemonic('B');
m_showBPGraph.setSelected(true);
m_showBPGraph.addActionListener(viewListener);
mView.add(m_showBPGraph);
//menu 2 item 5 : : : Temp Graph Toggle
m_showTempGraph = new JCheckBoxMenuItem("Show Temp Graph");
m_showTempGraph.setMnemonic('T');
m_showTempGraph.setSelected(true);
m_showTempGraph.addActionListener(viewListener);
mView.add(m_showTempGraph);
menuBar.add(mView); //adds the menu
return menuBar;
protected void updateMonitor() { }
public static void main(String argv[]) { new realframe(); }
THE SECONDARY JFRAME
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class realgui extends JDialog implements ActionListener
JTextField surname;
JTextField given;
JTextField age;
JTextField doctor;
JTextField phone;
Patient patient = new Patient();
JRadioButton radiomale;
JRadioButton radiofemale;
public realgui( JFrame frame )
super( frame, true );
System.out.println("in 1");
setTitle( "Add A New Patient" );
setSize( 400, 250 );
JPanel panel = new JPanel( new BorderLayout() );
panel.setLayout( new GridBagLayout() );
panel.setBorder( new EmptyBorder( new Insets( 5, 5, 5, 5 ) ) );
getContentPane().add( BorderLayout.CENTER, panel );
GridBagConstraints c = new GridBagConstraints();
Dimension shortField = new Dimension( 40, 20 );
Dimension mediumField = new Dimension( 100, 20 );
Dimension longField = new Dimension( 180, 20 );
EmptyBorder border = new EmptyBorder( new Insets( 0, 0, 0, 10 ) );
EmptyBorder border1 = new EmptyBorder( new Insets( 0, 20, 0, 10 ) );
c.insets = new Insets( 2, 2, 2, 2 );
c.anchor = GridBagConstraints.WEST;
JLabel lbl1 = new JLabel( "Surname:" );
lbl1.setBorder( border );
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
panel.add( lbl1, c );
surname = new JTextField();
surname.setPreferredSize( longField );
c.gridx = 1;
c.gridwidth = 3;
panel.add(surname, c );
JLabel lbl7 = new JLabel( "Given Name:" );
lbl7.setBorder( border );
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
panel.add( lbl7, c );
given = new JTextField();
given.setPreferredSize( longField );
c.gridx = 1;
c.gridwidth = 3;
panel.add(given, c );
JLabel lbl2 = new JLabel( "Age:" );
lbl2.setBorder( border );
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
panel.add( lbl2, c );
age = new JTextField();
age.setPreferredSize( shortField );
c.gridx = 1;
c.gridwidth = 3;
panel.add( age, c );
JLabel lbl3 = new JLabel( "Gender:" );
lbl3.setBorder( border );
c.gridx = 0;
c.gridy = 3;
panel.add( lbl3, c );
JPanel radioPanel = new JPanel();
radioPanel.setLayout( new FlowLayout( FlowLayout.LEFT, 5, 0 ) );
ButtonGroup group = new ButtonGroup();
radiomale = new JRadioButton( "Male" );
radiomale.setSelected( true );
group.add(radiomale);
radiofemale = new JRadioButton( "Female" );
group.add(radiofemale);
radioPanel.add(radiomale);
radioPanel.add(radiofemale);
c.gridx = 1;
c.gridwidth = 3;
panel.add( radioPanel, c);
JLabel lbl4 = new JLabel( "Doctor:" );
lbl4.setBorder( border );
c.gridx = 0;
c.gridy = 4;
panel.add( lbl4, c );
doctor = new JTextField();
doctor.setPreferredSize( longField );
c.gridx = 1;
c.gridwidth = 3;
panel.add(doctor, c );
JLabel lbl5 = new JLabel( "Phone Number:" );
lbl5.setBorder( border );
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 1;
panel.add( lbl5, c );
phone = new JTextField();
phone.setPreferredSize( mediumField );
c.gridx = 1;
c.gridwidth = 3;
panel.add(phone, c );
JButton submitBtn = new JButton( "Submit" );
c.gridx = 4;
c.gridy = 0;
c.gridwidth = 1;
c.fill = GridBagConstraints.HORIZONTAL;
panel.add( submitBtn, c );
submitBtn.addActionListener(this);
JButton cancelBtn = new JButton( "Cancel" );
c.gridy = 1;
c.anchor = GridBagConstraints.NORTH; // anchor north
panel.add( cancelBtn, c );
cancelBtn.addActionListener(this);
WindowListener wndCloser = new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
addWindowListener( wndCloser );
setVisible( true );
public static void main( String[] args ) {
new realgui( new JFrame() );
public void actionPerformed(ActionEvent evt)
if (evt.getActionCommand ().equals ("Submit"))
Person person = new Person();
String surnam = surname.getText();
String give = given.getText();
String ag = age.getText();
String docto = doctor.getText();
String phon = phone.getText();
char gende;
if(radiomale.isSelected()==true)
gende = 'M';
else
gende = 'F';
System.out.println("in 2 " + surnam);
person.setSurname(surnam);
person.setGiven(give);
// person.setAge(ag);
person.setDoctor(docto);
person.setPhone(phon);
person.setGender(gende);
System.out.println(surnam + " " + give + " " + ag + " " + gende + " " + docto + " " + phon);
person.setHistory();
patient.add(person);
System.exit(0);No, dispose() is inherited. Just replace System.exit(0); with:
setVisible(false);
dispose();I think that'll work in your code. -
Hello all,
I compiled and ran this program with no problems about 5 or 6 times as soon as I finished writing it. I walked away for about 15 minutes and tryed to run it again. The program runs fine up until the end; now, however, at the System.exit(0); line the system promptly REBOOTS.
I am running windows XP Pro.....
Any ideas as to what may be causing this?
1. Take input from user for how many numbers will be in the array.
2. Allow user to input the values 0ne by one usig for loop and break loop upon reaching
value input from number 1(above).
3. Make class to do linear search
import javax.swing.JOptionPane;
public class LinearSearch
public static void main(String args[]) {
SearchArrayLinear X = new SearchArrayLinear();
String input, input2, input3;
int array[], len, element, key;
input = JOptionPane.showInputDialog(null,
"How many integers do you want to input into the array? ", "INPUT",
JOptionPane.QUESTION_MESSAGE);
len = Integer.parseInt(input);
array = new int[len];
for (int counter = 0; counter < len; counter++)
array[ counter ] = Integer.parseInt( JOptionPane.showInputDialog(null,
"Input index " + counter + " into the array",
"INPUT", JOptionPane.QUESTION_MESSAGE) );
X.linearSearch(array);
class SearchArrayLinear
public void linearSearch( int array2[] ) {
String input = JOptionPane.showInputDialog(null, "Enter the Search key ",
"Search Key Input",
JOptionPane.QUESTION_MESSAGE);
int key = Integer.parseInt(input);
for( int counter = 0; counter < array2.length; counter++)
if (array2[counter] == key) {
JOptionPane.showMessageDialog(null,
"The search key was found in element " +
array2[counter], "RESULT",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
else {
JOptionPane.showMessageDialog(null,
" No element was found for the search key ",
"RESULT",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}Get this. Microsoft says that this is a "Driver problem" and to check the latest installed driver. At first, I didn't think much of it because I havn't installed any drivers or hardware between the time it was working and the time it quit working....or so I thought.
Apparently, one of the Microsoft automatic updates was a new processor driver for XP Pro. Since then, I cannot run any java programs without using JBuilder8. If I do, the computer reboots whenever the program reads the System.exit(*); line.
Looks like Microsoft has found yet another way to sabotage java.
Go figure.
Maybe you are looking for
-
EXCEL out put is not showing data
Hi All, My report is working fine it is showing data in XML but it is not showing data in Excel output. Excel output is empty. i have attached excel and xml files. please help me. FYI: these are migrated reports from 10g to 11g. Thanks in advanc
-
I tried to update my Firefox to version 4 last night. When it was complete, it asked me to restart my computer. After restarting the computer multiple times, I am continuing to get the message when trying to open Firefox. I also cannot uninstall Fire
-
I bought my iPhone 5 almost an year ago and since the last 2 weeks my battery lasts about 2 hours or less, while before it lastre a whole day. Can anybody tell me why is this happening or how can i solve my problem, please? Thank you.
-
hi friends could u pls anybody send the realtim issues of profit center account and internal order and cost center account . [email protected]
-
DB Instance fails to automatically start on cluster reboot
Hello - I cannot get the instance on node1 to automatically start on a reboot. It starts manually, and it starts automatically when the other node is rebooted. I also unregistered it, and re-registered the instance. Here is the errors from $ORA_CRS_H