HI all,

I'm having trouble putting a GUI on an existing java server program i have. I have added a frame to the code but all it does so far is pop up, there is no interaction.. I've tried moving all of my functions accross but to no avail.. i dont know if it is an issue with inheritance or what the general code is below

package rmicc;

import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
import java.util.*;
import java.io.*;

/**
 * <p>Title:  Server </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Server extends java.rmi.server.UnicastRemoteObject implements IntServer{
  boolean packFrame = false;

  String message = new String();                                                
  String time = new String();                                                   
  Calendar cal = Calendar.getInstance();                                        

  ArrayList Users = new ArrayList();                                            
  ArrayList UserNames = new ArrayList();                                        

  String ErrorLog = new String();
  String RegLog = new String();
  String ChatLog = new String();
  String WhisperLog = new String();

  /**
   * Construct and show the application.
   */
  public Server() throws java.rmi.RemoteException{

    Frame1 frame = new Frame1();
    if (packFrame) {
      frame.pack();
    }
    else {
      frame.validate();
    }

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    frame.setLocation( (screenSize.width - frameSize.width) / 2,
                      (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);

    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }


  public void setClientMessage(String Sender, String User, String clientMessage, int S)
      throws java.rmi.RemoteException
  {
    //code omitted
  }



  public void setServerMessage(String User, int State, String note)
      throws java.rmi.RemoteException
  {

    //code omitted
  }

  public void setClient(ClientInt c, int flag)
      throws java.rmi.RemoteException
  {
   //code omitted
  }

  public void register(String Username)
      throws java.rmi.RemoteException
  {
    //code omitted
  }

  public void unregister(String User)
      throws java.rmi.RemoteException
  {
    //code omitted
  }

  public void Broadcast(String message)
  {
      //code omitted
  }

  public String EncryptDecrypt(String message)
  {
    //code omitted
  }

  public void XML(String LogName, String Tag, int Level, int Stage, String nodeData){
    //code omitted
  }

  public void Unicast(int Type,String Sender,String User, int State, String note)
  {
    //code omitted
  }

  /*Application entry point.
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception exception) {
          exception.printStackTrace();
        }

//          new Server();
      }
    });
  }

  private void jbInit() throws Exception {
  }
}

I would be over the moon if some one could help, as this is really frustrating and im totally lost..

I've stripped the function code out as it would have made the code too large.

Any help appreciated

Cheers Guys

You did some modification to the code JBuilder generates for you I see ;)

You will need to design your screen and hook up the controls to enable the interaction.
You should also go for a proper object oriented approach, which would have the RMI functionality separate from the user interface.

That way you can do something like:

if (!GraphicsEnvironment.isHeadless()) {
            // graphical environment available, launch GUI for interactive mode

            MainFrame frame = new MainFrame(serverProps);
            frame.validate();
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = frame.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            frame.setLocation((screenSize.width - frameSize.width) / 2,
                              (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);

        } else {
            // no graphical subsystem, launch server without interactive mode
            // using the values from the properties file
            Server server = new Server(
                Integer.parseInt(serverProps.getProperty("rmi.port")),
                serverProps.getProperty("server.file"),
                serverProps.getProperty("rmi.service"),
                Integer.parseInt(serverProps.getProperty("server.timeout")));
            try {
                server.startServer();
            } catch (RemoteException ex) {
                System.err.println(server.getMessages());
                return;
            } catch (IOException ex) {
                System.err.println(server.getMessages());
                return;
            }

        }

to allow your server to also function on a machine that has no graphical shell using a configuration file to initialise it.
Mind I've not yet been able to actually test that code to see if the headless mode works, but I see no reason why it shouldn't.

cheers for the reply,

i will have to have a look into your suggestion.. i was kind of hoping for just a quick fix to get every thing transfered over to GUI, but it is beginning to not look that easy.

Cheers

quick hacks lead to big problems later on...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.