0

Hey everyone, I have my code written I just have one error I am stuck on, any help is greatly appreciated, thanks in advance.

My one error is on line 80 saying "illegal start of expression" pointing at the 'p' of public

import javax.swing.*;
import BreezySwing.*;

public class binary extends GBFrame
{
 private JLabel ArrayLengthLabel;
 private JLabel DataEntryLabel;
 private JLabel TargetValueLabel;
 private IntegerField ArrayLengthField;
 private IntegerField DataEntryField;
 private IntegerField TargetValueField;
 private JButton SetLengthButton;
 private JButton InsertDataButton;
 private JButton SearchButton;
 int count = 0;
 int search;
 int k = 0;
 boolean exchangeMade = true;
 int temp = 0;
 int[] fin = new int[10];
 int left = 0;
 int right =a.length -1;

	public binary()
	{
	  ArrayLengthLabel = addLabel ("Array Length" ,1,1,1,1);
	  DataEntryLabel = addLabel ("Data Entry" ,1,2,1,1);
	  TargetValueLabel = addLabel ("Target Value" ,1,3,1,1);
	  ArrayLengthField = addIntegerField (0 ,2,1,1,1);
	  DataEntryField = addIntegerField (0 ,2,2,1,1);
	  TargetValueField = addIntegerField (0 ,2,3,1,1);
	  SetLengthButton = addButton ("Set Length" ,3,1,1,1);
	  InsertDataButton = addButton ("Insert Data" ,3,2,1,1);
	  SearchButton = addButton ("Search" ,3,3,1,1);
	}

	public void buttonClicked(JButton buttonObj)
	{
		if(buttonObj == SetLengthButton)
		{
		  int[] fin = new int[ArrayLengthField.getNumber()];
		}
		
		else if(buttonObj == InsertDataButton)
		{
		  fin[count] = DataEntryField.getNumber();
		  count++;
		while((k < fin.length -1) && exchangeMade)
		  {
		  exchangeMade = false;
		  k++;
		  for(int j = 0; j < fin.length - k; j++)
		   {
		    if(fin[j] > fin[j+1])
		    {
		    temp = fin[j+1];
		    fin[j] = fin[j+1];
		    fin[j] = temp;
		    exchangeMade = true;
		    }
		   }
		  }
		}
		
		else if(buttonObj == SearchButton)
		{
		  search = TargetValueField.getNumber();
		  while (left <= right)
		  {
		  int midpoint = (left + right)/2;
		  if(fin[midpoint] == searchValue)
		    return midpoint;
		  else if (fin[midpoint] < searchValue)
		    left = midpoint + 1;
		  else
		    right = midpoint -1;
		}
		return -1;
	}
	public static void main (String[] args)
	{
	binary theGUI = new binary();
	theGUI.setSize(500, 500);
	theGUI.setVisible(true);
	}
;	
}
}
4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by cretaros
0

java is strictly:

1/ CaseSensitive

2/ Method Sensitive, (replace binary to myBinary)

maybe someone can help you with error

0

I'd look at your braces. That lonely close brace on line 87 tells me that you're out of balance in buttonClicked, and you filled in a brace at the end, but that's not where it's needed.
Go through and fix your indentation. Do it by hand and it should jump out at you.

0

Try putting the main method outside of the buttonClicked method - put it after the closing brace on line 87.

You'll then want to get rid of the "return -1", which is illegal since buttonClicked can't return an int. (or anything) You can also eliminate that unused semicolon, while you're at it.
That may sort things out for you.

0

jon.kiparsky suggest you put the main jst b4 the last brace of the class as follows

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.