2 Replies - 2003 Views - Last Post: 04 January 2011 - 12:34 PM Rate Topic: -----

#1 paniraj s  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-December 10

java error -class or interface expected

Posted 04 January 2011 - 03:19 AM

Dear Sir,
i have written code for "chatting system". while compiling , above error occured. the sample code is as follows:
//The client program:

	/*The Client program provide an graphical user interface for the clients.
	The program is explained function by function.*/

	/*Importing all required packages*/

	import javax.swing.*;//1235
	import javax.swing.border.*;//1236
	import java.applet.*;
	import java.awt.*;
	import java.awt.event.*;
	import java.io.*;
	import java.net.*;
	import java.util.*;
	import java.util.StringTokenizer;//1243

	/*The ClientApp class is the main applet  class of the program. In this class an
	instance of the client class is created and added to the content pane of the applet.
	Every class can extended only from one class and the client class extends  from the
	JTabbedPane class. In order to incorporate this instance into an applet the above
	said method has been employed */

	public class ClientApp extends JApplet
	{
	Client clt;

	public void init()
	{  getContentPane().setBackground(new Colour(139,158,142));
	   getContentPane().add(new Client());
	  }
	}

	/*The class client ,carries out the actual work of enabling the user to chat. The
	class implements the ActionListener and the Runnable interfaces as it makes use of
	buttons and threads. It extends the JTabbedPane class as it needs to behave as
	Tabbed Pane*/

	class Client extends JTabbedPane implements ActionListener,Runnable
	{
	/*Declaration of Variables*/

	/*These are the two main panels: panel1--the login panel and panel2--the main chat
	panel*/

	private JPanel panel1;
	private JPanel panel2;


	/*These variables are used throughout the program*/

	/*These variables used for arranging components*/

	private GridBagLayout gl;
	private GridBagConstraints gbc;

	/*The flags used to indicate various conditions*/


	private int loginFlag=0;
	private int disconFlag=1;

	/*Variables used to store essential values*/

	private String ourName="";
	private String password;
	private String room="none";

	private String dec="zero";
	private String requestor="no one";
	private String requestee="no one";
	private String tok="#";

	/*The variable used to establish the actual connection with the server and
	a thread which detects incoming messages*/

	private Socket socket;
	private DataOutputStream dout;
	private DataInputStream din;
	private Thread usrthrd;

	/*The variables requierd for panel1 are declared below*/




and so on
the error in lines are

D:\java1.4.2\bin>javac *.java
chatcode.java:1235: 'class' or 'interface' expected
        import javax.swing.*;
        ^
chatcode.java:1236: 'class' or 'interface' expected
        import javax.swing.border.*;
        ^
chatcode.java:1237: 'class' or 'interface' expected
        import java.applet.*;
        ^
chatcode.java:1238: 'class' or 'interface' expected
        import java.awt.*;
        ^
chatcode.java:1239: 'class' or 'interface' expected
        import java.awt.event.*;
        ^
chatcode.java:1240: 'class' or 'interface' expected
        import java.io.*;
        ^
chatcode.java:1241: 'class' or 'interface' expected
        import java.net.*;
        ^
chatcode.java:1242: 'class' or 'interface' expected
        import java.util.*;
        ^
chatcode.java:1243: 'class' or 'interface' expected
        import java.util.StringTokenizer;
        ^
9 errors



pl help me to compile
regards

Edited by Dogstopper: :code:
paniraj

This post has been edited by Dogstopper: 04 January 2011 - 03:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: java error -class or interface expected

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: java error -class or interface expected

Posted 04 January 2011 - 03:33 AM

what code is before line 1235 in the program?
it looks like you have import statements in the middle of your program
put them at the start of the code before the class statement
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: java error -class or interface expected

Posted 04 January 2011 - 12:34 PM

Please :code:
and indent your code properly

import javax.swing.*;//1235
import javax.swing.border.*;//1236
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.StringTokenizer;//1243

/*The ClientApp class is the main applet class of the program. In this class an
instance of the client class is created and added to the content pane of the applet.
Every class can extended only from one class and the client class extends from the
JTabbedPane class. In order to incorporate this instance into an applet the above
said method has been employed */

public class ClientApp extends JApplet
{
	Client clt;

	public void init()
	{ 
		getContentPane().setBackground(new Colour(139,158,142));
	    getContentPane().add(new Client());
	}
}

/*The class client ,carries out the actual work of enabling the user to chat. The
class implements the ActionListener and the Runnable interfaces as it makes use of
buttons and threads. It extends the JTabbedPane class as it needs to behave as
Tabbed Pane*/

class Client extends JTabbedPane implements ActionListener,Runnable
{
	/*Declaration of Variables*/

	/*These are the two main panels: panel1--the login panel and panel2--the main chat
panel*/

	private JPanel panel1;
	private JPanel panel2;


	/*These variables are used throughout the program*/

	/*These variables used for arranging components*/

	private GridBagLayout gl;
	private GridBagConstraints gbc;

	/*The flags used to indicate various conditions*/


	private int loginFlag=0;
	private int disconFlag=1;

	/*Variables used to store essential values*/

	private String ourName="";
	private String password;
	private String room="none";

	private String dec="zero";
	private String requestor="no one";
	private String requestee="no one";
	private String tok="#";

	/*The variable used to establish the actual connection with the server and
a thread which detects incoming messages*/

	private Socket socket;
	private DataOutputStream dout;
	private DataInputStream din;
	private Thread usrthrd;

	/*The variables requierd for panel1 are declared below*/






And post all your code, you obviously have a } or a { missing
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1