compile error

"class or interface expected"

Page 1 of 1

3 Replies - 1080 Views - Last Post: 11 April 2007 - 05:18 PM Rate Topic: -----

#1 luke1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-April 07

compile error

Posted 11 April 2007 - 11:13 AM

hey, the code below is part of a basic prison program. this part of the program adds test data into two arrays, prisoners and wardens. it also sets up a new GUI. i have attempted to display the contents of the prisoners array in a text area on the JFrame. however when i compile the code i get 3 errors:

PrisonGUI.java:112: 'class' or 'interface' expected
public static void main (String args[])
^
PrisonGUI.java:116: 'class' or 'interface' expected
}
^
PrisonGUI.java:118: 'class' or 'interface' expected
^
3 errors

i know that these errors are usually caused because of to many {} however i have checked my program and it looks ok to me. i am new to the GUI side of java so any help would be much appreciated. if any of the other classes that this part of the program links to are needed to be able to understand the code then please ask.

thanks for any help **Luke**

import java.awt.*;
import javax.swing.*;

public class PrisonGUI extends JFrame implements ActionListener
{

	private PrisonCanvas canvas;
	private JButton addPrisoner;
	private JButton addhsPrisoner;
	private JButton addWarden;
	private JButton viewPrisoners;
	private JButton viewhsPrisoners;
	private JButton viewWardens;

	private JTextArea displayArea;

	private Prison CarltonHouse;

	

	public PrisonGUI()
	{
		setLooknFeel();

		setTitle("Carlton House Prison");
		setBounds(0, 0, 500,300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Add some sample data

		Prisoners Dave = new Prisoners("Dave","Taylor",24, 501);
		Prisoners Matt = new Prisoners("Matt","Smith",35, 502);
		Prisoners Adam = new Prisoners("Adam","Jones",19, 503);

		Prison CarltonHouse = new Prison("Carlton House",30, 30, 30);
		CarltonHouse.addPrisoner(Dave);
		CarltonHouse.addPrisoner(Matt);
		CarltonHouse.addPrisoner(Adam);	

		canvas = new PrisonCanvas();
		getContentPane().add("Center", canvas);

		addPrisoner = new JButton("Add Prisoner");
		addhsPrisoner = new JButton("Add HS Prisoner");
		addWarden = new JButton("Add Warden");
		viewPrisoners = new JButton("View HS Prisoners");
		viewhsPrisoners = new JButton("View Prisoners");
		viewWardens = new JButton("View Wardens");

		JPanel buttonPanel = new JPanel(new GridLayout(2, 3, 3, 3));
		getContentPane().add("South", buttonPanel);

		buttonPanel.add(addPrisoner);
		buttonPanel.add(addhsPrisoner);
		buttonPanel.add(addWarden);
		buttonPanel.add(viewPrisoners);
		buttonPanel.add(viewhsPrisoners);
		buttonPanel.add(viewWardens);
		

		//*********Display Area********//

		JPanel northPanel = new JPanel();
				northPanel.setSize(1000,800);
				displayArea = new JTextArea("This is the display area" + "\nDetails of Prisoners will be displayed here			" +
								"\nPlease make your choice\n\n\n\n\n\n" );
				JScrollPane scrollPane;
				scrollPane = new JScrollPane(displayArea);
				//scrollPane.setSize(300,300);
				northPanel.add(scrollPane);
				getContentPane().add("Center", northPanel);



		setVisible(true);
	}

	private void setLooknFeel()
		{
				String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
				try
			  {
						UIManager.setLookAndFeel(lookAndFeel);
				}
			catch (Exception e)
			{
		   		e.printStackTrace();
			}
		}


	public void actionPerformed(ActionEvent e)
		{
		 		if (e.getSource() == displayPrisoners)
				{
			 			// display all Prisoners
/*
				  displayArea.setText("Display of all Prisoners - next Prisoner");
				  for (int i = 1; i < 8; ++i)
				   		displayArea.append("\na Prisoner");
*/
			CarltonHouse.outputPrisonDetailsFOR(displayArea);
		 		}
/*		 		else if (e.getSource() == displayPrisonerDetails)
				{
			 			// display details of specific Prisoner
	 			displayArea.setText("Display Prisonerwith ID :");
*/		 		}

	}

	public static void main (String args[])
	{
		new PrisonGUI();
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: compile error

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: compile error

Posted 11 April 2007 - 11:18 AM

Your declaration in main may need to look more like:
PrisonGUI p1 = new PrisonGUI();


Was This Post Helpful? 0
  • +
  • -

#3 luke1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-April 07

Re: compile error

Posted 11 April 2007 - 11:40 AM

:angry: same three errors again. any more ideas?

**Luke**
Was This Post Helpful? 0
  • +
  • -

#4 keems21  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 185
  • Joined: 03-February 07

Re: compile error

Posted 11 April 2007 - 05:18 PM

Comment out the closed bracket above the main method.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1