What I am trying to do is test the values of two variables, and if one is lower than the other then it will display an error message. When the user clicks okay it should return from the error pop-up back to the previous form... When I enter System.exit(0); or break;. it will terminate the program, is there a better syntax ?

My code:

//Declare and initialize variables
        int income = 0;
	int houseCost = 0;

	//Assigns data from text field to variables
	Income = Integer.parseInt(txtIncome.getText());
	houseCost = Integer.parseInt(txtHouseCost.getText());
		
	//Is income less than house cost ?
	if (income < houseCost)
	{
	      JOptionPane.showMessageDialog(null, "Your income is less than your housing cost.", "Error", JOptionPane.ERROR_MESSAGE);
	}

If you're in a method, which you have to be, you could say "return;". I wouldn't worry about it too much if you have a working method though.

If you're in a method, which you have to be, you could say "return;". I wouldn't worry about it too much if you have a working method though.

Ah, thank you ! The only reason I was wondering is because when in this case, income is less than houseCost, it would produce a logic error from insufficient funds to pay for your house and the label in which the answer is output to would be a false answer.

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.