•
•
•
•
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
![]() |
•
•
Join Date: Mar 2006
Posts: 11
Reputation:
Rep Power: 3
Solved Threads: 0
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
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
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
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation:
Rep Power: 18
Solved Threads: 195
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:
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.

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.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Python GUI (Python)
- GUI, matrix and vector libraries (C++)
- Python GUI build: Logic Complications and Mistakes (Python)
- trouble understanding widget commands (Python)
- Click event >> window appears? (Python)
- Data From C++ GUI to Excel/Notepad, Application Trouble (C++)
Other Threads in the Java Forum
- Previous Thread: cell phone
- Next Thread: CPU Scheduling Algorithm



Linear Mode