944,093 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1373
  • Java RSS
Apr 14th, 2006
0

re: Trouble with GUI

Expand Post »
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

Java Syntax (Toggle Plain Text)
  1. package rmicc;
  2.  
  3. import java.awt.Toolkit;
  4. import javax.swing.SwingUtilities;
  5. import javax.swing.UIManager;
  6. import java.awt.Dimension;
  7. import java.util.*;
  8. import java.io.*;
  9.  
  10. /**
  11.  * <p>Title: Server </p>
  12.  *
  13.  * <p>Description: </p>
  14.  *
  15.  * <p>Copyright: Copyright (c) 2006</p>
  16.  *
  17.  * <p>Company: </p>
  18.  *
  19.  * @author not attributable
  20.  * @version 1.0
  21.  */
  22. public class Server extends java.rmi.server.UnicastRemoteObject implements IntServer{
  23. boolean packFrame = false;
  24.  
  25. String message = new String();
  26. String time = new String();
  27. Calendar cal = Calendar.getInstance();
  28.  
  29. ArrayList Users = new ArrayList();
  30. ArrayList UserNames = new ArrayList();
  31.  
  32. String ErrorLog = new String();
  33. String RegLog = new String();
  34. String ChatLog = new String();
  35. String WhisperLog = new String();
  36.  
  37. /**
  38.   * Construct and show the application.
  39.   */
  40. public Server() throws java.rmi.RemoteException{
  41.  
  42. Frame1 frame = new Frame1();
  43. if (packFrame) {
  44. frame.pack();
  45. }
  46. else {
  47. frame.validate();
  48. }
  49.  
  50. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  51. Dimension frameSize = frame.getSize();
  52. if (frameSize.height > screenSize.height) {
  53. frameSize.height = screenSize.height;
  54. }
  55. if (frameSize.width > screenSize.width) {
  56. frameSize.width = screenSize.width;
  57. }
  58. frame.setLocation( (screenSize.width - frameSize.width) / 2,
  59. (screenSize.height - frameSize.height) / 2);
  60. frame.setVisible(true);
  61.  
  62. try {
  63. jbInit();
  64. }
  65. catch (Exception ex) {
  66. ex.printStackTrace();
  67. }
  68. }
  69.  
  70.  
  71. public void setClientMessage(String Sender, String User, String clientMessage, int S)
  72. throws java.rmi.RemoteException
  73. {
  74. //code omitted
  75. }
  76.  
  77.  
  78.  
  79. public void setServerMessage(String User, int State, String note)
  80. throws java.rmi.RemoteException
  81. {
  82.  
  83. //code omitted
  84. }
  85.  
  86. public void setClient(ClientInt c, int flag)
  87. throws java.rmi.RemoteException
  88. {
  89. //code omitted
  90. }
  91.  
  92. public void register(String Username)
  93. throws java.rmi.RemoteException
  94. {
  95. //code omitted
  96. }
  97.  
  98. public void unregister(String User)
  99. throws java.rmi.RemoteException
  100. {
  101. //code omitted
  102. }
  103.  
  104. public void Broadcast(String message)
  105. {
  106. //code omitted
  107. }
  108.  
  109. public String EncryptDecrypt(String message)
  110. {
  111. //code omitted
  112. }
  113.  
  114. public void XML(String LogName, String Tag, int Level, int Stage, String nodeData){
  115. //code omitted
  116. }
  117.  
  118. public void Unicast(int Type,String Sender,String User, int State, String note)
  119. {
  120. //code omitted
  121. }
  122.  
  123. /*Application entry point.
  124.   public static void main(String[] args) {
  125.   SwingUtilities.invokeLater(new Runnable() {
  126.   public void run() {
  127.   try {
  128.   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  129.   }
  130.   catch (Exception exception) {
  131.   exception.printStackTrace();
  132.   }
  133.  
  134. // new Server();
  135.   }
  136.   });
  137.   }
  138.  
  139.   private void jbInit() throws Exception {
  140.   }
  141. }
  142.  

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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crws416 is offline Offline
11 posts
since Mar 2006
Apr 14th, 2006
0

Re: Trouble with GUI

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:
Java Syntax (Toggle Plain Text)
  1. if (!GraphicsEnvironment.isHeadless()) {
  2. // graphical environment available, launch GUI for interactive mode
  3.  
  4. MainFrame frame = new MainFrame(serverProps);
  5. frame.validate();
  6. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  7. Dimension frameSize = frame.getSize();
  8. if (frameSize.height > screenSize.height) {
  9. frameSize.height = screenSize.height;
  10. }
  11. if (frameSize.width > screenSize.width) {
  12. frameSize.width = screenSize.width;
  13. }
  14. frame.setLocation((screenSize.width - frameSize.width) / 2,
  15. (screenSize.height - frameSize.height) / 2);
  16. frame.setVisible(true);
  17.  
  18. } else {
  19. // no graphical subsystem, launch server without interactive mode
  20. // using the values from the properties file
  21. Server server = new Server(
  22. Integer.parseInt(serverProps.getProperty("rmi.port")),
  23. serverProps.getProperty("server.file"),
  24. serverProps.getProperty("rmi.service"),
  25. Integer.parseInt(serverProps.getProperty("server.timeout")));
  26. try {
  27. server.startServer();
  28. } catch (RemoteException ex) {
  29. System.err.println(server.getMessages());
  30. return;
  31. } catch (IOException ex) {
  32. System.err.println(server.getMessages());
  33. return;
  34. }
  35.  
  36. }

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 14th, 2006
0

Re: Trouble with GUI

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crws416 is offline Offline
11 posts
since Mar 2006
Apr 15th, 2006
0

Re: Trouble with GUI

quick hacks lead to big problems later on...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: cell phone
Next Thread in Java Forum Timeline: CPU Scheduling Algorithm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC