Results 1 to 2 of 2
  1. #1
    Irish Rayray is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Student GUI with RMI Server

    Hi All,

    I have a program which creates a RMI server for a student Client like so

    Name Address Class Group
    Tom Low Street Web 2
    Mary High Street Game 2
    John Midd Street Web 2

    And i have a gui which use the 3 heading but i want to get the gui to be automatically updated when run not by clicking a button to show the updated information not the information above which is displayed just after this.

    Like picture below.
    Lab_8.1_Client.bmp

    Its just the GUI bit im stuck on i can not finad out how to populate the GUI with this information.

    This is the Gui code
    Java Code:
    import java.awt.event.*;
    
    import javax.swing.*;
    import java.awt.GridLayout;
    
    public class StudentGui extends JFrame
    {
    	private JTextField NameLabel= new JTextField("Name");
    	private JTextField AddressLabel= new JTextField("Address");
    	private JTextField GroupLabel= new JTextField("Group");
    	private JTextField FirstName= new JTextField(" ");
    	private JTextField SecondName= new JTextField(" ");
    	private JTextField ThirdName= new JTextField(" ");
    	private JTextField FirstAddress= new JTextField(" ");
    	private JTextField SecondAddress= new JTextField(" ");
    	private JTextField ThirdAddress= new JTextField(" ");
    	private JTextField FirstGroup= new JTextField(" ");
    	private JTextField SecondGroup= new JTextField(" ");
    	private JTextField ThirdGroup= new JTextField(" ");
    	
    	StudentGui(String s){
    		super(s);
    		
    			getContentPane().setLayout(new GridLayout(4,3));
    			getContentPane().add(NameLabel);
    			getContentPane().add(AddressLabel);
    			getContentPane().add(GroupLabel);
    			getContentPane().add(FirstName);
    			getContentPane().add(FirstAddress);
    			getContentPane().add(FirstGroup);
    			getContentPane().add(SecondName);
    			getContentPane().add(SecondAddress);
    			getContentPane().add(SecondGroup);
    			getContentPane().add(ThirdName);
    			getContentPane().add(ThirdAddress);
    			getContentPane().add(ThirdGroup);
    			
    			setSize(350,150);
    		    setVisible(true);
    		    
    	}
    	  public static void main(String[] args){
    		 new StudentGui("RMI GUI Client");
    	  }
    }
    StudentClient Code

    Java Code:
    import java.rmi.*;
    
    public class StudentClient
    {
        public static void main(String args[]){
            String url = "rmi:///";
    
            try{
                StudentInterface aTom=(StudentInterface)Naming.lookup(url+"Tom");
                StudentInterface aMary=(StudentInterface)Naming.lookup(url+"Mary");
                StudentInterface aJohn=(StudentInterface)Naming.lookup(url+"John");
    
                System.out.println("Name	Address		Class Group");
            	System.out.println(aTom.getName()+"	"+aTom.getAddress()+"	"+aTom.getGroup());
            	System.out.println(aMary.getName()+"	"+aMary.getAddress()+"	"+aMary.getGroup());
            	System.out.println(aJohn.getName()+"	"+aJohn.getAddress()+"	"+aJohn.getGroup());
                
                System.out.println("\n" + "Changed too:" + "\n" );
    
                aTom.setAddress("Lower Street");
                aMary.setAddress("Higher Street");
                aMary.setGroup("Game 3");
                aJohn.setGroup("Web 3");
                
                System.out.println("Name	Address		Class Group");
            	System.out.println(aTom.getName()+"	"+aTom.getAddress()+"	"+aTom.getGroup());
            	System.out.println(aMary.getName()+"	"+aMary.getAddress()+"	"+aMary.getGroup());
            	System.out.println(aJohn.getName()+"	"+aJohn.getAddress()+"	"+aJohn.getGroup());
    
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    If you need the Rest of the Code it can be provided.

    Thank You in advance.

  2. #2
    Irish Rayray is offline Member
    Join Date
    Apr 2012
    Posts
    21
    Rep Power
    0

    Default Re: Student GUI with RMI Server

    Hi all,

    Just in case anyone ever does anything like this this is how i figured it out in the end was quite easy :)


    Java Code:

    Java Code:
    import java.awt.event.*;
     
    import javax.swing.*;
    import java.awt.GridLayout;
    import java.rmi.Naming;
     
    public class StudentGui extends JFrame
    {
        private JTextField NameLabel= new JTextField("Name");
        private JTextField AddressLabel= new JTextField("Address");
        private JTextField GroupLabel= new JTextField("Group");
        private JTextField FirstName= new JTextField("");
        private JTextField SecondName= new JTextField("");
        private JTextField ThirdName= new JTextField("");
        private JTextField FirstAddress= new JTextField("");
        private JTextField SecondAddress= new JTextField("");
        private JTextField ThirdAddress= new JTextField("");
        private JTextField FirstGroup= new JTextField("");
        private JTextField SecondGroup= new JTextField("");
        private JTextField ThirdGroup= new JTextField("");
         
        String url = "rmi:///";
         
        StudentGui(String s){
            super(s);
             
                getContentPane().setLayout(new GridLayout(4,3));
                getContentPane().add(NameLabel);
                getContentPane().add(AddressLabel);
                getContentPane().add(GroupLabel);
                getContentPane().add(FirstName);
                getContentPane().add(FirstAddress);
                getContentPane().add(FirstGroup);
                getContentPane().add(SecondName);
                getContentPane().add(SecondAddress);
                getContentPane().add(SecondGroup);
                getContentPane().add(ThirdName);
                getContentPane().add(ThirdAddress);
                getContentPane().add(ThirdGroup);
                 
                setSize(350,150);
                setVisible(true);    
                 
                try{
                    StudentInterface aTom=(StudentInterface)Naming.lookup(url+"Tom");
                    FirstName.setText(aTom.getName());
                    FirstAddress.setText(aTom.getAddress());
                    FirstGroup.setText(aTom.getGroup());
                    StudentInterface aMary=(StudentInterface)Naming.lookup(url+"Mary");
                    SecondName.setText(aMary.getName());
                    SecondAddress.setText(aMary.getAddress());
                    SecondGroup.setText(aMary.getGroup());
                    StudentInterface aJohn=(StudentInterface)Naming.lookup(url+"John");
                    ThirdName.setText(aJohn.getName());
                    ThirdAddress.setText(aJohn.getAddress());
                    ThirdGroup.setText(aJohn.getGroup());
                }catch(Exception a){
                    a.printStackTrace();
                }
        }
          public static void main(String[] args){
             new StudentGui("RMI GUI Client");
          }
    }

Similar Threads

  1. Jsp:add student
    By mamtha in forum New To Java
    Replies: 6
    Last Post: 01-16-2012, 08:26 AM
  2. student need help
    By adamrain in forum New To Java
    Replies: 9
    Last Post: 11-29-2009, 12:10 AM
  3. Student Help
    By mattwaab in forum Java Applets
    Replies: 0
    Last Post: 02-08-2008, 06:31 PM
  4. help student
    By jvasilj1 in forum New To Java
    Replies: 15
    Last Post: 02-02-2008, 09:23 AM
  5. please help a student
    By jvasilj1 in forum New To Java
    Replies: 0
    Last Post: 02-01-2008, 02:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •