-
Urgent Help Needed!!!!!
Hi, i have been told that there is a small modification i have to make to this implemenation code for it to work, can anyone show me where and what i have to write?
thanks a lot in advance
Also i have been told that i have to change a few thing sin the connect and disconnect parts, i dont know this either!!
implementation code:
*public class ChatClientImpl extends JFrame implements ChatClient {
private static final String DEFAULT_CODEBASE = "http://localhost/chat/";
private static final int DEFAULT_PORT = 1234;
private static final String TITLE = "Chat Client";
private String login;
private ChatService service;
private ChatClient sender = this;
private boolean connected = false;
private JTextField serverNameField;
private JTextField serverPortField;
private JTextField loginField;
private JButton connectButton;
private JButton disconnectButton;
private JTextField messageField;
private JButton sendButton;
private JTextArea messageArea;
*public String getLogin() throws RemoteException
{
return login;
}
*public void receiveChat(String message) throws RemoteException
{
messageArea.append(message + "\n");
}
*public ChatClientImpl()
{
createControls();
createMessageArea();
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
showStatus();
setVisible(true);
try {
UnicastRemoteObject.exportObject(this);
}
catch (Exception error) {
errorDialog(error);
}
}
*private void showStatus()
{
if (connected)
setTitle(TITLE + " : connected");
else
setTitle(TITLE + " : not connected");
}
*private void createControls()
{
JPanel controls = new JPanel(new GridLayout(5, 1));
JPanel panel = new JPanel();
panel.add(new JLabel("Server name", JLabel.RIGHT));
serverNameField = new JTextField(15);
serverNameField.setText("localhost");
panel.add(serverNameField);
controls.add(panel);
panel = new JPanel();
panel.add(new JLabel(" Port", JLabel.RIGHT));
serverPortField = new JTextField(10);
serverPortField.setText(String.valueOf(DEFAULT_PORT));
panel.add(serverPortField);
controls.add(panel);
panel = new JPanel();
panel.add(new JLabel("Login", JLabel.RIGHT));
loginField = new JTextField(10);
loginField.setText("?");
panel.add(loginField);
controls.add(panel);
panel = new JPanel();
addConnectButton(panel);
addDisconnectButton(panel);
controls.add(panel);
panel = new JPanel();
messageField = new JTextField(30);
panel.add(messageField);
addSendButton(panel);
controls.add(panel);
getContentPane().add(controls, BorderLayout.NORTH);
}
*private void addConnectButton(JPanel panel)
{
connectButton = new JButton("Connect");
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
connect();
if (connected) {
serverNameField.setEnabled(false);
serverPortField.setEnabled(false);
loginField.setEnabled(false);
connectButton.setEnabled(false);
}
}
});
panel.add(connectButton);
}
*private void addDisconnectButton(JPanel panel)
{
disconnectButton = new JButton("Disconnect");
disconnectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
disconnect();
serverNameField.setEnabled(true);
serverPortField.setEnabled(true);
loginField.setEnabled(true);
connectButton.setEnabled(true);
}
});
panel.add(disconnectButton);
}
*private void addSendButton(JPanel panel)
{
sendButton = new JButton("Send");
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
if (service != null) {
try {
service.sendMessage(sender, messageField.getText());
messageField.setText("");
}
catch (Exception error) {
errorDialog(error);
}
}
}
});
panel.add(sendButton);
}
*private void createMessageArea()
{
messageArea = new JTextArea(10, 40);
messageArea.setEditable(false);
getContentPane().add(new JScrollPane(messageArea), BorderLayout.CENTER);
}
*private void errorDialog(Exception error)
{
JOptionPane.showMessageDialog(this, error.getMessage(),
TITLE + " Error", JOptionPane.ERROR_MESSAGE);
}
*private void connect()
{
try
{
int port;
try {
port = Integer.parseInt(serverPortField.getText());
}
catch (Exception error) {
port = DEFAULT_PORT;
serverPortField.setText(String.valueOf(port));
}
showStatus();
login = loginField.getText();
}
catch (Exception error) {
service = null;
connected = false;
showStatus();
errorDialog(error);
}
}
*private void disconnect()
{
try {
if (service != null) {
}
}
catch (Exception error) {
errorDialog(error);
}
finally {
connected = false;
showStatus();
}
}
*public static void setCodeBase()
{
String codebase = System.getProperty("java.rmi.server.codebase");
if (codebase == null) {
Properties sysProps = System.getProperties();
sysProps.put("java.rmi.server.codebase", DEFAULT_CODEBASE);
System.setProperties(sysProps);
}
}
*public static void main(String[] argv)
{
System.setSecurityManager(new RMISecurityManager());
setCodeBase();
JFrame app = new ChatClientImpl();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks