2 Replies - 234 Views - Last Post: 21 April 2011 - 08:59 PM Rate Topic: -----

#1 dbzfanl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-December 09

Distributed Programming and Action Listeners

Posted 21 April 2011 - 10:54 AM

Hello there! I've got a question (or two) that I can't seem to find an easy answer to.

I'm trying to design a sports drafting program. The problem is, I can't really get any solid information on what type of connection (socket, RMI, etc) would be best for doing such a thing. Should I use a database or a list of some sort, and which connection is better depending on the situation? The program will be set up with a "server" at my house with a form of input so I can start and manage the draft (and it will also be able to e-mail but that's besides the point), and the "clients" will have a combo box of choices for the players that will either disappear or will not be available for selection if they are drafted.

Also, about action listeners: it's been a while since I used GUIs and I think I'm confusing myself. How do I add multiple action listener methods for different buttons in the same class?

Thanks and much appreciated,
Ken

Is This A Good Question/Topic? 0
  • +

Replies To: Distributed Programming and Action Listeners

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,672
  • Joined: 13-March 10

Re: Distributed Programming and Action Listeners

Posted 21 April 2011 - 12:13 PM

I am studying RMI right now so im glad you asked. RMI is quite good because it does a LOT of stuff behind the scenes e.g. listeneing for connections, assigning new socket for the communication. With the server-cient architecture (using Sockets and ServerSockets) you would need to hand code it.
Please note that RMI is used for distributed apps. The idea is that you call the object on the server and you get the return value on the client side. Its NOT really that hard to program. You just need to make sure you have the interface that extends Remote and every method throws RemoteException.
Then you create a class that implements these methods - that would be your server. Then you create the Client class - check you Swing - and you can call the methods that were defined in the interface and work will be done in the class that implementeed interface.

About action listeners you need to have if statemens or separate inner classes. I show you sample if statements:

private JButton buttonOne,buttonTwo;

//some code

buttonOne.addActionListener(this);
buttonTwo.addActionListener(this);

//some code


public void actionPerformed(ActionEvent event)
{
  //if statements i was talking about
   if(event.getSource() == buttonOne)
   {
        //action for button one
   }else if(event.getSource() == buttonTwo)
   {
       //action for button two
   }
}




Note that the actionPerformed() method will be called every time button is clicked.
Hope it helps.
Was This Post Helpful? 0
  • +
  • -

#3 dbzfanl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-December 09

Re: Distributed Programming and Action Listeners

Posted 21 April 2011 - 08:59 PM

So, in your opinion, RMI would probably be better suited for my situation?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1