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 2 of 2

Thread: Error with taking float numbers from an input dialog box.

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Error with taking float numbers from an input dialog box.

    Hey,
    I'm fairly new to java and I'm having some trouble with my project. It gives me errors for lines like this:
    float temp = float.parseFloat(JOptionPane.showInputDialog(null, "Enter start time:","Start Time",3));
    The errors say something like "';' expected" or "class expected". I know you're supposed to put an f after a decimal when you declare a float and I think it may have something with that. But I don't know where to put it in or if that's the problem at all.
    All help greatly appreciated!
    Máire

    Here's all of my code:
    import javax.swing.JOptionPane;
    import jm.util.*;
    public class Project2
    {
        public static void main(String [] args)
        {
            String InputName1, InputName2, OutputName, start, end;
            String menu =  
                "1. Mix Two Files.\n2. Loop a File\n3. Insert Silence Into a File\n4. Fade Part of a File\n5. Chop a File";
            int MenuSelection = Integer.parseInt(JOptionPane.showInputDialog(null,menu));
            if (MenuSelection == 1)
            {
                float [] d1,d2;
             	InputName1 = getFileName("first ");
                InputName2 = getFileName("second ");
                OutputName = getOutName();
                d1 = Read.audio(InputName1);
                d2 = Read.audio(InputName2);
                float [] mixedData;
                if (d1.length > d2.length)
                 mixedData = mix(d1, d2);
                if (d2.length > d1.length)
                 mixedData = mix(d2, d1);
                Write.audio(mixedData, OutputName);
            }
            else if (MenuSelection == 2)
            {
             InputName1 = getFileName("");
             start = startLoc();
             end = endLoc();
             OutputName = getOutName();
             times = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the number of times you want to loop this file:"));
             float [] data = Read.audio(InputName1);
             float [] result = loop(InputName1, start, end, times);
             Write.audio(result, OutputName);
            }
            else if (MenuSelection == 3)
            {
    	        InputName1 = getFileName("");
    	        start = startLoc();
    	        end = endLoc();
    	        OutputName = getOutName();
    	        float [] data = Read.audio(InputName1);
    	        float Silence = insertSilence(data, start, end);
    	        Write.audio(Silence, OutputName);
        	}
        	else if (MenuSelection == 4)
         	{
    	     	InputName1 = getFileName("");
    	        start = startLoc();
    	        end = endLoc();
    	        OutputName = getOutName();
    	        float FadeSize = float.parseFloat(JOptionPane.showInputDialogue(null,"Please enter the fade size:");//having trouble with this line
    	        float [] data = Read.audio(InputName1); 
    	        float [] fadedData = Fade(data, start, end, FadeSize);
    	        Write.audio(fadedData, OutputName);
     
         	}
         	else if (MenuSelection == 5)
        	{
    	    	InputName1 = getFileName("");
             	start = startLoc();
             	end = endLoc();
             	OutputName = getOutName();
             	float [] data = Read.audio(InputName1);
             	float [] choppedData = chop(data,start,end);
             	Write.audio(choppedData, OutputName);
         	}	
        }
        public static String getFileName(String p)
        {
      		String tempName = JOptionPane.showInputDialog(null,"Enter " + p + "file name:","File Name",3);   
      		return tempName;
      	}
      	public static String getOutName()
      	{
    	  	String tempName = JOptionPane.showInputDialog(null,"Enter output file name:","File Name",3);   
      		return tempName;
    	} 
    	//And even more trouble with these two methods here.
      	public static float startLoc()
      	{
    	  	float temp = float.parseFloat(JOptionPane.showInputDialog(null,"Enter start time:","Start Time",3));
       		return temp;
      	}
      	public static float endLoc()
      	{
    	  	float temp = float.parseFloat(JOptionPane.showInputDialog(null,"Enter end time:","End Time",3));
       		return temp;
      	}
      	public static float [] mix(float [] longest, float [] shortest)
      	{
       		float [] tempData = new float[longest.length];
       		for (int i = 0; i < shortest.length; i++)
        		tempData[i] = (longest[i] + shortest [i]) * 0.5f;
       		for (int i = shortest.length; i < longest.length; i++)
        		tempData[i] = longest[i] * 0.5f;
       		return tempData;
      	}
      	public static float [] loop(float [] data, int startL, int endL, int repeats)
      	{
    	  	int length = endL - startL;
    	  	float [] tempData = new float[length * repeats];
    	  	for (int i = 0; i < length; i++)
    	  		tempData[i] = data[startLocation + i];
    	  	for (int i = 0; i < repeats; i++)
    	  	{
    		  	for (int j = 0; j < length; j++)
    		  		tempdata[j + i * length] = tempdata[j];
    	 	}
    	 	return tempData;
     	}
     	public static float [] insertSilence(float [] data, int startL, int endL);
     	{
    	 	int length = endL - startL;
    	 	for (int i = 0; i < length; i++)
    	 		data[startL + i] = 0.0f;
    	 	return data;
     	}
     	public static float [] chop(float [] data, int start, int end)
     	{
    	 	int length = end - start;
    	 	float [] tempData = new float[length];
    	 	for (int i = 0; i < length; i ++)
    	 		tempData[i] = data[start + i];
    	 	return tempData;
     	}
     	public static float [] Fade(float [] data , int startL, int endL, int fadeSize)
     	{
    	 	int length = endL - startL;
    	 	float [] tempData = new float[length];
    	 	for(int i = 0; i < length; i++)
    	 		tempData[i] = data[startL + 1];
    	 	for(int i = 0; i < fadesize; i++)
    	 		tempData[i] *= (float)i/(float)fadesize;
    	 	return tempData;
     	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Error with taking float numbers from an input dialog box.

    Java is case-sensitive. Float != float, String != string, Integer != integer, etc.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Dialog box not allowing user input?
    By michaelgilbert in forum AWT / Java Swing
    Replies: 13
    Last Post: November 1st, 2011, 05:22 PM
  2. Taking Input in String Array
    By syehjafa in forum Collections and Generics
    Replies: 8
    Last Post: July 25th, 2011, 07:18 AM
  3. How to write 2 dimensional array of float numbers to binary file?
    By Ghuynh in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 17th, 2010, 04:26 PM
  4. Simple Input Dialog Question
    By tabutcher in forum Java Theory & Questions
    Replies: 0
    Last Post: March 1st, 2010, 11:10 PM
  5. How to check that console input should be integer only?
    By Konnor in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 2nd, 2009, 05:37 AM