well ... it runs and it shuts down when it has to .

when exactly does it go wrong for you?

well ... it runs and it shuts down when it has to .

when exactly does it go wrong for you?

at first, i ty to input nothing, then the "invalid information" comes out then ill try to put something then, it will run till that "Another transaction" comes out and ill click "no" but it still runs :(

hmmm ... think I may know ... wait a minute, I'll test

hmmm ... think I may know ... wait a minute, I'll test

ok sir...but when i sent that code to my groupmate she said that it runs correctly

OK... I was assuming that you had that problem in the normal flow of the application, now I know where it goes wrong:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

				payroll();
			}

when you have an invalid input there, you re-start the method, but you haven't finished the method yet. so, it will first run the method and if that finishes, it still has to finish the one that was still running.

change your code, like this:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

			//	payroll();
// comment this out, this is what causes your problem
			}
else{
// in this else block, you put the rest of the code
NumberFormat formatter = new DecimalFormat("#.00");

			rh = Integer.parseInt(JOptionPane.showInputDialog("Enter Rate Per Hour:"));

			JOptionPane.showMessageDialog(null, "Name: " + name + "\n\nHome Address:" + add + "\n\nContact:" + contact
					+ "\n\nEmail Address:" + email);

			String want1 = JOptionPane.showInputDialog("How do you want to calculate your rate? \n\nA. Per Hour? "
					+ "\n\nB.Per day? \n\nC.Per week? \n\nD.Per Month? ");

			int total1;

			if (want1.equalsIgnoreCase("A")) {
				h = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of hours:"));
				total = rh * h;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Hour is: " + formatter.format(total) + " PHP");
			}

			else if (want1.equalsIgnoreCase("B")) {
				int day = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of days:"));
				int dd = 8 * day;
				total1 = rh * dd;
				JOptionPane
						.showMessageDialog(null, "Your Total Rate Per Day is:  " + formatter.format(total1) + " PHP");
			} else if (want1.equalsIgnoreCase("C")) {
				int week = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Weeks:"));
				int dd = 56 * week;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Week is:  " + formatter.format(total1)
						+ " PHP");
			} else if (want1.equalsIgnoreCase("D")) {
				int month = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of MOnth:"));
				int dd = 224 * month;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is: " + formatter.format(total1));
			}

			conf = JOptionPane
					.showConfirmDialog(null, "Another Transaction?", "Transaction", JOptionPane.YES_NO_OPTION);
// here, end your else block
}
// and then, end your while block
} while (conf == 0);

try your code like this and see if it works.


}

OK... I was assuming that you had that problem in the normal flow of the application, now I know where it goes wrong:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

				payroll();
			}

when you have an invalid input there, you re-start the method, but you haven't finished the method yet. so, it will first run the method and if that finishes, it still has to finish the one that was still running.

change your code, like this:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

			//	payroll();
// comment this out, this is what causes your problem
			}
else{
// in this else block, you put the rest of the code
NumberFormat formatter = new DecimalFormat("#.00");

			rh = Integer.parseInt(JOptionPane.showInputDialog("Enter Rate Per Hour:"));

			JOptionPane.showMessageDialog(null, "Name: " + name + "\n\nHome Address:" + add + "\n\nContact:" + contact
					+ "\n\nEmail Address:" + email);

			String want1 = JOptionPane.showInputDialog("How do you want to calculate your rate? \n\nA. Per Hour? "
					+ "\n\nB.Per day? \n\nC.Per week? \n\nD.Per Month? ");

			int total1;

			if (want1.equalsIgnoreCase("A")) {
				h = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of hours:"));
				total = rh * h;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Hour is: " + formatter.format(total) + " PHP");
			}

			else if (want1.equalsIgnoreCase("B")) {
				int day = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of days:"));
				int dd = 8 * day;
				total1 = rh * dd;
				JOptionPane
						.showMessageDialog(null, "Your Total Rate Per Day is:  " + formatter.format(total1) + " PHP");
			} else if (want1.equalsIgnoreCase("C")) {
				int week = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Weeks:"));
				int dd = 56 * week;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Week is:  " + formatter.format(total1)
						+ " PHP");
			} else if (want1.equalsIgnoreCase("D")) {
				int month = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of MOnth:"));
				int dd = 224 * month;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is: " + formatter.format(total1));
			}

			conf = JOptionPane
					.showConfirmDialog(null, "Another Transaction?", "Transaction", JOptionPane.YES_NO_OPTION);
