User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 401,720 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,112 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 789 | Replies: 3
Reply
Join Date: Mar 2006
Posts: 11
Reputation: crws416 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
crws416 crws416 is offline Offline
Newbie Poster

Question re: Trouble with GUI

  #1  
Apr 14th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Trouble with GUI

  #2  
Apr 14th, 2006
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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Mar 2006
Posts: 11
Reputation: crws416 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
crws416 crws416 is offline Offline
Newbie Poster

Re: Trouble with GUI

  #3  
Apr 14th, 2006
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
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Trouble with GUI

  #4  
Apr 15th, 2006
quick hacks lead to big problems later on...
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC