Calling a Swing class method from from another swing class method

Hi guys,
I'm desperate for help or a pointing in the right direction. Basically, I want to call the public void createUI method in class AddressUI in the public void createUI method of PartnerUI class. Is that legal? How do I go about it? Thanks.
package com.client.gui;
import java.awt.*;
import javax.swing.*;
import client.application.MainFrame;
import client.gui.base.BasicDialogUI;
import client.page.base.BasicDialogPage;
import client.table.model.AddressModel;
public class AddressUI extends BasicDialogUI{
     private static final long serialVersionUID = -1214150134433745466L;
     public AddressUI(MainFrame frame, BasicDialogPage page) {
          super(frame, page);
     @Override
     public void createUI() {
     AddressModel am = new AddressModel();
     JTable table = new JTable(am);
     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     table.setColumnSelectionAllowed(true);
     JScrollPane scroller = new JScrollPane(table);
     scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
     scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
     JPanel addressPanel = new JPanel(new FlowLayout());
     addressPanel.setBackground(Color.BLUE);
     addressPanel.setForeground(Color.WHITE);
     addressPanel.setOpaque(true);
     JLabel addressHeader = new JLabel("Anschriften:");
     JPanel addressHeaderPanel = new JPanel();
     addressHeaderPanel.setBackground(Color.BLUE);
     addressHeaderPanel.setForeground(Color.WHITE);
     addressHeader.setOpaque(true);
     addressHeaderPanel.add(addressHeader);
     JButton buttonNew = new JButton("Neu");
     JButton buttonChange = new JButton("Ändern");
     JButton buttonDelete = new JButton ("Löschen");
     JPanel buttonsPanel = new JPanel(new FlowLayout());
     buttonsPanel.add(buttonNew);
     buttonsPanel.add(buttonChange);
     buttonsPanel.add(buttonDelete);
     addressPanel.add(buttonsPanel, FlowLayout.RIGHT);
     addressPanel.add(scroller, FlowLayout.CENTER);
     addressPanel.add(addressHeaderPanel, FlowLayout.LEFT);
     public final void showUI() {
          createUI();
          getMainFrame().setDialogPanel(this);
          getMainFrame().pack();
          this.setVisible(true);
     @Override
     public void formToModel() {
     @Override
     public void modelToForm() {
     @Override
     public boolean validateUI() {
          return true;
package com.impaqgroup.pp.client.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JTable;
import com.impaqgroup.pp.client.application.MainFrame;
import com.impaqgroup.pp.client.gui.base.BasicDialogUI;
import com.impaqgroup.pp.client.page.base.BasicDialogPage;
import com.impaqgroup.pp.client.table.model.PartnerModel;
public class PartnerUI extends BasicDialogUI{
     private static final long serialVersionUID = 1024614598666310834L;
     public PartnerUI(MainFrame frame, BasicDialogPage page) {
          super(frame, page);
     @Override
     public void createUI() {
          JPanel partnerPanel = new JPanel();
          partnerPanel.setBackground(Color.BLUE);
          partnerPanel.setForeground(Color.WHITE);
          partnerPanel.setOpaque(true);
          PartnerModel pm = new PartnerModel();
          JTable partnerTable = new JTable(pm);
          partnerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          partnerTable.setColumnSelectionAllowed(true);
          partnerPanel.add(partnerTable, BorderLayout.CENTER);
     @Override
     public final void showUI() {
          createUI();
          getMainFrame().setDialogPanel(this);
          getMainFrame().pack();
          this.setVisible(true);
     @Override
     public void formToModel() {
     @Override
     public void modelToForm() {
     @Override
     public boolean validateUI() {
          return true;
}

Have you tried adding something like the below to PartnerUI#createUI() ?
AddressUI aui = new AddressUI( getMainFrame(), getPage() );
aui.createUI();

Similar Messages

  • Initialize/set a base class from a another base class instance

    Hi,
    How can I initialize/set a base class from a another base class instance? I do not want to do a copy of it.
    It would look something like:
    class A {...}
    class B extends A
        B(A a)
            // super = a;
        setA(A a)
            // super = a;
    }Thank you.

    erikku wrote:
    Thanks Winton. It is what I did first but A has lots of methods and if methods are later added to A, I will have to edit B again. For those two reasons, I wanted to use inheritance. The part I was not sure with was the way to initialize B's base (A).You pays your money and you takes your choice. One way (this way) you have to provide forwarders; the other way (inheritance) you have to provide constructors (and if A has a lot of em, you may be writing quite a few).
    Ask yourself this question: is every B also an A? No exceptions. Ever.
    If the answer is 'yes', then inheritance is probably the best way to go.
    However, if there is even the remotest chance that an instance of B should not exhibit 100% of the behaviour of A, now or in the future, then the wrapper style is probably what you want.
    Another great advantage of the wrapper style is that methods can be added to A without affecting the API for B (unless you want to).
    Winston
    PS: If your Class A has a constructor or constructors that take a pile of parameters, you might also want to look at the Builder pattern. However, that's not really what we're talking about here, and it should probably be implemented on A anyway.

  • Where to put methods in a abstract base class - subclasses system

    Hi,
    I’d like to ask a question on some basic design practice.
    When there are methods which are common in some subclasses so I would like to “move them up” in the base abstract class, I would also like to make sure that the ADT concept of the base class itself is not broken. So I don’t want to have methods in the base class that are not general enough to be there. How to resolve this?
    For example I create a base abstract class Vehicle. Then I create subclasses Plane and Tanker and realize that the startEnginge() method in them is the same and in order remove the duplicated code, I can put it in Vehicle. But later there may be Bicycle or Sled subclasses which don’t need startEngine().
    In a broader sense, I would like to keep the Vehicle class as similar to the real word concept of vehicles as possible. And not evey vehicle have engine of course.
    What is the solution?
    Extending the class hierarchy by injecting another abstract class between the base and the subclasses? (e.g: VehicleWithEngine)
    I suppose I can’t use Interfaces because I need to have the common implemenations as well.
    Thanks for any comments in advance,
    lemonboston
    ps: I am a beginner and don't know the terminology, so if there are programming expression for the followings for example, I would be thankful if someone could help with this too:
    - moving common methods up in the class hierarchy
    - injecting a class in the hierarchy
    - abstract base class - subclasses system

    lemonboston wrote:
    Hi,
    I’d like to ask a question on some basic design practice.
    When there are methods which are common in some subclasses so I would like to “move them up” in the base abstract class, I would also like to make sure that the ADT concept of the base class itself is not broken. So I don’t want to have methods in the base class that are not general enough to be there. How to resolve this?
    You are talking about code.
    Instead you need to talk about the design.
    The base class represents conceptually a 'type' of something. That 'type' defines behavior. That behavior is what goes in the base class nothing else (in terms of design.)
    If you have common functionality which does not fit into the definition (design) of the 'type' then you put it in another class and use (composition) that class in the sub class.
    For example I create a base abstract class Vehicle. Then I create subclasses Plane and Tanker and realize that the startEnginge() method in them is the same and in order remove the duplicated code, I can put it in Vehicle. But later there may be Bicycle or Sled subclasses which don’t need startEngine(). No that is not how it works.
    You have specific examples of some vehicles and then you need to manage those types generically. That is the first step.
    Second step is then to determine what the exact 'type' is that you want to manage. And you use the requirements of the need to create the 'type'.
    Then you look at the specific examples to determine how they will meet the needs of the type.
    Thus if I have an application that must start the engines of all the vehicles in the city then I must have a vehicle class which has startEngine.
    But if I have an application that manages vehicles as inventory (like a retail store) and then decide that because my examples both have engines that I might as well move it into the base class. In that case there is no 'need' for the application to manage starting vehicles. The fact that both have engines is irrelevant.
    So looking back at your example you have stated functionality about your specific types but you have not stated anything about why your application needs to deal with that functionality generically.
    Another way to think about it is that you do not put the shared functionality in the base because you can but rather because you must.

  • Calling another java class from a java class

    Hi Friends,
    I have a class tht works in 2 modes,depending upon which mode i am passing (gui or text) on the command line eg:
    java myclass [mode]
    I want to call this command from another java class,and i wrote this code:
    try
             Process theProcess =
                Runtime.getRuntime().exec("java myclass  "+args[0]);
          catch(IOException e)
             System.err.println("Error on exec() method");
             e.printStackTrace();
          }When i pass "gui" it works fine,but when i pass"text", the class completes and nothing shows up on the command prompt window,so can please somebody tell me how to make this work.
    Thanks

    As aniseed just pointed out, you could do something like this:
    import javax.swing.*;
    class Test extends JFrame {
         public Test(String title) {
              this.setTitle(title);
              this.pack();
              this.setSize(300, 300);
              this.setLocationRelativeTo(null);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) { new Test(argv[0]).setVisible(true); }
    public class Test2 {
         public static void main(String[] argv) {
              Test.main(argv);
    }Run it by executing this command:
    java Test2 "Title of Frame"See if that's not what you're looking for ...

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • Calling a java application from within another class

    I have written a working java application that accepts command line parameters through public static void main(String[] args) {} method.
    I'm using webMethods and I need to call myapplication from within a java class created in webMethods.
    I know I have to extend my application class within the webMethods class but I do not understand how to pass the parameters.
    What would the syntax look like?
    Thanks in advance!

    why do you want to call the second class by its main method ??
    Why not have another static method with a meaningfull name and well defined parameters ?
    main is used by the jvm as an entry point in your app. it is not really meant for two java applications to communicate with each other but main and the code is not really readable.
    Have a look at his sample
    double myBalance = Account.getBalance(myAccountId);
    here Account is a class with a static method getBalance which return the balance of the account id you passed.
    and now see this one, here Account has a main method which is implemented to call getBalance.
    String[] args = new String[1];
    args[0] = myAccountId;
    Account.main(args);
    the problem with the code above is
    main doesn't return anything so calling it does do much good. two the code is highly unreadable because no one know what does the main do... unlike the sample before this one where the function name getBalance clearly told what is the function doing without any additional comments.
    hope this helps.... let me know if you need any additional help.
    regards,
    Abhishek.

  • Using Methods not Defined in a class that you are calling them from

    For one of my assignment I have had to create a class with methods and then create another class to test the methods.
    I keep getting the error message "cannot resolve symbol"
    And the error points to the line where I am calling the class.
    I have put the classes in a package and imported them.
    Here is the method I am calling.
    public boolean validDate(int day, int month, int year)
    if(leapYear(year))
    daysInMonth = 29;
    else
    getNumberOfDaysInMonth(month);
    return true;
    This is how I am calling it from the test class
    if(validDate(day1,month1,year1))
    testnewDate.java:38 cannot resolve symbol
    symbol : method validDate(int,int,int)
    location:class newdate.testnewDate
    if(validDate(day1,month1,year1))
    ^
    If anyone is able to help I can give you my java source files if I haven't given enough information.

    You can't call another class's method directly from your class. You need to get an object of that class and should call the method using that object.
    If you have written public boolean validDate(int day, int month, int year) method in class DateValidator, then from your test class, you have to call that like this,
    DateValidator dv = new DateValidator();
    if(dv.validDate(day1,month1,year1)) {
    // Take actions
    Hope it is clear.
    Sudha

  • Calling method validator from EO to another EO

    Hi, I am usning JDEV 11.1.16.0
    I have two EOs Person and PersonJob
    there is an association created PersonEOTOPersonJob
    In my PersonJobEO I have a method validator which calls a method in my PersonJobEOImpl.java where i am doing some validation.
    Now the problem is that when I am trying to modify one attribute in my PersonEO and not modifying anything in PersonJobEO, I need the call the same method validator from PersonJObEO.
    I don't want to make my PersonJobEO row dirty just to call the method validator in PersonJobEO.
    Is there a way to call the PersonJobEo method validator whenever my PersonEo becomes dirty or a particular attribute, say person status is update
    I have tried below code which did not help me
    public void validatePersonJobEntity(){
    RowIterator relationsRows = getPersonJobEO();
    EntityImpl relEntityRow;
    while(relationsRows.hasNext()){
    relEntityRow = (EntityImpl)relationsRows.next();
    relEntityRow.validateEntity();
    }

    Hi ,
    Let me try to explain more clearly with an example
    In PersonEO I have an attribute called status, which is an LOV and accepts values "active" and "inactive"
    In PersonJObEO I have a method validator named ValidateDuplicateRowbyDate(), which checks for duplicate jobs based on start, end date for "active" persons.
    I have given the definition for ValidateDuplicateRowbyDate in my PersonJobEOImpl.java
    eg
    class PersonJobEOImpl{
    //other code
    public void ValidateDuplicateRowbyDate(Arraylist ctx){
    //Logic to check for duplicate jobs based on start and end date for active Person
    As per the above logic duplicates are allowed for inactive user.
    Now when someone updates the inactive status to active for a person without touching the PersonJob data. I need to fire same validation.
    The PersonJobEo validation is not fired as it is not dirty. I need to call the PersonJobEO validation whenever personStatus is updated
    eg.
    Scenario 1
    PersonEO
    Person_id person_name status
    1001 John active
    PersonJobEO
    JobId person_id Job_name start_date end_date
    2001 1001 Sales 5/4/2010 5/10/2011
    2002 1002 Service 5/4/2010 5/10/2011(This is invalid two rows with same start and end date is not allowed)
    Scenario 2
    PersonEO
    Person_id person_name status
    1002 SAM inactive
    PersonJobEO
    JobId person_id Job_name start_date end_date
    2003 1001 Sales 5/4/2010 5/10/2011
    2004 1002 Service 5/4/2010 5/10/2011(allowed as person status is in active)
    Scenario 3
    When status for person_id 1002(SAM) is updated to active from inactive i need to perform the validation on PersonJobEO and i should not allow the status to be updated
    here i want to trigger validation ValidateDuplicateRowbyDate in PersonJobEO

  • Calling another java class from a servlet

    I am trying to write a web based form handling system (for a college project)
    I have a servlet that responds to a user request for a form. I have another java program (HTMOut) that parses the xml file for the form and produces HTML output. When I call the HTMOut from the servlet it crashes the webserver (Tomcat). But if I call HTMOut from an ordinary java class it runs fine. If I call another test program from my servlet that works too.
    Any ideas?

    where does your HTMOut output? A file or a stream? I think it is better that HTMOut can output to a stream you can set externally.

  • How to reach a method of an object from within another class

    I am stuck in a situation with my program. The current situation is as follows:
    1- There is a class in which I draw images. This class is an extension of JPanel
    2- And there is a main class (the one that has main method) which is an extension of JFrame
    3- In the main class a create an instance(object) of StatusBar class and add it to the main class
    4- I also add to the main class an instance of image drawing class I mentioned in item 1 above.
    5- In the image drawing class i define mousemove method and as the mouse
    moves over the image, i want to display some info on the status bar
    6- How can do it?
    7- Thanks!

    It would make sense that the panel not be forced to understand its context (in this case a JFrame, but perhaps an applet or something else later on) but offer a means of tracking.
    class DrawingPanel extends JPanel {
      HashSet listeners = new HashSet();
      public void addDrawingListener(DrawingListener l) {
         listeners.add(l);
      protected void fireMouseMove(MouseEvent me) {
         Iterator i = listeners.iterator();
         while (i.hasNext()) {
            ((DrawingListener) i.next()).mouseMoved(me.getX(),me.getY());
    class Main implements DrawingListener {
      JFrame frame;
      JLabel status;
      DrawingPanel panel;
      private void init() {
         panel.addDrawingListener(this);
      public void mouseMoved(int x,int y) {
         status.setText("x : " + x + " y: " + y);
    public interface DrawingListener {
      void mouseMoved(int x,int y);
    }Of course you could always just have the Main class add a MouseMotionListener to the DrawingPanel, but if the DrawingPanel has a scale or gets embedded in a scroll pane and there is some virtual coordinate transformation (not using screen coordinates) then the Main class would have to know about how to do the transformation. This way, the DrawingPanel can encapsulate that knowledge and the Main class simply provides a means to listen to the DrawingPanel. By using a DrawingListener, you could add other methods as well (versus using only a MouseMotionListener).
    Obviously, lots of code is missing above. In general, its not a good idea to extend JFrame unless you really are changing the JFrames behavior by overrding methods, etc. Extending JPanel is okay, as you are presumably modifiying the drawing code, but you'd be better off extending JComponent.

  • Accessing a native method from within a packaged class

    I have seen some very useful information from RPaul. However, I can not quite get it to work.
    I have a class "JNIGetUserId" that is in a package "com.services.localoptions". I am trying to call a native method from a dll. it works fine at the default package level. But not in the package. I have tried adding the "_" between each level of the directory in the h and c++ files. I also found that doing a javah at the top of the package structure it includes some information in the h file. A "_0005" shows up between each level.
    This is on Windows XP. I am also using VisualAge for Java. I also am using JDK 1.3.1.
    The source files:
    package com.services.localoptions;
    * This class provides the JNI Interface to call the
    * AD User Maintainence routines.
    * These routines are stored in the JNIGetUserIdLibrary.dll.
    * The routines are:
    * <ul>
    * <li>getUser - returns a string containing the User Id
    * <eul>
    * @author: Ray Rowehl
    * @date (10/15/2003 10:30:59 AM)
    public class JNIGetUserId
         // Load the library
         static
         try
              System.out.println("loading dll");
         System.loadLibrary("JNIGetUserIdLibrary");
         System.out.println("loaded dll");
         catch (UnsatisfiedLinkError ue)
              System.out.println("Link Error");
    * native C++ method to call getUserId routine
    public native String getUser() throws Exception;
    * This method allows us to test standalone..
    * Creation date: (10/16/2003 2:08:58 PM)
    * @param args java.lang.String[]
    public static void main(String[] args)
         try
              System.out.println("Trying method 3");
              JNIGetUserId lGUD = new JNIGetUserId();
              System.out.println(lGUD.getUser());
         catch (Exception e)
              System.out.println("Got an exception " + e);
              e.printStackTrace();
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class JNIGetUserId */
    #ifndef IncludedJNIGetUserId
    #define IncludedJNIGetUserId
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: JNIGetUserId
    * Method: getUser
    * Signature: ()Ljava/lang/String;
    JNIEXPORT jstring JNICALL Java_com_localoptions_JNIGetUserId_getUser
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    // Implements method to return a string to Java
    // C++ core header
    #include <iostream.h>
    // header from Java Interface
    #include "JNIGetUserId.h"
    #include "JNIGetUserId2.h"
    // returns a string back to Java for package structure
    JNIEXPORT jstring JNICALL Java_com_services_localoptions_JNIGetUserId_getUser
    ( JNIEnv * env, jobject thisObject )
         // set up constant user id for testing return
         char* userid = "RROWEHLP";
         // return userid to caller
         return env->NewStringUTF( userid );     
    // returns a string back to Java for flat structure
    JNIEXPORT jstring JNICALL Java_JNIGetUserId_getUser
    ( JNIEnv * env1, jobject thisObject1 )
         // set up constant user id for testing return
         char* userid1 = "RROWEHL1";
         // return userid to caller
         return env1->NewStringUTF( userid1 );     
    }

    Ok. A co-worker figured it out for me. The key thing is to do "javah com.services.localoptions.JNIGetUserId". Note the use of "." instead of "\". Running on windows, I was used to doing "\". That was part of the problem. Another key is doing the javah at the top of the package structure. This was mentioned in a post over at IBM.
    We got our JNI stuff working now. thanks, ray.

  • How to call methods defined in another class ? is it possible?

    Hi all,
    I am new to using JNI, was wondering if this is possible and how I might be able to do this. I'm trying to call some set/get functions defined in a class that is not part of the class where I have my native code defined and called...
    Let me explain a bit, I have a class JobElement (singular Job) that stores all the data associated with a Job, such as job name, job id, etc.
    Another class JobsElement (plural Jobs) contains all the Jobs that are currently running.
    The code is set up something like this...
    class JobElement {
         String jobID;
         String jobName;
         public void setJobId(String newJobID) { jobID = newJobID; }
         public void setJobName(String newJobName) { jobName = newJobName; }
    class JobsElement {
         Date timeDateStamp;
         JobElement job;
    class AppRoot {
         JobsElement allJobs = null;
         JobElement _currentJob = null;
         public native getAllJobs();
    }In my native method, getAllJobs(), I essentially want to call the set functions that are defined for JobElement when filling in the information of the Job. (then finally add the JobElement to the JobsElement list)
    In summary, I basically want to know if it's possible to call the equivilent of this java code from the native code??
         _currentJob.setJobName(newJob)
    In the native code I tried to find the setJobID method but got a NoSuchMethodError. (which is what I expected)
    Thanks in advance.

    Hi,
    In your getAllJobs(), the JNI Equiv would be JNIEnv_ClassName_getAllJobs(JNIEnv** anEnv, jobject jAppRootobj)
    Since you are calling the AppRoot object's method, the jobj in the native method call will be jAppRootobj-AppRoot's instance.
    What you can do is
    Get the field id of _currentJob.
    Get the <jobject-value of currentJob> of JobElement i.e. currentJob.
    Then get the method ids of setJobID and setJobName.
    Call these non-static methods on <jobject-value of _currentJob> to set the values.
    I hope I made a try to help you. Please correct me if I am wrong.

  • How to instantiate an object from another's class?

    Hi... first post here
    I have the following problem:
    I have a first object, lets call it obj1, of class X (where X could be, for example, 'Class1' or in another moment 'Class2', etc.)
    Now, I have another object, obj2, which I wish to instantiate it with the same class as obj1. The problem is I don't always know which class does obj1 belongs, so programming with an if-else statement and the getClass().getName() method is not a solution, since I cannot program for all the possible cases.
    I know that with obj1.getClass() I get obj1's class and that with obj1.getClass().getName() I get a String with obj1's class name.
    I guess that making obj2 of class Object I can get it, but my question is:
    How do I do to create the instance of obj2 so its class in that moment is the same as the class of obj1? (And by the way, how can I use a specific constructor of obj1 for obj2?)
    I repeat that the if-else method won't do since the class for obj1 won't always be in a known set of classes.
    Thanks for any help or tip you can give me
    Javier
    from Mexico

    You would use the Class.forName() static method to get a Class object of the class you are looking for. Then you would use its newInstance() to create an instance of that class using a no-arguments constructor. If you need some other constructor (and how would you know that?) then Class has a getConstructor(...) method and a getConstructors() method that return one or more Constructor objects you could use. Follow the API documentation from there.

  • No access to method from within the same class

    Hey there.
    First I have to excuse my English for I'm german and just learning...
    Ok, my problem is as follows. I have a class called JDBC_Wrapper it includes the method sendQuery(String query). When I call this method from within another class (where 'wrapper' is my instance of JDBC_Wrapper) it works fine. For example:
    wrapper.sendQuery("SELECT * FROM myDataBase");
    But then I have written a method called getNumRows() into my JDBC_Wrapper class.
    This method should send a query through sendQuery(Strin query) but when calling getNumRows() it says: "java.sql.SQLException: [FileMaker][ODBC FileMaker Pro driver][FileMaker Pro]Unbekannter Fehler." (Unbekannter Fehler -> Unknown Exception). What could that be?
    I'm using jdk2 sdk 1.4.2 with BlueJ. My database is Filemaker Pro 6. The ODBC/JDBC connector works fine.
    BerndZack

    This is within my JDBC_Wrapper class:
    public ResultSet sendQuery(String query)
            if(connected)
                try
                    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet rs = s.executeQuery(query);
                    return rs;
                catch(Exception e)
                    System.out.println(e);
            else
                //System.out.println("There is no connection to the datasource!");
            return null;
    public int getNumRows()
            try
                ResultSet r;
                r = this.sendQuery("SELECT COUNT(*) FROM " + table_name); // At this line the error occurs
                r.next();
                return (int)r.getInt(1);
            catch(Exception e)
                System.out.println(e.getMessage());
                return -1;
    }When I call sendQuery() from within another class it works, but calling getNumRows()
    throws an exception.

  • Calling an action from a different controller class with an input form

    I have a Controller class declared as follows...
    public class Controller extends PageFlowController
    This class is not in a package. Inside this Controller class, I have a form class that is used as input for an Action method.
    public static class OrderDetailsForm extends FormData
    I also have another Controller class that exists in a subdirectory (and consequently has a package name)..
    package createOrder;
    class CreateOrderController extends PageFlowController
    From an Action within this Controller class, I want to forward to an Action in the first Controller class. I need to get access to the OrderDetailsForm class to do this, but I don't know how to declare a variable of the OrderDetailsForm class. I tried to do this...
    Controller.OrderDetailsForm myForm;
    But the compiler doesn't accept this. My question is what is the class name that I should be specifying to create an instance of OrderDetailsForm that lives in the Controller class that doesn't live inside a package?

    Do you know how to create an object of a class in some other class? The code you wrote seems you dont have basic sense of what is a object and class. Where did you create the object of your People class in your animal class? Create the object of people class within the animal class like:
    public class Animals {
        People people;
        public Televoting() {
        public void showAnimals() {
            people = new People(); // This is called the object creation by calling the constructor of the People 
                                              // class. Now you can access all the methods and variables of your people
                                              // class through the people object.
            System.out.println(people.peoples[0] + " is not an animal, but a person.") // Notice the difference.
    }I am sorry to say that you are not a good student and learner.
    Shan.

Maybe you are looking for