// here, end your else block
}
// and then, end your while block
} while (conf == 0);

try your code like this and see if it works.


}

sir what rest of the code? u mean all of the codes??

OK... I was assuming that you had that problem in the normal flow of the application, now I know where it goes wrong:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

				payroll();
			}

when you have an invalid input there, you re-start the method, but you haven't finished the method yet. so, it will first run the method and if that finishes, it still has to finish the one that was still running.

change your code, like this:

if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

			//	payroll();
// comment this out, this is what causes your problem
			}
else{
// in this else block, you put the rest of the code
NumberFormat formatter = new DecimalFormat("#.00");

			rh = Integer.parseInt(JOptionPane.showInputDialog("Enter Rate Per Hour:"));

			JOptionPane.showMessageDialog(null, "Name: " + name + "\n\nHome Address:" + add + "\n\nContact:" + contact
					+ "\n\nEmail Address:" + email);

			String want1 = JOptionPane.showInputDialog("How do you want to calculate your rate? \n\nA. Per Hour? "
					+ "\n\nB.Per day? \n\nC.Per week? \n\nD.Per Month? ");

			int total1;

			if (want1.equalsIgnoreCase("A")) {
				h = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of hours:"));
				total = rh * h;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Hour is: " + formatter.format(total) + " PHP");
			}

			else if (want1.equalsIgnoreCase("B")) {
				int day = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of days:"));
				int dd = 8 * day;
				total1 = rh * dd;
				JOptionPane
						.showMessageDialog(null, "Your Total Rate Per Day is:  " + formatter.format(total1) + " PHP");
			} else if (want1.equalsIgnoreCase("C")) {
				int week = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Weeks:"));
				int dd = 56 * week;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Week is:  " + formatter.format(total1)
						+ " PHP");
			} else if (want1.equalsIgnoreCase("D")) {
				int month = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of MOnth:"));
				int dd = 224 * month;
				total1 = rh * dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is: " + formatter.format(total1));
			}

			conf = JOptionPane
					.showConfirmDialog(null, "Another Transaction?", "Transaction", JOptionPane.YES_NO_OPTION);
// here, end your else block
}
// and then, end your while block
} while (conf == 0);

try your code like this and see if it works.


}

sir how did that happened? wen i put that else that u told me it run correctly and it started from the beginning, how did that happen without calling the method to start from the beginning?

it didn't restart your method, your method was still running. he just looped over everything else, and went straigt to the end of the while loop.
there, he checked the value of conf. since I never gave the possibility to change the value, and the default value of an int = 0, he passed the
while(conf == 0 );
as true, and went to the next run of the while loop

it didn't restart your method, your method was still running. he just looped over everything else, and went straigt to the end of the while loop.
there, he checked the value of conf. since I never gave the possibility to change the value, and the default value of an int = 0, he passed the
while(conf == 0 );
as true, and went to the next run of the while loop

ok sir yes,,, now it runs correctly, remember my problem concerned with adding color on my JOption??? this is what i did:
UIManager um=new UIManager();
um.put("OptionPane.background",Color.black);
um.put("Panel.background",Color.magenta);


that's what i have used but then i keep on getting yellow lines, that means that i have an unused variable, how to i erase those yellow lines?

you get a few of those in your current code too. where did you get those lines with that code? can you show me the complete code the way it is?

weren't you going to try to put this application in a JFrame gui?

you get a few of those in your current code too. where did you get those lines with that code? can you show me the complete code the way it is?

weren't you going to try to put this application in a JFrame gui?

i did some codes with my friend using Jframe, but my groupmates said that, our teacher didnt teach us on making Jframes, thats why we shouldnt do that because for sure the panel will be asking questions that will be hard for us to answer...thats why we switched back to using JOptionPane only, this is my code:

package PAyroll;


import javax.swing.JOptionPane;
import javax.swing.UIManager;

import java.awt.Color;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.UIManager;

