Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java+Swing+unixconnectivity  RSS feed

 
Shivani Monga
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey..

Little help needed here..

I have a frame two buttons:
button 1: killbutton (added actionevent on this, which kills a particular UNIX process passed as argument from other
components)
button 2: startbutton (added actionevent on this one too, which should start the killed UNIX process passed as argument
other components)

Now, I have created a connection class and a session class.. and am instantiating the connection class and session class on the event on killbutton

public class homeframe extends javax.swing.JFrame {
String username = "uname";
String password = "pswd";
String hostip= "";
String processname="";
// I can't instantiate Connection class here because its constructor takes an argument "hostip", which is decided at runtime (on click of "killbutton")
private void killbuttonActionPerformed(java.awt.event.ActionEvent evt) {
try
{
if (comboserver.getSelectedItem().equals("machine1"))
{hostip = <machine1 IP>;}

else if (comboserver.getSelectedItem().equals("machine2"))
{hostip = "<machine2 IP>";}

Connection conn = new Connection(hostip);// connection created here would mean that i can't use conn instance outside //killbuttonActionPerformed
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
Session sess = conn.openSession();
...
...
conn.close();
sess.close();
}

private void startbuttonActionPerformed(java.awt.event.ActionEvent evt)
{

}

In this scenario, I will have to make a new connection for the "startbutton" event but I don't want that. I want the connection to be made just once, though there can be multiple sessions on that one connection (e.g. one session to kill the process and second session to start the process)

How's it possible in this scenario that I can just make the connection once and use its instance throughout the code?
 
Shivani Monga
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call me Dumb --

I did it.. let me know if anyone wants to know how
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!