Calling a method from another class or accessing a component from another

Hi all
im trying to make a find/replace dialog box
my main application form has a jtextpane and when i open up the find and replace dialog box it has two textboxes (find and replace)
now i have the code to do the finding on my jtextpane but how do i call that code to do the find method?
I have tried having the code in my main application class but then how do i call that method from my dialog box class?
ive also tried having the code in my dialog box class, but then how to i tell it to work on my jtextpane which is in my main ap class?

well if someone had been nice enough to provide me
with a tutorial i wouldnt have gotten into this
muddle, no need to be rude is there!I'm not rude. And you also wouldn't have gotten into the muddle if you searched yourself. This site provides many very good tutorials about all kinds of stuff.
http://java.sun.com/docs/books/tutorial/java/javaOO/classes.htmlAmong other things, it mentions that "static" defines everything that belongs to a class, as opposed to an object.

Similar Messages

  • Calling a method of one class from another withing the same package

    hi,
    i've some problem in calling a method of one class from another class within the same package.
    for eg. if in Package mypack. i'm having 2 files, f1 and f2. i would like to call a method of f2 from f1(f1 is a servlet) . i donno exactly how to instantiate the object for f2. can anybody please help me in this regard.
    Thank u in advance.
    Regards,
    Fazli

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Calling a method in Runnable Class

    Hello I am trying to water this down but how can I call a method in my class
    If I am passed only thread t.
    MyClass mc = new MyClass();
    Thread t = new Thread(mc);
    t.start(); //works because it is a method of Thread
    t.myMethodInMyClass (); // wont work because it cant find it
    I have attempted casting to MyClass but I get CCException.
    Any help would be wonderful..
    cheers and thanks in advance.
    Scott

    Well, you could potentially have too many things in one class. You may want to try and modularize your classes more. But 'if in several situations [you] need different things to run'... well, the logic is just going to have to be there for that in some form.
    Now, if you've already performed the logic to determine what to run and you are going to have to perform the logic again (in your run() method), then there is a flaw in your design.

  • How to call main method in one class from another class

    Suppose i have a code like this
    class Demo
    public static void main(String args[])
    System.out.println("We are in First class");
    class Demo1
    public static void main(String args[])
    System.out.println("We are in second class");
    In the above program how to call main method in demo calss from Demo1 class......???????

    No, i dont know how to call other than main methods from other classes
    And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch).........

  • Calling a method within a class form another class(ViewController)

    I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class (with no NIB) just to handle the display of the table in a UITableView. So, I added a skeleton cocoa touch class file to my classes folder to handle this function when parameters change.
    So, in my app delegate, the "applicationdidFinishLaunchingWithOptions" method loads my mainViewController and NIB.  On the "viewDidLoad" method in my mainViewController, I read a URL into an SQLite database and close the database.  Herein lies the problem: I want to call my new class (TableViewHandler) and pass it the array created in the mainViewController and use the array to populate the UITable.
    How do I call a class from within another class (which has no NIB) to populate the table?  Especially if my TableViewHandler has no "viewDidLoad", "viewDidAppear", etc.
    Regads,
    -Kevin

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Call a method of a class in a constructor of another class?

    Is this good programming or should i do it in another way?
    Consider an ordering system, where I have three classes, "Booking", "Table" and "Customer.
    My idea is to create a booking assigned to a table and a customer, the fields in the booking class is a Customer and a Table and the constructor assigns values to these field.
    In my Table class i have a method that books the table "bookTable(Customer customer)" and sets the availablility to 'false'.
    So my question is, is it good programming to call the method 'bookTable()' in the table class from the constructor of the Booking class? Or should i do it in another way?
    Edited by: DJHingapus on Jul 6, 2009 5:12 AM

    This sounds the wrong way around. What is the return value of bookTable(Customer)?
    I'd expect it to return a Booking object that it creates.
    Generally, you want the constructor to do as little as possible (while still only ever returning in a valid state, of course!).
    The problem you can get when you call other methods is that you introduce the possibility of other objects getting access to your object before the constructor has finished running (i.e. before the object is completely initialized). This can lead to nasty problems that are hard to find and debug.

  • How to call a method in IMPL class from one context node

    Hi, I´ve been only study the posibility to access a method in the IMPL class  from one context node class...CN## without using events, is there a way to call it ??? I don´t have it as requierement just learning thanks !.

    Hi,
    Try this by following this you can get the custom controller instacne in the view context nodes, for your requirement you can keep the view implementation class instance instead of cuco..
    To get the custom controller instance in Context node getter/setter method:
    1. Declare Cuco instance reference variable in ctxt class..
    2. Set this cuco ref. in the Create context node method of ctxt class:
    try.
    gr_cucoadminh ?= owner->get_custom_controller( 'ICCMP_BTSHEAD/cucoadminh' ). "#EC NOTEXT
    catch cx_root.
    endtry.
    you can avoid this step as this is not needed in case of view isntance
    3. Assign this instance to the respective context node Create method using:
    BTStatusH->gr_cuco ?= gr_cucoadminh.  " here assign the view implementation ref. " me" instead of gr_cucoadminh
    Here gr_cuco is the ref. variable of custom controller in the respective context node for eg. BtstatusH
    Sample implementation of this can be found in
    ICCMP_BTSHEAD/BTSHeader ->context node BTACTIVITYH-> attr ->GR_CUCO(instance of cuco)
    Cheers,
    Sumit Mittal

  • How to call particular method in action class from Portlets StrutsContent

    I am developing a web application which uses weblogic portlets and struts. This is what I have for now in the .portlet file.
    +<netuix:strutsContent action="getStudentList" module = "people/students"+
    refreshAction = "getStudentList" reqestAttrpersistence="none"/>
    I want it to change something like this:
    +<netuix:strutsContent action="getStudentList.do?method=allGrads" module = "people/students"+
    refreshAction = "getStudentLis.do?method=allGrads" reqestAttrpersistence="none"/>
    But this is not working. So how can I achieve something like that?
    Thanks
    Edited by: user13634949 on Jun 23, 2011 1:22 PM
    Edited by: user13634949 on Jun 23, 2011 1:22 PM

    No, i dont know how to call other than main methods from other classes
    And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch).........

  • Calling a method in a class extended from thread

    I'm trying to use two threads of type ThreadTest to call the addNum method in the class below. I found that i couldnt call the addnum method with the instances I created but had to make the addnum method static and then call it with the class name ThreadTest.Is there anyway to get round this? i'm doing this exercise to try and understand synchronisation. Thanks
    import java.lang.Thread;
    import java.util.*;
    class ThreadTest extends Thread implements Runnable{
         private int x;
         private static ArrayList intnumbers = new ArrayList();
         public ThreadTest(int no)
              x=no;
         public void run()
              for (int i=0; i<x; i++)
                   try
                   System.out.println(i);
                   Thread.currentThread().sleep((long)(Math.random() * 1000));
              }catch(InterruptedException e ){e.getMessage();}
         public static void addNum(int n)
              synchronized(intnumbers){
                        intnumbers.add(new Integer(n));
    public static void main(String[] args)
         Thread  testThread = new Thread(new ThreadTest(50));
         Thread  testThreadb = new Thread(new ThreadTest(50));
         testThread.start();
         testThreadb.start();
              ThreadTest.addNum(10);
        //*** this gives an error
        //testThread.addNumber(10);
        //testThreadb.addNumber(10);
    }

    ok here goes again. ;).
    import java.lang.Thread;
    import java.util.*;
    class ThreadTest extends Thread implements Runnable{
         private int x;
         private static ArrayList intnumbers = new ArrayList();
         public ThreadTest(int no)
              x=no;
         public void run()
              for (int i=0; i<x; i++)
                   try
                   System.out.println(i);
                   Thread.currentThread().sleep((long)(Math.random() * 1000));
              }catch(InterruptedException e ){e.getMessage();}
         public static void addNum(int n)
              synchronized(intnumbers){
                        intnumbers.add(new Integer(n));
    public static void main(String[] args)
         Thread  testThread = new ThreadTest(50);
         testThread.start();
         //gives error so how can i create 2 instances of testThread and call addNum with them?
         //testThread.addNum(10);
    //works ok but I want to call addNum with 2 different threads
         ThreadTest.addNum(10);
    }

  • Call a method of a class file from an Applet

    I have an Applet nmaed CountDown.java in which I have to call a method "doSelect" of a class file named DBConnection.java. How do I do this? Both the Applet and the class file are in the same directory.

    You should put both classes in the same package and create a jar file containing the whole package.
    Make sure the DBConnection class is public or protected and that the method you're trying to call is public or protected.

  • Calling main method of a class

    Hi
    I have to call the Main method of a class in some other class becuass that class is accepting command line aurguments.
    I test it and everything is working fine.
               String[] strings = new String[3];
               strings[0] = "E:/practice.cap";
               strings[1] = "-o";
               strings[2] = "E:/practice.txt";
               Main.main(strings);I now want to know is there any drawback of doing this ?
    BR
    regards

    Muhammad Umer wrote:
    Good Explanation. But my question is not to explain the importance of main method in classes :)As far as the Java language and APIs go, there's nothing wrong with calling main just like any other method, because it is just another method. It's only special to the JVM, and to programmers who assume that it's the entry point to the program.
    As far as Java is concerned, you can call as many mains as you want. The only potential problem arises if some particular main is written in a way that relies on it being the entry point to the whole program. That is, if the author wrote it with the assumption that it would only be called by the JVM at startup time, and would not be called arbitrarily from within your code (EDIT: and if proper behavior relies on that assumption being upheld). However, this is just a particular case of a general issue that we always have to be aware of, namely, make sure you understand how a method is intended to be used, and use it in that fashion, or accept the consequences.
    EDIT: However, having said that, it's unusual to call main explicitly, so if you can, I would suggest pulling the functionality that you want out of that main into a different method, and then both your code and the main can call that method. If you cannot do that, then at the point where you call main, clearly document why you're doing it. Otherwise, whoever reads the code a few months or years from now--maybe somebody else, maybe you--will be wondering if the programmer really knew what he was doing, or if that is a mistake. That kind of second-guessing is the source of a lot of maintenance nightmares.
    Edited by: jverd on Nov 3, 2011 8:43 AM

  • How do i call the method in a class using servlet

    i am doing a project which need to use servlet to call a few methods in a class and display those method on the broswer. i tried to write the servlet myself but there are still some errors .. can anyone help:
    The servlet i wrote :
    package qm.minipas;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test extends HttpServlet {
    Database database;
    /** Initializes the servlet.
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    database = FlatfileDatabase.getInstance();
    /** Destroys the servlet.
    public void destroy() {
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("this is my class wossname"+FlatfileDatabase.getInstance()); // this is calling the toString() method in the instance of myJavaClass
    out.println("this is my method"+FlatfileDatabase.getAll());
    out.println("</body>");
    out.println("</html>");
    out.close();
    /** Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    my methods which i need to call are shown below:
    public Collection getAll() {
    return Collections.unmodifiableCollection(patientRecords);
    public Collection getInpatients() {
    Collection selection=new ArrayList();
    synchronized(patientRecords) {
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(next.isInpatient())
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByAdmissionDate(Date dateOfAdmission) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(dateOfAdmission.equals(next.getDateOfAdmission()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByAdmissionDates(Date from,Date to)
    throws IllegalArgumentException {
    if(to.before(from))
    throw new IllegalArgumentException("End date must not be before start date");
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    Date nextAD=next.getDateOfAdmission();
    if((nextAD.after(from)||nextAD.equals(from))
    &&(nextAD.before(to)||nextAD.equals(to)))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByDischargeDates(Date from,Date to)
    throws IllegalArgumentException {
    if(to.before(from))
    throw new IllegalArgumentException("End date must not be before start date");
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    Date nextAD=next.getDateOfDischarge();
    if(nextAD==null)
    continue;
    if((nextAD.after(from)||nextAD.equals(from))
    &&(nextAD.before(to)||nextAD.equals(to)))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByConsultant(String consultant) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(consultant.equalsIgnoreCase(next.getConsultant()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByDischargeDate(Date dateOfDischarge) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(dateOfDischarge.equals(next.getDateOfDischarge()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getBySurname(String surname) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(surname.equalsIgnoreCase(next.getSurname()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByWard(String ward) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(ward.equalsIgnoreCase(next.getWard()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);

    please provide a detail description of your errors.

  • Calling a Method in other Class

    I want to call a method in another class when an action is preformed can anyone suggest how I might do this??
         addSquare.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
         

    I want to call a method in another class when an
    action is preformed can anyone suggest how I might do
    this??
            addSquare.addActionListener(new ActionListener()
                 public void actionPerformed(ActionEvent e)
                 {               OtherClass oc = //getrefererncetootherclass
                   oc.methodtocall(params, to, pass);

  • How to call a method of a class where the name of method is string

    i have a method of a class in the form of a string and i have the object of the class to which it belongs .what i want to do is call this method.
    for ex:
    S1 s=new S1();
    // this is the object of my class. this class has one method called executeMe()
    String methodname="executeMe";
    //i have the name of the method with me in the form of string.
    so how can i call the class's method in this scenario from the string like what should i write in sucha way that i get s.executeMe(); it is not presumed that this will only be the method that will be called. there maybe some other method too and it has also to be called this way. so please guide.

    S1 s = new S1();
    String name = "executeMe";
    Method m = s.getClass().getDeclaredMethod(name,null); // no parameters
    m.invoke(s,null);Built from memory, maycontain flaws.

  • Networking a firewire hard drive from a Mac and access the drive from a PC

    I'm trying to network a firewire hard drive from my Mac and access that hard drive from a Windows XP PC. I can see the main internal hard drive but I cannot see the firewire hard drive. Does anybody have a solution or work around?
    Many thanks,
    Roy

    Thanks SO MUCH! Not only does it work, BUT IT IS FREE!!!!
    See, I have two firewire (external) HDs, connected to a Mac, connected to a PC, connected to a USB external HD... now I can share files from the USB HD to the firewire HDs!
    Gotta love technology!
    Matthew

Maybe you are looking for

  • Eraser and Brush Not Working Correctly (picture)

    For some reason photoshop at times will only let me erase or draw within the confines of a specific layer. It seems to happen randomly without me accidently hitting a hotkey of some sort. For instance in the image below, I was drawing and randomly I

  • How to know if an transaction is in display mode or change mode

    Hi, I have to set an information message if any transaction is in display mode and an error message if it is in change mode for a particular condition. How would I know programmatically that it is in display mode or change mode for a screen?

  • Should I get java script?

    New computer, new to Mac, new printer (Brother MFC 7860DW). D/L drivers, software, etc from Brothers' site. Firmware requires Java Script and when I run it to see if it is on this machine, it appears not! In Terminal App I type in   "java -version" a

  • Workspace Login and VPD

    I have an application that implements VPD using a database package and the policies use application logins. If I login to the workspace (as ADMIN) and use the SQL browser, then I fire the policy with the username ADMIN which is not an application use

  • [SOLVED] Trying to get a fresh install of Arch to jump right into OBox

    As the title indicates, this is my goal. I do have some problems getting there: 1. When I boot the computer, it boots into a login screen (cli) for arch. 2. I have tried adding both startx and openbox-session to the .xinitrc (as described in the begi