public class payrollsystem {

	

	
	public static void main(String[] args){
		  
		 UIManager um=new UIManager();
	       um.put("OptionPane.background",Color.yellow);
	       um.put("Panel.background",Color.yellow);
		  JOptionPane.showMessageDialog(null,"Welcome to online payroll System");
	
		  
		  payroll();
	
	
	
	}



		 public static void payroll(){ 	
			 int conf=0; 
			 
		
			do{ 
				 int YEs =0;
			       String name="";
			       String add= "";
			       String contact= "";
			       String email= "";
			       String want="";
			       String a= "A";
			       String b="B";
			       String c="C";
			       String d="D";
			       String e="E";
			       String f="Q";
			       int rh=0;
			       int h=0;
			       int total=0;
		
			       UIManager um=new UIManager();
			       
			       
			       um.put("OptionPane.messageForeground",Color.white);
			       um.put("OptionPane.background",Color.blue);
			       um.put("Panel.background",Color.pink);      	 
			
	      name = JOptionPane.showInputDialog(null, "Enter Name:");
	      add = JOptionPane.showInputDialog(null,"Enter Address:");
    	  contact = JOptionPane.showInputDialog(null,"Enter contact:");
		  email = JOptionPane.showInputDialog(null,"Enter Email Address:");
		  
		
		  if ( name == null || name.equals("") || add == null || add.equals("") || contact == null || contact.equals("") ||
				  email ==null || email.equals("")){
		  
		  JOptionPane.showMessageDialog(null,"invalid information","Student Enrollment",JOptionPane.PLAIN_MESSAGE);
			  
		
		  }  
		  else{
	
	    	  NumberFormat formatter = new DecimalFormat("#.00");
	  		
	    	  
	    	  um.put("OptionPane.messageForeground",Color.white);
		       um.put("OptionPane.background",Color.pink);
		       um.put("Panel.background",Color.black);      	 
	  
	    	rh = Integer.parseInt(JOptionPane.showInputDialog("Enter Rate Per Hour:"));
		
	      
	         JOptionPane.showMessageDialog(null,"Name: "+name+"\n\nHome Address:"+add+"\n\nContact:"+contact+"\n\nEmail Address:"+email);
			
	      
			String want1 = JOptionPane.showInputDialog("How do you want to calculate your rate? \n\nA. Per Hour? " +
					"\n\nB.Per day? \n\nC.Per week? \n\nD.Per Month? ");
			
			int total1;
	
			if (want1.equalsIgnoreCase("A")){
				h = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of hours:"));
				total= rh*h;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Hour is: "+formatter.format(total)+" PHP");
			}
			
			else if(want1.equalsIgnoreCase("B")){
				int day=Integer.parseInt(JOptionPane.showInputDialog("Enter Number of days:"));
				int dd = 8*day;
				total1= rh*dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is:  "+formatter.format(total1)+" PHP");
			}
			else if(want1.equalsIgnoreCase("C")){
				int week=Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Weeks:"));
				int dd = 56*week;
				total1= rh*dd;
				JOptionPane.showMessageDialog(null, "Your Total Rate Per Week is:  "+formatter.format(total1)+" PHP");
			}
			else if(want1.equalsIgnoreCase("D")){
					int month=Integer.parseInt(JOptionPane.showInputDialog("Enter Number of MOnth:"));
					int dd = 224*month;
					total1= rh*dd;
					JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is: "+formatter.format(total1));	
		    }
		   
		 
		
		conf=JOptionPane.showConfirmDialog(null,"Another Transaction?","Transaction",JOptionPane.YES_NO_OPTION);
		    }
		  }while(conf==0);
	  }
   }

i wonder why there are yellow lines in there

because you are accessing a static method as if it is an instance method.
I'll try to remove all those yellows and show you after.

because you are accessing a static method as if it is an instance method.
I'll try to remove all those yellows and show you after.

ok sir, i saw my classmates program having an OptionDialog withoput using Jframe, can u teach me that?

I changed a bit of your code, for instance, look at where you had:
.equalsIgnoreCase("A")

I've removed all the yellow underlining, I've commented out what you don't need, and I added the reason why. just look it over a bit, and see if you understand it.

