Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

Thread: NEed Help, Aqi calculator change javascript to JAva Gui.?

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NEed Help, Aqi calculator change javascript to JAva Gui.?

    i need help for interpreting this javascript to javacode. this script is about AQI calculator.<br> the code in java srcript, does someone can help me immediately. here is the link and so the code too :,br>
    AQI Calculator: Concentration to AQI
    <script type="text/javascript">
    function Linear(AQIhigh, AQIlow, Conchigh, Conclow, Concentration)
    {
    var linear;
    var Conc=parseFloat(Concentration);
    var a;
    a=((Conc-Conclow)/(Conchigh-Conclow))*(AQIhigh-AQIlow)+AQIlow;
    linear=Math.round(a);
    return linear;
    }
     
    function AQIPM25(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=(Math.floor(10*Conc))/10;
    if (c>=0 && c<15.5)
    {
    	AQI=Linear(50,0,15.4,0,c);
    }
    else if (c>=15.5 && c<35.5)
    {
    	AQI=Linear(100,51,35.4,15.5,c);
    }
    else if (c>=35.5 && c<65.5)
    {
    	AQI=Linear(150,101,65.4,35.5,c);
    }
    else if (c>=65.5 && c<150.5)
    {
    	AQI=Linear(200,151,150.4,65.5,c);
    }
    else if (c>=150.5 && c<250.5)
    {
    	AQI=Linear(300,201,250.4,150.5,c);
    }
    else if (c>=250.5 && c<350.5)
    {
    	AQI=Linear(400,301,350.4,250.5,c);
    }
    else if (c>=350.5 && c<500.5)
    {
    	AQI=Linear(500,401,500.4,350.5,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    //line63
    function AQIPM10(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=Math.floor(Conc);
    if (c>=0 && c<55)
    {
    	AQI=Linear(50,0,54,0,c);
    }
    else if (c>=55 && c<155)
    {
    	AQI=Linear(100,51,154,55,c);
    }
    else if (c>=155 && c<255)
    {
    	AQI=Linear(150,101,254,155,c);
    }
    else if (c>=255 && c<355)
    {
    	AQI=Linear(200,151,354,255,c);
    }
    else if (c>=355 && c<425)
    {
    	AQI=Linear(300,201,424,355,c);
    }
    else if (c>=425 && c<505)
    {
    	AQI=Linear(400,301,504,425,c);
    }
    else if (c>=505 && c<605)
    {
    	AQI=Linear(500,401,604,505,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    //line104
    function AQICO(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=(Math.floor(10*Conc))/10;
    if (c>=0 && c<4.5)
    {
    	AQI=Linear(50,0,4.4,0,c);
    }
    else if (c>=4.5 && c<9.5)
    {
    	AQI=Linear(100,51,9.4,4.5,c);
    }
    else if (c>=9.5 && c<12.5)
    {
    	AQI=Linear(150,101,12.4,9.5,c);
    }
    else if (c>=12.5 && c<15.5)
    {
    	AQI=Linear(200,151,15.4,12.5,c);
    }
    else if (c>=15.5 && c<30.5)
    {
    	AQI=Linear(300,201,30.4,15.5,c);
    }
    else if (c>=30.5 && c<40.5)
    {
    	AQI=Linear(400,301,40.4,30.5,c);
    }
    else if (c>=40.5 && c<50.5)
    {
    	AQI=Linear(500,401,50.4,40.5,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    //line145
    function AQISO21hr(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=Math.floor(Conc);
    if (c>=0 && c<36)
    {
    	AQI=Linear(50,0,35,0,c);
    }
    else if (c>=36 && c<76)
    {
    	AQI=Linear(100,51,75,36,c);
    }
    else if (c>=76 && c<186)
    {
    	AQI=Linear(150,101,185,76,c);
    }
    else if (c>=186 && c<=304)
    {
    	AQI=Linear(200,151,304,186,c);
    }
    else if (c>=304 && c<=604)
    {
    	AQI="SO2message";
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    function AQISO224hr(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=Math.floor(Conc);
    if (c>=0 && c<=304)
    {
    	AQI="SO2message";
    }
     
    else if (c>=304 && c<605)
    {
    	AQI=Linear(300,201,604,305,c);
    }
    else if (c>=605 && c<805)
    {
    	AQI=Linear(400,301,804,605,c);
    }
    else if (c>=805 && c<=1004)
    {	
    	AQI=Linear(500,401,1004,805,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    //line186
    function AQIOzone8hr(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=(Math.floor(Conc))/1000;
     
    if (c>=0 && c<.060)
    {
    	AQI=Linear(50,0,0.059,0,c);
    }
    else if (c>=.060 && c<.076)
    {
    	AQI=Linear(100,51,.075,.060,c);
    }
    else if (c>=.076 && c<.096)
    {
    	AQI=Linear(150,101,.095,.076,c);
    }
    else if (c>=.096 && c<.116)
    {
    AQI=Linear(200,151,.115,.096,c);
    }
    else if (c>=.116 && c<.375)
    {
    	AQI=Linear(300,201,.374,.116,c);
    }
    else if (c>=.375 && c<.605)
    {
    	AQI="O3message";
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
    //line219
     
    function AQIOzone1hr(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=(Math.floor(Conc))/1000;
    if (c>=.125 && c<.165)
    {
    	AQI=Linear(150,101,.164,.125,c);
    }
    else if (c>=.165 && c<.205)
    {
    	AQI=Linear(200,151,.204,.165,c);
    }
    else if (c>=.205 && c<.405)
    {
    	AQI=Linear(300,201,.404,.205,c);
    }
    else if (c>=.405 && c<.505)
    {
    	AQI=Linear(400,301,.504,.405,c);
    }
    else if (c>=.505 && c<.605)
    {
    	AQI=Linear(500,401,.604,.505,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
     
    function AQINO2(Concentration)
    {
    var Conc=parseFloat(Concentration);
    var c;
    var AQI;
    c=(Math.floor(Conc))/1000;
    if (c>=0 && c<.054)
    {
    	AQI=Linear(50,0,.053,0,c);
    }
    else if (c>=.054 && c<.101)
    {
    	AQI=Linear(100,51,.100,.054,c);
    }
    else if (c>=.101 && c<.361)
    {
    	AQI=Linear(150,101,.360,.101,c);
    }
    else if (c>=.361 && c<.650)
    {
    	AQI=Linear(200,151,.649,.361,c);
    }
    else if (c>=.650 && c<1.250)
    {
    	AQI=Linear(300,201,1.249,.650,c);
    }
    else if (c>=1.250 && c<1.650)
    {
    	AQI=Linear(400,301,1.649,1.250,c);
    }
    else if (c>=1.650 && c<=2.049)
    {
    	AQI=Linear(500,401,2.049,1.650,c);
    }
    else
    {
    	AQI="Out of Range";
    }
    return AQI;
    }
     
    function AQICategory(AQIndex)
    {
    var AQI=parseFloat(AQIndex)
    var AQICategory;
    if (AQI<=50)
    {
    	AQICategory="Good";
    }
    else if (AQI>50 && AQI<=100)
    {
    	AQICategory="Moderate";
    }
    else if (AQI>100 && AQI<=150)
    {
    	AQICategory="Unhealthy for Sensitive Groups";
    }
    else if (AQI>150 && AQI<=200)
    {
    	AQICategory="Unhealthy";
    }
    else if (AQI>200 && AQI<=300)
    {
    	AQICategory="Very Unhealthy";
    }
    else if (AQI>300 && AQI<=400)
    {
    	AQICategory="Hazardous";
    }
    else if (AQI>400 && AQI<=500)
    {
    	AQICategory="Hazardous";
    }
    else
    {
    	AQICategory="Out of Range";
    }
    return AQICategory;
    }
    //316
     
    function ClearColor()
    {
     
    	document.form.outputbox2.style.backgroundColor="white";
     
    }
     
    function UnitDetermin(form)
    {
    //var form
     
    document.form.txtunit.style.textAlign="center";
    document.form.outputbox2.style.backgroundColor="white";
     
    document.form.inputbox.value="";
    document.form.outputbox1.value="";
    document.form.outputbox2.value="";
    document.form.TextSensitive.value="";
    document.form.HealthEffects.value="";
    document.form.Cautionary.value="";
     
    if (document.form.pollutant.selectedIndex == '1' || document.form.pollutant.selectedIndex == '2')
    {
    	document.form.txtunit.value="ug/m3";	
    }
    else if (document.form.pollutant.selectedIndex == '3')
    {
    	document.form.txtunit.value="ppm";	
    }
    else if (document.form.pollutant.selectedIndex == '4' || document.form.pollutant.selectedIndex == '5' || document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7' || form.pollutant.selectedIndex == '8')
    {
    	document.form.txtunit.value="ppb";	
    }
    return true;
    }
     
    function AQICalc(form)
    {
    var b;
     
    document.form.inputbox.style.textAlign="center";
    document.form.inputbox.style.backgroundColor="white";
     
    var f;
    f=document.form.inputbox.value
    f=f.replace(/\,/,'');
     
    if (document.form.pollutant.selectedIndex == '0')
    {
    	alert("You have not selected a pollutant.");	
    }
    if (document.form.pollutant.selectedIndex == '1')
    {
    	b=AQIPM25(f);	
    }
    else if (document.form.pollutant.selectedIndex == '2')
    {
    	b=AQIPM10(f);	
    }
    else if (document.form.pollutant.selectedIndex == '3')
    {
    	b=AQICO(f);	
    }
    else if (document.form.pollutant.selectedIndex == '4')
    {
    	b=AQISO21hr(f);	
    }
    else if (document.form.pollutant.selectedIndex == '5')
    {
    	b=AQISO224hr(f);	
    }
    else if (document.form.pollutant.selectedIndex == '6')
    {
    	b=AQIOzone8hr(f);	
    }
    else if (document.form.pollutant.selectedIndex == '7')
    {
    	b=AQIOzone1hr(f);	
    }
    else if (document.form.pollutant.selectedIndex == '8')
    {
    	b=AQINO2(f);	
    }
    if (b == "Out of Range")
    {
    	alert("The concentration number you've entered is out of range for this pollutant.");
    	document.form.inputbox.value=" ";
    	document.form.outputbox1.value=" ";
    	document.form.outputbox2.value=" ";
    	document.form.TextSensitive.value="";
    	document.form.HealthEffects.value="";
    	document.form.Cautionary.value="";
    }
     
    else if (b == "SO2message")
    {
    	alert("1-hr SO2 values do not define higher AQI values ( >= 201 ).  AQI values of 201 or greater are calculated with 24-hour SO2 concentrations.");
    	document.form.inputbox.value=" ";
    	document.form.outputbox1.value=" ";
    	document.form.outputbox2.value=" ";
    	document.form.TextSensitive.value="";
    	document.form.HealthEffects.value="";
    	document.form.Cautionary.value="";
    }
     
     
    else if (b == "O3message")
    {
    	alert("8-hour ozone values do not define higher AQI values (>=301).  AQI values of 301 or greater are calculated with 1-hour ozone concentrations.");
    	document.form.inputbox.value=="";
    	document.form.outputbox1.value=="";
    	document.form.outputbox2.value=="";
    	document.form.TextSensitive.value=="";
    	document.form.HealthEffects.value=="";
    	document.form.Cautionary.value=="";
    }
     
    else
    {
    	document.form.outputbox1.value=b;
    	document.form.outputbox2.value=AQICategory(b);
    }
    document.form.outputbox1.style.textAlign="center";
    document.form.outputbox2.style.textAlign="center";
    document.form.TextSensitive.style.textAlign="center";
    document.form.HealthEffects.style.textAlign="center";
    document.form.Cautionary.style.textAlign="center";
     
    if (document.form.outputbox2.value == 'Good')
    {
    	document.form.outputbox2.style.backgroundColor="#00e000";
    	document.form.outputbox2.style.color="black";
    	document.form.HealthEffects.value="None";
    	document.form.Cautionary.value="None";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7')
    	{
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    	}
    }
    else if (document.form.outputbox2.value == 'Moderate')
    {
    	document.form.outputbox2.style.backgroundColor="#ffff00";
    	document.form.outputbox2.style.color="black";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    		document.form.HealthEffects.value="None";
    		document.form.Cautionary.value="None";	
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    		document.form.HealthEffects.value="None";
    		document.form.Cautionary.value="None";	
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    		document.form.HealthEffects.value="None";
    		document.form.Cautionary.value="None";	
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    		document.form.HealthEffects.value="None";
    		document.form.Cautionary.value="None";	
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7')
    	{
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    		if (document.form.pollutant.selectedIndex == '6')
    		{
    			document.form.HealthEffects.value="Unusually sensitive individuals may experience respiratory symptoms.";
    			document.form.Cautionary.value="Unusually sensitive people should consider limiting prolonged outdoor exertion.";
    		}
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    		document.form.HealthEffects.value="Unusually sensitive individuals may experience respiratory symptoms.";
    		document.form.Cautionary.value="Unusually sensitive people should consider reducing prolonged or heavy outdoor exertion.";
    	}
    }
    else if (document.form.outputbox2.value == 'Unhealthy for Sensitive Groups')
    {
    	document.form.outputbox2.style.backgroundColor="#ff7600";
    	document.form.outputbox2.style.color="black";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    		document.form.HealthEffects.value="Increasing likelihood of respiratory symptoms in sensitive individuals, aggravation of heart or lung disease and premature mortality in persons with cardiopulmonary disease and the elderly.";
    		document.form.Cautionary.value="People with respiratory or heart disease, the elderly and children should limit prolonged exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    		document.form.HealthEffects.value="Increasing likelihood of respiratory symptoms	and aggravation	of lung disease, such as asthma.";
    		document.form.Cautionary.value="People with respiratory	disease, such as asthma, should	limit outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    		document.form.HealthEffects.value="Increasing likelihood of reduced exercise tolerance due to increased cardiovascular symptoms, such as chest pain, in people with cardiovascular disease.";
    		document.form.Cautionary.value="People with cardiovascular disease, such as angina, should limit heavy exertion and avoid sources of CO, such as heavy traffic.";
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    		document.form.HealthEffects.value="Increasing likelihood of respiratory symptoms, such as chest tightness and breathing discomfort, in people with asthma.";
    		document.form.Cautionary.value="People with asthma should consider limiting outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7')
    	{
    		document.form.HealthEffects.value="Increasing likelihood of respiratory symptoms and breathing discomfort in active children and adults and people with respiratory disease, such as asthma.";
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    		if (document.form.pollutant.selectedIndex == '6')
    		{
    			document.form.Cautionary.value="Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion.";
    		}
    		else if (document.form.pollutant.selectedIndex == '7')
    		{
    			document.form.Cautionary.value="Active children and adults, and people with respiratory disease, such as asthma, should limit heavy outdoor exertion.";
    		}
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    		document.form.HealthEffects.value="Increasing likelihood of respiratory symptoms and breathing discomfort in active children, the elderly, and people with lung disease, such as asthma.";
    		document.form.Cautionary.value="Active children, the elderly, and people with lung disease, such as asthma, should reduce prolonged or heavy outdoor exertion.";
    	}
    }
    else if (document.form.outputbox2.value == 'Unhealthy')
    {
    	document.form.outputbox2.style.backgroundColor="#ff0000";
    	document.form.outputbox2.style.color="black";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    		document.form.HealthEffects.value="Increased aggravation of heart or lung disease and premature mortality in persons with cardiopulmonary disease and the elderly; increased respiratory effects in general population.";
    		document.form.Cautionary.value="People with respiratory or heart disease, the elderly and children should avoid prolonged exertion; everyone else should limit prolonged exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    		document.form.HealthEffects.value="Increased respiratory symptoms and aggravation of lung disease, such as asthma; possible respiratory effects in general population.";
    		document.form.Cautionary.value=" ";
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    		document.form.HealthEffects.value="Reduced exercise tolerance due to increased cardiovascular symptoms, such as chest pain, in people with cardiovascular disease.";
    		document.form.Cautionary.value="People with cardiovascular disease, such as angina, should limit moderate exertion and avoid sources of CO, such as heavy traffic.";
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    		document.form.HealthEffects.value="Increased respiratory symptoms, such as chest tightness and wheezing in people with asthma; possible aggravation of heart or lung disease.";
    		document.form.Cautionary.value="Children, asthmatics, and people with heart or lung disease should limit outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7')
    	{
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    		document.form.HealthEffects.value="Greater likelihood of respiratory symptoms and breathing difficulty in active children and adults and people with respiratory disease, such as asthma; possible respiratory effects in general population.";
    		if (document.form.pollutant.selectedIndex == '6')
    		{		
    			document.form.Cautionary.value="Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion.";
    		}
    		else if (document.form.pollutant.selectedIndex == '7')
    		{
    			document.form.Cautionary.value="Active children and adults, and people with respiratory disease, such as asthma, should avoid heavy outdoor exertion; everyone else, especially children, should limit heavy outdoor exertion.";
    		}	
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    		document.form.HealthEffects.value="Greater likelihood of respiratory symptoms in active children, the elderly, and people with lung disease, such as asthma; possible respiratory effects in general population.";
    		document.form.Cautionary.value="Active children, the elderly, and people with lung disease, such as asthma, should avoid prolonged or heavy outdoor exertion; everyone else, expecially children, should reduce prolonged or heavy outdoor exertion.";
    	}
    }
    else if (document.form.outputbox2.value == 'Very Unhealthy')
    {
    	document.form.outputbox2.style.backgroundColor="#990049";
    	document.form.outputbox2.style.color="#ffffff";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    		document.form.HealthEffects.value="Significant aggravation of heart or lung disease and premature mortality in persons with cardiopulmonary disease and the elderly; significant increase in respiratory effects in general population.";
    		document.form.Cautionary.value="People with respiratory or heart disease, the elderly and children should avoid any outdoor activity; everyone else should avoid prolonged exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    		document.form.HealthEffects.value="Significant increase in respiratory symptoms and aggravation of lung disease, such as asthma; increasing likelihood of respiratory effects in general population.";
    		document.form.Cautionary.value="People with respiratory disease, such as asthma, should avoid any outdoor activity; everyone else, especially the elderly and children, should limit outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    		document.form.HealthEffects.value="Significant aggravation of cardiovascular symptoms, such as chest pain, in people with cardiovascular disease.";
    		document.form.Cautionary.value="People with cardiovascular disease, such as angina, should avoid exertion and sources of CO, such as heavy traffic.";
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    		document.form.HealthEffects.value="Significant increase in respiratory symptoms, such as wheezing and shortness of breath, in people with asthma; aggravation of heart or lung disease.";
    		document.form.Cautionary.value="Children, asthmatics, and people with heart or lung disease should avoid outdoor exertion; everyone else should limit outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || document.form.pollutant.selectedIndex == '7')
    	{
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    		document.form.HealthEffects.value="Increasingly severe symptoms and impaired breathing likely in active children and adults and people with respiratory disease, such as asthma; increasing likelihood of respiratory effects in general population.";	
    		document.form.Cautionary.value="Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    		document.form.HealthEffects.value="Increasingly severe symptoms and impaired breathing likely in active children, the elderly, and people with lung disease, such as asthma; increasing likelihood of respiratory effects in general population.";
    		document.form.Cautionary.value="Active children, the elderly, and people with lung disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should avoid prolonged or heavy outdoor exertion.";
    	}
    }
    else if (document.form.outputbox2.value == 'Hazardous')
    {
    	document.form.outputbox2.style.backgroundColor="#7E0023";
    	document.form.outputbox2.style.color="#ffffff";
    	if (document.form.pollutant.selectedIndex == '1')
    	{
    		document.form.TextSensitive.value="People with respiratory or heart disease, the elderly and children are the groups most at risk.";
    		document.form.HealthEffects.value="Serious aggravation of heart or lung disease and premature mortality in persons with cardiopulmonary disease and the elderly; serious risk of respiratory effects in general population.";
    		document.form.Cautionary.value="Everyone should avoid any outdoor exertion; people with respiratory or heart disease, the elderly and children should remain indoors.";
    	}
    	else if (document.form.pollutant.selectedIndex == '2')
    	{
    		document.form.TextSensitive.value="People with respiratory disease are the group most at risk.";
    		document.form.HealthEffects.value="Serious risk of respiratory symptoms and aggravation of lung disease, such as asthma; respiratory effects likely in general population.";
    		document.form.Cautionary.value="Everyone should avoid any outdoor exertion; people with respiratory disease, such as asthma, should remain indoors.";
    	}
    	else if (document.form.pollutant.selectedIndex == '3')
    	{
    		document.form.TextSensitive.value="People with heart disease are the group most at risk.";
    		document.form.HealthEffects.value="Serious aggravation of cardiovascular symptoms, such as chest pain, in people with cardiovascular disease; impairment of strenuous activities in general population.";
    		document.form.Cautionary.value="People with cardiovascular disease, such as angina, should avoid exertion and sources of CO, such as heavy traffic; everyone else should limit heavy exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '4' || form.pollutant.selectedIndex == '5')
    	{
    		document.form.TextSensitive.value="People with asthma are the group most at risk.";
    		document.form.HealthEffects.value="Severe respiratory symptoms, such as wheezing and shortness of breath, in people with asthma; increased aggravation of heart or lung disease; possible respiratory effects in general population.";
    		document.form.Cautionary.value="Children, asthmatics, and people with heart or lung disease should remain indoors; everyone else should avoid outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '6' || document.form.pollutant.selectedIndex == '7')
    	{
    		document.form.TextSensitive.value="Children and people with asthma are the groups most at risk.";
    		document.form.HealthEffects.value="Severe respiratory effects and impaired breathing likely in active children and adults and people with respiratory disease, such as asthma; increasingly severe respiratory effects likely in general population.";	
    		document.form.Cautionary.value="Everyone should avoid all outdoor exertion.";
    	}
    	else if (document.form.pollutant.selectedIndex == '8')
    	{
    		document.form.TextSensitive.value="People with asthma or other respiratory diseases, the elderly, and children are the groups most at risk.";
    		document.form.HealthEffects.value="Severe respiratory effects and impaired breathing likely in active children, the elderly, and people with lung disease, such as asthma; increasingly severe respiratory effects likely in general population.";
    		document.form.Cautionary.value="Children, the elderly, and people with lung disease, such as asthma, should remain indoors; everyone else, especially children, should avoid outdoor exertion.";
    	}
    }
    else
    {
    	document.form.outputbox2.style.backgroundColor="#ffffff";
    	document.form.outputbox2.style.color="black";
    	document.form.TextSensitive.value="";
    	document.form.HealthEffects.value="";
    	document.form.Cautionary.value="";
    }
     
    return true;
    }
     
     
    </script>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    What have you tried? Please post your current code with questions about where you are having problems.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    I am actually working on right now, preparing components and try to understand.

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    hello there, i can only make this. would you show me.how to display the item by choosing the index in if else. the displayed text field will appear units each pollutant, like the Aqi Calc in the link above.

    package explorer;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    class Nilai implements ActionListener {
    	public static void main (String[]args){
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Nilai nm = new Nilai();
    				nm.show();
    			}
    		});
    	}
     
    	public JFrame frame;
            public JComboBox cmbPol; 
    	public JLabel labelPol,labelUnit,labelInput,labelAqi,labelKategori;
     
    	public JTextField textUnit,textInput,textAqi,TextKategori;
     
    	public JButton buttonCal,buttonOK,buttonCancel,buttonKeluar;
    	String[] listpolutan ={"PM2.5 - Particulate &lt;2.5 microns (24hr avg)",
              "PM10 - Particulate &lt;10 microns (24hr avg)",
              "CO - Carbon Monoxide (8hr avg)","SO2 - Sulfur Dioxide (1hr avg)",
              "SO2 - Sulfur Dioxide (24hr avg)","O3 - Ozone (8hr avg)",
              "O3 - Ozone (1hr avg)","NO2 - Nitrogen Dioxide (1hr avg)"};
     
    	public Nilai(){
     
            labelPol = new JLabel("Polutan");
            labelPol.setLocation(0, 10);
            labelPol.setSize(labelPol.getPreferredSize());
     
            labelUnit = new JLabel("Unit");
            labelUnit.setLocation(0, 40);
            labelUnit.setSize(labelPol.getPreferredSize());
     
            labelInput = new JLabel("Input");
            labelInput.setLocation(0, 60);
            labelInput.setSize(labelInput.getPreferredSize());
     
            labelAqi = new JLabel("AQI");
            labelAqi.setLocation(0, 80);
            labelAqi.setSize(labelAqi.getPreferredSize());
     
            labelKategori = new JLabel("Kategori");
            labelKategori.setLocation(0, 100);
            labelKategori.setSize(labelKategori.getPreferredSize());
     
     
     
            cmbPol = new JComboBox(listpolutan);
            cmbPol.setSelectedIndex(0);
            cmbPol.setLocation(80, 10);
            cmbPol.setSize(cmbPol.getPreferredSize());
            cmbPol.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) {
     
                    textAqi.setText("You Selected : " +      
                    ((JComboBox)e.getSource()).getSelectedItem());
                    }
                   });
     
     
     
     
            textUnit = new JTextField(10);
            textUnit.setLocation(80, 40);
            textUnit.setSize(textUnit.getPreferredSize());
     
            textInput = new JTextField(10);
            textInput.setLocation(80, 60);
            textInput.setSize(textInput.getPreferredSize());
     
            textAqi = new JTextField(10);
            textAqi.setLocation(80, 80);
            textAqi.setSize(textAqi.getPreferredSize());
     
            TextKategori = new JTextField(10);
            TextKategori.setLocation(80, 100);
            TextKategori.setSize(TextKategori.getPreferredSize());
     
     
        	buttonOK = new JButton("OK");
        	buttonOK.setLocation(200, 40);
        	buttonOK.setSize(80,20);
        	buttonOK.addActionListener(this);
     
     
        	buttonCancel = new JButton("Reset");
        	buttonCancel.setLocation(200, 70);
        	buttonCancel.setSize(80,20);
        	buttonCancel.addActionListener(this);
     
            buttonCal = new JButton("Calc");
        	buttonCal.setLocation(200, 100);
        	buttonCal.setSize(80,20);
        	buttonCal.addActionListener(this);
     
        	buttonKeluar = new JButton("Out");
        	buttonKeluar.setLocation(285, 40);
        	buttonKeluar.setSize(80,40);
        	buttonKeluar.addActionListener(this);
     
       	}
     
     
     
            public void show(){
    	frame = new JFrame ("AQI Calc");
    	frame.setLayout(null);
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
        	frame.getContentPane().add(labelPol);
        	frame.getContentPane().add(labelUnit);
        	frame.getContentPane().add(labelInput);
        	frame.getContentPane().add(labelAqi);
        	frame.getContentPane().add(labelKategori);
        	frame.getContentPane().add(buttonOK);
     
        	frame.getContentPane().add(buttonCancel);
        	frame.getContentPane().add(buttonCal);
        	frame.getContentPane().add(buttonKeluar);
     
        	frame.getContentPane().add(cmbPol);
        	frame.getContentPane().add(textUnit);
        	frame.getContentPane().add(textInput);
        	frame.getContentPane().add(textAqi);
        	frame.getContentPane().add(TextKategori);
     
    	frame.setBounds(0, 0, 400, 300);
        	frame.setLocationRelativeTo(null);
        	frame.setVisible(true);
    	}
     
     
     
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }


    aq.jpg

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    hello there,mr Norm. i can only do this. would you showme how to implements getSelectedindex in ifelse condition in order appear in the textfield(textUnit).
    here is my code:
    package explorer;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    class Nilai implements ActionListener {
    	public static void main (String[]args){
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Nilai nm = new Nilai();
    				nm.show();
    			}
    		});
    	}
     
    	public JFrame frame;
            public JComboBox cmbPol; 
    	public JLabel labelPol,labelUnit,labelInput,labelAqi,labelKategori,textKet;
    	public JTextField textUnit,textInput,textAqi,TextKategori;
    	public JButton buttonCal,buttonOK,buttonCancel,buttonOut;
    	String[] listpolutan ={"PM2.5 - Particulate &lt;2.5 microns (24hr avg)",
              "PM10 - Particulate &lt;10 microns (24hr avg)",
              "CO - Carbon Monoxide (8hr avg)","SO2 - Sulfur Dioxide (1hr avg)",
              "SO2 - Sulfur Dioxide (24hr avg)","O3 - Ozone (8hr avg)",
              "O3 - Ozone (1hr avg)","NO2 - Nitrogen Dioxide (1hr avg)"};
     
    	public Nilai(){
     
            labelPol = new JLabel("Polutan");
            labelPol.setLocation(0, 10);
            labelPol.setSize(labelPol.getPreferredSize());
     
            labelUnit = new JLabel("Unit");
            labelUnit.setLocation(0, 40);
            labelUnit.setSize(labelPol.getPreferredSize());
     
            labelInput = new JLabel("Input");
            labelInput.setLocation(0, 60);
            labelInput.setSize(labelInput.getPreferredSize());
     
            labelAqi = new JLabel("AQI");
            labelAqi.setLocation(0, 80);
            labelAqi.setSize(labelAqi.getPreferredSize());
     
            labelKategori = new JLabel("Kategori");
            labelKategori.setLocation(0, 100);
            labelKategori.setSize(labelKategori.getPreferredSize());
     
     
        	labelKet = new JLabel("Desc");
        	labelKet.setLocation(200, 140);
        	labelKet.setSize(labelKet.getPreferredSize());
     
     
            cmbPol = new JComboBox(listpolutan);
            cmbPol.setSelectedIndex(0);
     
            cmbPol.setLocation(80, 10);
            cmbPol.setSize(cmbPol.getPreferredSize());
     
            cmbPol.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) {
                    int index = cmbPol.getSelectedIndex();
                    if (cmbPol.getItemAt(index) == "3");
                    textAqi.setText("You Selected : ");     
     
                    }
                   });
     
            textUnit = new JTextField(10);
            textUnit.setLocation(80, 40);
            textUnit.setSize(textUnit.getPreferredSize());
     
            textInput = new JTextField(10);
            textInput.setLocation(80, 60);
            textInput.setSize(textInput.getPreferredSize());
     
            textAqi = new JTextField(10);
            textAqi.setLocation(80, 80);
            textAqi.setSize(textAqi.getPreferredSize());
     
            TextKategori = new JTextField(10);
            TextKategori.setLocation(80, 100);
            TextKategori.setSize(TextKategori.getPreferredSize());
     
     
        	buttonOK = new JButton("OK");
        	buttonOK.setLocation(200, 40);
        	buttonOK.setSize(80,20);
        	buttonOK.addActionListener(this);
     
     
        	buttonCancel = new JButton("reset");
        	buttonCancel.setLocation(200, 70);
        	buttonCancel.setSize(80,20);
        	buttonCancel.addActionListener(this);
     
            buttonCal = new JButton("Calc");
        	buttonCal.setLocation(200, 100);
        	buttonCal.setSize(80,20);
        	buttonCal.addActionListener(this);
     
        	buttonKeluar = new JButton("Out");
        	buttonKeluar.setLocation(285, 40);
        	buttonKeluar.setSize(80,40);
        	buttonKeluar.addActionListener(this);
     
       	}
     
     
     
            public void show(){
    	frame = new JFrame ("AQI Calc");
    	frame.setLayout(null);
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
        	frame.getContentPane().add(labelPol);
        	frame.getContentPane().add(labelUnit);
        	frame.getContentPane().add(labelInput);
        	frame.getContentPane().add(labelAqi);
        	frame.getContentPane().add(labelKategori);
        	frame.getContentPane().add(labelKet);
        	frame.getContentPane().add(buttonOK);
     
        	frame.getContentPane().add(buttonCancel);
        	frame.getContentPane().add(buttonCal);
        	frame.getContentPane().add(buttonKeluar);
     
        	frame.getContentPane().add(cmbPol);
        	frame.getContentPane().add(textUnit);
        	frame.getContentPane().add(textInput);
        	frame.getContentPane().add(textAqi);
        	frame.getContentPane().add(TextKategori);
     
     
    	frame.setBounds(0, 0, 400, 300);
        	frame.setLocationRelativeTo(null);
        	frame.setVisible(true);
    	}
     
     
     
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

     if (cmbPol.getItemAt(index) == "3");
    You should use the equals() method for comparing Strings, not the == operator

    Can you explain your problem with the getSelectedIndex() method?


    The posted code has many compiler errors. You should fix those before writing any more new code.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    firstly i try to interpreting this javascript step by step.from this scriptbelow, when i click the item list of JComboBox in TextUnit will appear the Units.
    if (document.form.pollutant.selectedIndex == '1' || document.form.pollutant.selectedIndex == '2')
    {
    	document.form.txtunit.value="ug/m3";	
    }
    else if (document.form.pollutant.selectedIndex == '3')
    {
    	document.form.txtunit.value="ppm";	
    }
    else if (document.form.pollutant.selectedIndex == '4' || document.form.pollutant.selectedIndex == '5' || document.form.pollutant.selectedIndex == '6' || form.pollutant.selectedIndex == '7' || form.pollutant.selectedIndex == '8')
    {
    	document.form.txtunit.value="ppb";	
    }
    return true;
    }

    im using netbeans, i apologize for the bugs.i try to use getSelectedIndex then the unit will change and not appear the item. and this my code, but it dosnt work...
    int index = cmbPol.getSelectedIndex();
                    String str;
                    if (cmbPol.getItemAt(index).equals(3)){
                    textAqi.setText("You Selected : ");}// +      
     
                    if(cmbPol.getItemAt(index).equals(2)){
                    textAqi.setText("sagertrh ");
                    }
                    else{textAqi.setText("sgg ");}

    thank you for reply

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    First get the code you posted to compile without errors and execute and show a GUI window.
    When that is done, THEN worry about adding more code. Don't add any more code until the current code compiles and executes without errors.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    here is my code :

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    class Nilai implements ActionListener {
    	public static void main (String[]args){
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Nilai nm = new Nilai();
    				nm.show();
    			}
    		});
    	}
     
    	public JFrame frame;
            public JComboBox cmbPol; 
    	public JLabel labelPol,labelUnit,labelInput,labelAqi,labelKategori,labelJudul,
                   labelKet;
    	public JTextField textUnit,textInput,textAqi,TextKategori;
    	public JButton buttonCal,buttonOK,buttonCancel,buttonOut;
    	String[] listpolutan ={"PM2.5 - Particulate &lt;2.5 microns (24hr avg)",
              "PM10 - Particulate &lt;10 microns (24hr avg)",
              "CO - Carbon Monoxide (8hr avg)","SO2 - Sulfur Dioxide (1hr avg)",
              "SO2 - Sulfur Dioxide (24hr avg)","O3 - Ozone (8hr avg)",
              "O3 - Ozone (1hr avg)","NO2 - Nitrogen Dioxide (1hr avg)"};
     
    	public Nilai(){
     
            labelPol = new JLabel("Polutan");
            labelPol.setLocation(0, 10);
            labelPol.setSize(labelPol.getPreferredSize());
     
            labelUnit = new JLabel("Unit");
            labelUnit.setLocation(0, 40);
            labelUnit.setSize(labelPol.getPreferredSize());
     
            labelInput = new JLabel("Input");
            labelInput.setLocation(0, 60);
            labelInput.setSize(labelInput.getPreferredSize());
     
            labelAqi = new JLabel("AQI");
            labelAqi.setLocation(0, 80);
            labelAqi.setSize(labelAqi.getPreferredSize());
     
            labelKategori = new JLabel("Kategori");
            labelKategori.setLocation(0, 100);
            labelKategori.setSize(labelKategori.getPreferredSize());
     
     
     
        	labelKet = new JLabel("Description");
        	labelKet.setLocation(200, 140);
        	labelKet.setSize(labelKet.getPreferredSize());
     
     
            cmbPol = new JComboBox(listpolutan);
            cmbPol.setSelectedIndex(0);
     
            cmbPol.setLocation(80, 10);
            cmbPol.setSize(cmbPol.getPreferredSize());
     
            cmbPol.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) {
                    int index = cmbPol.getSelectedIndex();
                    String str;
                    if (cmbPol.getItemAt(index).equals(3)){
                    textUnit.setText("mg/m3");}    
     
                    if(cmbPol.getItemAt(index).equals(2)){
                    textUnit.setText("kg");
                    }
                    else{textUnit.setText("ppb");}
            }
                   });
     
            textUnit = new JTextField(10);
            textUnit.setLocation(80, 40);
            textUnit.setSize(textUnit.getPreferredSize());
     
            textInput = new JTextField(10);
            textInput.setLocation(80, 60);
            textInput.setSize(textInput.getPreferredSize());
     
            textAqi = new JTextField(10);
            textAqi.setLocation(80, 80);
            textAqi.setSize(textAqi.getPreferredSize());
     
            TextKategori = new JTextField(10);
            TextKategori.setLocation(80, 100);
            TextKategori.setSize(TextKategori.getPreferredSize());
     
     
     
        	labelKet = new JLabel("");
        	labelKet.setLocation(200, 160);
        	labelKet.setSize(100,20);
     
        	buttonOK = new JButton("OK");
        	buttonOK.setLocation(200, 40);
        	buttonOK.setSize(80,20);
        	buttonOK.addActionListener(this);
     
     
        	buttonCancel = new JButton("reset");
        	buttonCancel.setLocation(200, 70);
        	buttonCancel.setSize(80,20);
        	buttonCancel.addActionListener(this);
     
            buttonCal = new JButton("count");
        	buttonCal.setLocation(200, 100);
        	buttonCal.setSize(80,20);
        	buttonCal.addActionListener(this);
     
        	buttonOut = new JButton("out");
        	buttonOut.setLocation(285, 40);
        	buttonOut.setSize(80,40);
        	buttonOut.addActionListener(this);
     
       	}
     
     
     
            public void show(){
    	frame = new JFrame ("AQI Calc");
    	frame.setLayout(null);
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
        	frame.getContentPane().add(labelPol);
        	frame.getContentPane().add(labelUnit);
        	frame.getContentPane().add(labelInput);
        	frame.getContentPane().add(labelAqi);
        	frame.getContentPane().add(labelKategori);
        	frame.getContentPane().add(labelKet);
        	frame.getContentPane().add(buttonOK);
     
        	frame.getContentPane().add(buttonCancel);
        	frame.getContentPane().add(buttonCal);
        	frame.getContentPane().add(buttonOut);
     
        	frame.getContentPane().add(cmbPol);
        	frame.getContentPane().add(textUnit);
        	frame.getContentPane().add(textInput);
        	frame.getContentPane().add(textAqi);
        	frame.getContentPane().add(TextKategori);
        	frame.getContentPane().add(labelKet);
     
    	frame.setBounds(0, 0, 400, 300);
        	frame.setLocationRelativeTo(null);
        	frame.setVisible(true);
    	}
     
     
     
     
     
    }

    that was my code, and this is the results. and the units dosnt change.
    aq.jpg

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    The posted code still has compiler errors that need to be fixed.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    its oke when i run on mylaptop. i've copied the code and check again, the problem come from the package.is my code above cannot be copiled mr.Norm? here the code again.
    package explorer;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    class Nilai implements ActionListener {
    	public static void main (String[]args){
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Nilai nm = new Nilai();
    				nm.show();
    			}
    		});
    	}
     
    	public JFrame frame;
            public JComboBox cmbPol; 
    	public JLabel labelPol,labelUnit,labelInput,labelAqi,labelKategori,labelJudul,
                   labelKet;
    	public JTextField textUnit,textInput,textAqi,TextKategori;
    	public JButton buttonCal,buttonOK,buttonCancel,buttonOut;
    	String[] listpolutan ={"PM2.5 - Particulate &lt;2.5 microns (24hr avg)",
              "PM10 - Particulate &lt;10 microns (24hr avg)",
              "CO - Carbon Monoxide (8hr avg)","SO2 - Sulfur Dioxide (1hr avg)",
              "SO2 - Sulfur Dioxide (24hr avg)","O3 - Ozone (8hr avg)",
              "O3 - Ozone (1hr avg)","NO2 - Nitrogen Dioxide (1hr avg)"};
     
    	public Nilai(){
     
            labelPol = new JLabel("Polutan");
            labelPol.setLocation(0, 10);
            labelPol.setSize(labelPol.getPreferredSize());
     
            labelUnit = new JLabel("Unit");
            labelUnit.setLocation(0, 40);
            labelUnit.setSize(labelPol.getPreferredSize());
     
            labelInput = new JLabel("Input");
            labelInput.setLocation(0, 60);
            labelInput.setSize(labelInput.getPreferredSize());
     
            labelAqi = new JLabel("AQI");
            labelAqi.setLocation(0, 80);
            labelAqi.setSize(labelAqi.getPreferredSize());
     
            labelKategori = new JLabel("Kategori");
            labelKategori.setLocation(0, 100);
            labelKategori.setSize(labelKategori.getPreferredSize());
     
     
     
        	labelKet = new JLabel("Description");
        	labelKet.setLocation(200, 140);
        	labelKet.setSize(labelKet.getPreferredSize());
     
     
            cmbPol = new JComboBox(listpolutan);
            cmbPol.setSelectedIndex(0);
     
            cmbPol.setLocation(80, 10);
            cmbPol.setSize(cmbPol.getPreferredSize());
     
            cmbPol.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) {
                    int index = cmbPol.getSelectedIndex();
                    String str;
                    if (cmbPol.getItemAt(index).equals(3)){
                    textUnit.setText("mg/m3");}    
     
                    if(cmbPol.getItemAt(index).equals(2)){
                    textUnit.setText("kg");
                    }
                    else{textUnit.setText("ppb");}
            }
                   });
     
            textUnit = new JTextField(10);
            textUnit.setLocation(80, 40);
            textUnit.setSize(textUnit.getPreferredSize());
     
            textInput = new JTextField(10);
            textInput.setLocation(80, 60);
            textInput.setSize(textInput.getPreferredSize());
     
            textAqi = new JTextField(10);
            textAqi.setLocation(80, 80);
            textAqi.setSize(textAqi.getPreferredSize());
     
            TextKategori = new JTextField(10);
            TextKategori.setLocation(80, 100);
            TextKategori.setSize(TextKategori.getPreferredSize());
     
     
     
        	labelKet = new JLabel("");
        	labelKet.setLocation(200, 160);
        	labelKet.setSize(100,20);
     
        	buttonOK = new JButton("OK");
        	buttonOK.setLocation(200, 40);
        	buttonOK.setSize(80,20);
        	buttonOK.addActionListener(this);
     
     
        	buttonCancel = new JButton("reset");
        	buttonCancel.setLocation(200, 70);
        	buttonCancel.setSize(80,20);
        	buttonCancel.addActionListener(this);
     
            buttonCal = new JButton("count");
        	buttonCal.setLocation(200, 100);
        	buttonCal.setSize(80,20);
        	buttonCal.addActionListener(this);
     
        	buttonOut = new JButton("out");
        	buttonOut.setLocation(285, 40);
        	buttonOut.setSize(80,40);
        	buttonOut.addActionListener(this);
     
       	}
     
     
     
            public void show(){
    	frame = new JFrame ("AQI Calc");
    	frame.setLayout(null);
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
        	frame.getContentPane().add(labelPol);
        	frame.getContentPane().add(labelUnit);
        	frame.getContentPane().add(labelInput);
        	frame.getContentPane().add(labelAqi);
        	frame.getContentPane().add(labelKategori);
        	frame.getContentPane().add(labelKet);
        	frame.getContentPane().add(buttonOK);
     
        	frame.getContentPane().add(buttonCancel);
        	frame.getContentPane().add(buttonCal);
        	frame.getContentPane().add(buttonOut);
     
        	frame.getContentPane().add(cmbPol);
        	frame.getContentPane().add(textUnit);
        	frame.getContentPane().add(textInput);
        	frame.getContentPane().add(textAqi);
        	frame.getContentPane().add(TextKategori);
        	frame.getContentPane().add(labelKet);
     
    	frame.setBounds(0, 0, 400, 300);
        	frame.setLocationRelativeTo(null);
        	frame.setVisible(true);
    	}
     
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
     
     
     
     
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    I see you have add the listener method now. It was not in post#9

    Now you can start adding the code you were talking about.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    oke. you mean about my code problem? in that code, getselectedindex doesnt work. do you have any explanation why or some example? what is the right statements for my code?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    Add some println statements that print out the values that are returned by the methods so you can see what the computer sees when it executes the if statement.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    would you explain more specifically sir?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    Print out what is returned by these methods:
    cmbPol.getSelectedIndex()
    cmbPol.getItemAt(index)
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    if i print out the returned from its method then the number of index will displayed. i mean, how to replace selected index that i choose with other statements? in this case i give each index of item with unit item, e.g. when i click the firs polutan then unit become mg,second pollutant unit become kg, etc.

  18. #18
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    i've already add this code, and itswork, but i supposed to get more simple codes using selectedindex. for a while this is work. now im going continue to other function method.i hope you can help me. thank you mr.Norm.
    cmbPol = new JComboBox(listpolutan);
            cmbPol.setLocation(80, 10);
            cmbPol.setSize(cmbPol.getPreferredSize());
            cmbPol.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) {
     
                    if(cmbPol.getSelectedItem().equals("PM2.5 - Particulate &lt;2.5 microns (24hr avg)")){
                    textUnit.setText("ug/m3");}
                    if(cmbPol.getSelectedItem().equals("PM10 - Particulate &lt;10 microns (24hr avg)")){
                    textUnit.setText("ug/m3");}
                    if(cmbPol.getSelectedItem().equals("CO - Carbon Monoxide (8hr avg)")){
                    textUnit.setText("ppm");}
                    if(cmbPol.getSelectedItem().equals("SO2 - Sulfur Dioxide (1hr avg)")){
                    textUnit.setText("ppb");}
                    if(cmbPol.getSelectedItem().equals("SO2 - Sulfur Dioxide (24hr avg)")){
                    textUnit.setText("ppb");}
                    if(cmbPol.getSelectedItem().equals("O3 - Ozone (8hr avg)")){
                    textUnit.setText("ppb");}
                    if(cmbPol.getSelectedItem().equals("O3 - Ozone (1hr avg)")){
                    textUnit.setText("ppb");}
                    if(cmbPol.getSelectedItem().equals("NO2 - Nitrogen Dioxide (1hr avg)")){
                    textUnit.setText("ppb");}
     
                         }
                   });

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEed Help, Aqi calculator change javascript to JAva Gui.?

    Instead of matching against the full String from the combobox, could you just just the index value?
    A problem when matching full Strings is they can be mistyped and not be the same String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Calculator GUI Help
    By bzhagar in forum AWT / Java Swing
    Replies: 6
    Last Post: October 3rd, 2012, 07:42 AM
  2. GUI Calculator: Adding Answer Button? Please Help
    By Staticity in forum What's Wrong With My Code?
    Replies: 29
    Last Post: July 27th, 2011, 03:18 PM
  3. GUI Scientific Calculator. Please help! (Event Handling)
    By BlackGazer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 9th, 2011, 07:14 AM
  4. change JTable column name, gui does not update at once
    By renars in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 23rd, 2011, 10:39 AM
  5. calculator GUI needs to compute
    By javanovice in forum AWT / Java Swing
    Replies: 3
    Last Post: May 4th, 2010, 02:16 PM