| | |
re: Trouble with GUI
![]() |
•
•
Join Date: Mar 2006
Posts: 11
Reputation:
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
Java Syntax (Toggle Plain Text)
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:
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:
Java Syntax (Toggle Plain Text)
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