import java.awt.Color;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class payrollsystem {

	public static void main(String[] args) {

		// UIManager um = new UIManager(); => you shouldn't instantiate this
		UIManager.put("OptionPane.background", Color.yellow);
		UIManager.put("Panel.background", Color.yellow);
		JOptionPane.showMessageDialog(null, "Welcome to online payroll System");

		payroll();

	}

	public static void payroll() {
		int conf = 0;

		do {
			// int YEs =0; => variable never used
			String name = "";
			String add = "";
			String contact = "";
			String email = "";
			// String want=""; => variable never used
			String a = "A";
			String b = "B";
			String c = "C";
			String d = "D";
			// String e="E"; => value never used
			// String f="Q"; => value never used
			int rh = 0;
			int h = 0;
			int total = 0;

			// UIManager um=new UIManager(); => you don't have to instantiate this

			UIManager.put("OptionPane.messageForeground", Color.white);
			UIManager.put("OptionPane.background", Color.blue);
			UIManager.put("Panel.background", Color.pink);

			name = JOptionPane.showInputDialog(null, "Enter Name:");
			add = JOptionPane.showInputDialog(null, "Enter Address:");
			contact = JOptionPane.showInputDialog(null, "Enter contact:");
			email = JOptionPane.showInputDialog(null, "Enter Email Address:");

			if (name == null || name.equals("") || add == null || add.equals("") || contact == null
					|| contact.equals("") || email == null || email.equals("")) {

				JOptionPane.showMessageDialog(null, "invalid information", "Student Enrollment",
						JOptionPane.PLAIN_MESSAGE);

			} else {

				NumberFormat formatter = new DecimalFormat("#.00");

				UIManager.put("OptionPane.messageForeground", Color.white);
				UIManager.put("OptionPane.background", Color.pink);
				UIManager.put("Panel.background", Color.black);

				rh = Integer.parseInt(JOptionPane.showInputDialog("Enter Rate Per Hour:"));

				JOptionPane.showMessageDialog(null, "Name: " + name + "\n\nHome Address:" + add + "\n\nContact:"
						+ contact + "\n\nEmail Address:" + email);

				String want1 = JOptionPane.showInputDialog("How do you want to calculate your rate? \n\nA. Per Hour? "
						+ "\n\nB.Per day? \n\nC.Per week? \n\nD.Per Month? ");

				int total1;

				if (want1.equalsIgnoreCase(a)) {
					h = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of hours:"));
					total = rh * h;
					JOptionPane.showMessageDialog(null, "Your Total Rate Per Hour is: " + formatter.format(total)
							+ " PHP");
				}

				else if (want1.equalsIgnoreCase(b)) {
					int day = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of days:"));
					int dd = 8 * day;
					total1 = rh * dd;
					JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is:  " + formatter.format(total1)
							+ " PHP");
				} else if (want1.equalsIgnoreCase(c)) {
					int week = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Weeks:"));
					int dd = 56 * week;
					total1 = rh * dd;
					JOptionPane.showMessageDialog(null, "Your Total Rate Per Week is:  " + formatter.format(total1)
							+ " PHP");
				} else if (want1.equalsIgnoreCase(d)) {
					int month = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of MOnth:"));
					int dd = 224 * month;
					total1 = rh * dd;
					JOptionPane.showMessageDialog(null, "Your Total Rate Per Day is: " + formatter.format(total1));
				}

				conf = JOptionPane.showConfirmDialog(null, "Another Transaction?", "Transaction",
						JOptionPane.YES_NO_OPTION);
			}
		} while (conf == 0);
	}
}

ok sir, i saw my classmates program having an OptionDialog withoput using Jframe, can u teach me that?

what exactly do you mean? you don't have a JFrame

what exactly do you mean? you don't have a JFrame

sir i have removed this


UIManager um=new UIManager();


but i have errors:

Multiple markers at this line
- um cannot be resolved
- The static method put(Object, Object) from the type UIManager should be accessed in a
static way


thats my error

well, I showed you in my post:
replace the um there with the name of the class, UIManager.
put is a static method, which means you can call it by the class itself, you don't need an instance.

well, I showed you in my post:
replace the um there with the name of the class, UIManager.
put is a static method, which means you can call it by the class itself, you don't need an instance.

sir, im making a flowchart on this program, :) please check it if its ryt, when i finish please! haha!

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.