• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to call a constructor from action performed method of a button?  RSS feed

 
Shobana Sukumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hav a method like

public void actionPerformed(ActionEvent e)
{

if (e.getActionCommand().equals("Next"))
{
System.out.println("next");
}

}
} now how to call a constructor in the same program from this actionperformed method?
 
jaspal singh
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

u did not mention which object u wanna initialize.

to initiate object u just declare the instance dependin on ur requirement.

and then u can call new to allocate memeory.

e.g.
//declare at the start of class

Employee e1;


then in actionperformed method u can call constuctor to to initialize the object.

e.g.
actionperformed(Event e)
{
e1 = new Employee();
}


ho p u got it.may be not
 
Shobana Sukumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is i need to call a constructor which has resultset as its argument.in that case i need to call that from the actionperformed method which must also contain a resultset.but the action performed method doestnt have a resultset. so wot do do
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A constructor is not a normal method. This cannot be called explicitly like calling other methods.A constructor can only be call implicitly while creating an instance of a class
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shobana Sukumar:
the problem is i need to call a constructor which has resultset as its argument.in that case i need to call that from the actionperformed method which must also contain a resultset.but the action performed method doestnt have a resultset. so wot do do


Basically I feel passing resultset to a method is not a good design.
You can use a transfer object for solving this.
Please google for Transfer objget to get more idea
http://faq.javaranch.com/view?DataTransferObject
[ December 14, 2005: Message edited by: Srinivasa Raghavan ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... your post seems to be getting scatter-shot replies. Perhaps the best way to allow forum members to help you would be if you explained what your are trying to do, what your goal is. Just mentioning that you want to invoke a construction and later that, oh by the way, I need to pass it a ResultSet, is not revealing the right sort of information.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!