Results 1 to 2 of 2
Thread: Student GUI with RMI Server
- 03-01-2013, 10:26 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
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
StudentClient CodeJava 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"); } }
If you need the Rest of the Code it can be provided.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(); } } }
Thank You in advance.
- 03-05-2013, 02:09 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
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
-
Jsp:add student
By mamtha in forum New To JavaReplies: 6Last Post: 01-16-2012, 07:26 AM -
student need help
By adamrain in forum New To JavaReplies: 9Last Post: 11-28-2009, 11:10 PM -
Student Help
By mattwaab in forum Java AppletsReplies: 0Last Post: 02-08-2008, 05:31 PM -
help student
By jvasilj1 in forum New To JavaReplies: 15Last Post: 02-02-2008, 08:23 AM -
please help a student
By jvasilj1 in forum New To JavaReplies: 0Last Post: 02-01-2008, 01:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks