# Looking for Java help



## Psychohyena (Mar 19, 2010)

Hi people,

I'm in the process of making a Java-based chat program as part of a course and I've run into a problem and as it's the weekend I can't check with my tutor what's going wrong and it will drive me crazy.

The folder structure is as follows:

Chatmaniax (main folder)
----> Client (Client class)
        Stuffs (package folder)
                  aGUI (GUI class)
                  Send (Send thread class)
                  Receive (Receive thread class)
Send code:

```
package Stuffs;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Send extends Thread
{
	public aGUI myGUI;
	
	public void Send(aGUI newGUI)
	{
		myGUI = newGUI;
	}	
}
```

aGUI code:

```
package Stuffs;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class aGUI extends JFrame
{
	public JButton Send = new JButton();
	public JButton Exit = new JButton();
	public JTextArea chatArea;
	public JTextField myText = new JTextField();
	public JScrollPane scroller;
	public JPanel textPanel = new JPanel();
	public String sendText = null;
	public boolean sendMsg = false;
	
	public void Create()
	{
		CreateButtons();
		CreateTextStuff();
		CreateWindow();
	}
	
	public void CreateButtons()
	{
		//Setup the Send Button.
		Send.setText("Send");
		Send.setToolTipText("Send a message");
		Send.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				sendText = GetText();
				chatArea.append(sendText);
				sendMsg = true;
			}
		});
		
		//Setup the Exit button.
		Exit.setText("Exit");
		Exit.setToolTipText("Close the program");
		Exit.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				sendText = "quit";
				System.exit(0);
			}
		});
	}
	
	public void CreateTextStuff()
	{
		textPanel.setLayout(new BoxLayout(textPanel,BoxLayout.PAGE_AXIS));
		textPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
		
		
		chatArea = new JTextArea();
		chatArea.setEditable(false);
		chatArea.setLineWrap(true);
		scroller = new JScrollPane(chatArea);
		textPanel.add(Box.createRigidArea(new Dimension(0,5)));
		textPanel.add(scroller);
		scroller.setPreferredSize(new Dimension(200,150));
		scroller.setAlignmentX(Component.LEFT_ALIGNMENT);
		textPanel.add(Box.createRigidArea(new Dimension(0,5)));
		myText.setAlignmentX(Component.LEFT_ALIGNMENT);
		myText.setMaximumSize(new Dimension(256,1));
		myText.setColumns(15);
		myText.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				chatArea.append(myText.getText()+ "\n");
			}
		});
		textPanel.add(myText);
		textPanel.add(Box.createRigidArea(new Dimension(0,5)));
		textPanel.add(Send);
		
		Send.setAlignmentX(Component.LEFT_ALIGNMENT);
	}
	
	public void CreateWindow()
	{
		getContentPane().setLayout( new BorderLayout());
		setSize(300,300);
		Dimension dim;
		dim = Toolkit.getDefaultToolkit().getScreenSize();
		dim.width = dim.width/2 - 200;
		dim.height = dim.height/2 - 200;
		setBounds(dim.width, dim.height, 400, 400);
		getContentPane().add(Exit, BorderLayout.SOUTH);
		getContentPane().add(textPanel, BorderLayout.WEST);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public String GetText()
	{
		sendText = myText.getText();
		return sendText;
	}
}
```

Client code:

```
import Stuffs.*;

import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Client extends JFrame
{
	
	public static void main(String args[])
	{
		aGUI myClient = new aGUI();
		myClient.Create();
		Send mySender = new Send(myClient);
	}
}
```

Now when I go to compile it gives me the following error (I'm using a text editor with compile caps):
---------- Capture Output ----------
> "C:\Program Files\Java\jdk1.6.0_18\bin\javac.exe" I:\Javastuffs\Chatmaniax\Client.java
I:\Javastuffs\Chatmaniax\Client.java:16: cannot find symbol
symbol  : constructor Send(Stuffs.aGUI)
location: class Stuffs.Send
		Send mySender = new Send(myClient);
		                ^
1 error

> Terminated with exit code 1.

If someone could give me an idea of where I've gone wrong that would be great.


----------



## FordGT90Concept (Mar 19, 2010)

Make sure to compile the file with Stuffs.Send before Client.java.


----------



## temp02 (Mar 19, 2010)

Seems pretty obvious, you are missing the class contructor (actually it had an extra void so it was not being treated as a contructor, remove it and it should compile), it should be something like this:

```
package Stuffs;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Send extends Thread
{
	public aGUI myGUI;
	
	public [b][s]void[/s][/b] Send(aGUI newGUI)
	{
		myGUI = newGUI;
	}	
}
```

Also, if you really want this to be a thread I'll sugest that you take a glance at the SUN page for the Thread class.


----------



## FordGT90Concept (Mar 19, 2010)

Good catch.  It's past my bedtime.


----------



## Psychohyena (Mar 19, 2010)

temp02 said:


> Seems pretty obvious, you are missing the class contructor (actually it had an extra void so it was not being treated as a contructor, remove it and it should compile), it should be something like this:
> 
> ```
> package Stuffs;
> ...



Well dunno what I did but it's compiling. Thanks for pointing out the void in the constructor btw. After making the changes recommended etc it kept continuing to give me the error even when doing a compile from the command line. It's so annoying when you don't think you've made any changes and then it suddenly works.


----------

