Simple enough, but calling one method from another class

Hi all
I know it's pretty simple, even though I do not see where I am going wrong for some reason any. Basically, I have a class that extends JPanel but when I try to call one of its methods in my main class I get an error. The code (I hope) is:

Main.Java
import java.awt.BorderLayout;
// ...
import javax.swing.UIManager;

public class Main extends JFrame implements ActionListener {

     JFrame frame;
     public static JPanel statusBar;

     public Main() {

          // ...

          // Add a status bar
          statusBar = new StatusBar();
          mainPanel.add( statusBar, BorderLayout.SOUTH );

          setContentPane( mainPanel );
          // ...
     }

     // ...

     public static void setStatusBarText( String s ) {
          statusBar.setStatusText("Test");
     }

     // ...
}
StatusBar.java
import java.awt.Color;
// ...
import javax.swing.SwingConstants;

public class StatusBar extends JPanel {

     private int barWidth;
     private static JLabel status;

     public StatusBar() {
          super();
          //barWidth = Main.getProgramWidth();
          //setPreferredSize( new Dimension(barWidth,22) );
          setLayout( new FlowLayout( FlowLayout.LEADING ) );
          setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(160,160,160) ) );

          status = new JLabel("Test", SwingConstants.LEFT);
          //status.setVerticalAlignment( SwingConstants.CENTER );
          add( status );
     }

     protected void setStatusText( String s ) {
          status.setText( s );
          revalidate();
     }
}
The "statusBar.setStatusText ("Test")"; call in the main class file does not work and I get the error:

>
cannot find symbol
symbol: setStatusText (java.lang.String) method
Location: class javax.swing.JPanel
statusBar.setStatusText ("Test");
>

Any ideas what I am doing wrong? I created an instance of the class called status bar StatusBar, can I use it to call the setStatusText() method (via statusBar.setStatusText ()) I thought everything is OK, then it does not work? Even if there is an easier way to do what I want to achieve (i.e. to update a JLabel since the 'central' main class file instead of setting the JLabel static and have all classes call him directly), I'd be glad to know where I am going wrong here nevertheless.

Thank you very much
Tristan
     public static JPanel statusBar;

     public static void setStatusBarText( String s ) {
          statusBar.setStatusText("Test");
     }

>
cannot find symbol
symbol: setStatusText (java.lang.String) method
Location: class javax.swing.JPanel
statusBar.setStatusText ("Test");
>

The type of variable statusBar is JPanel. That's all the compiler takes into account. It is not relevant that at a certain point in the program, the type of the object pointed to by this variable is a subclass of JPanel (because at another time, it might be an instance of another subclass or JPanel itself.

Tags: Java

Similar Questions

  • Call the method from another application

    Then. That is my question. Is it possible to call a method from another application, so I can get some data from this app?

    I know that I could also do this with persistent store, but I would like to do it this way.

    Thank you. I'll try with world events and TIME store.

  • How to stop one timer from another class?

    I am trying to stop a timer in the stopwatch class MainMenu class. But my code does not work, here is my code:

    in the class MainMenu I have method:

    public function pauseGame (e:MouseEvent){

         timestop = new Stopwatch();

         timestop.Stoptimer(); }

    in the Stopwatch class, I'm trying to stop my timer with:

    public function Stoptimer(){

          timer.stop();

          timer.removeEventListener(TimerEvent.TIMER, timeFun);

          return; }

    You pass a reference to the timer to the Stoptimer class.

  • Calling functions from another class

    How one accesses a function from another class?

    Let's say I have a file called .as hand. My flash file uses this as this is the main class to make it work when you test the program. Let's say I have another class named Test that looks like this:

    package

    {

    public class Test

    {

    public void Test()

    {

    trace ("why don't you work?');

    }

    }

    }

    I want call the Test function when the game takes place (in the appellant to hand), how would he enter the main run file? I imported to it, made sure that the functions were public/static, created as a variable and it still doesn't work.

    Any help would be good

    the constructor for a class is different from a 'normal' function

    If you can't do something like

    meow: Test of var = new Meow();

    To call it thus:

    test: Test of var = new Test();

    test. Meow();

  • Call one report of another

    Hello

    Reports * 10 g * is it possible to call one report of another? So I have a button on a report, and how do I call another report? (with some parameter of the calling report). I know in Developer 2000 it is possible, but in 10g (which is based on the web I've heard is not possible).

    Please give me an answer if you know.

    Thank you

    Hello

    Several documents are available in "My Oracle Support":

    Tips for using hyperlinks in Drill Down reports (Doc ID 756110.1)
    How to design dynamic Drilldown Web Hyperlink reports (Doc ID 109507.1)
    How to create Drill Down Web of relationships using hyperlinks (Doc ID 160262.1)
    ...

    Concerning

  • FRM-92101 happens when I open one form from another and then close it.

    FRM-92101 happens when I open one form from another, check something, display a message to the user and exit the screen to the previous shape.

    Version of forms: 10.1.2.0.2. Java: 1.6.0_23. Browser: IE6

    When I put forward two messages of 'EXIT_FORM', all right and the second form is closed again to the first shape just like I wanted.
    In 9.0 forms, it did not.

    It has to do with the fact that I use JRE instead of JInitiator?
    Thank you.

    Take a look by using the built-in NAME_IN forms. You will find the NAME_IN function takes a STRING as parameter. Change your code to:

    IF NAME_IN('SYSTEM.CURSOR_ITEM') IS NOT NULL THEN
       SYNCHRONIZE;
    END IF;
    

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • How could call a report from another report?

    Dear developers,

    How could call a report from another report?

    is this possible? and what is the call statement?

    Note: I use the 6i report



    Thanks in advance,


    Bil

    Hello

    It seems that you 'open' a quote before: orderby.
    You must "close" this quote after: orderby

    SRW.run_report ("report = SDCRVRF106 Cl_NO ='|"'|: CLIENT_no | "") ' || ' d1='||'''' || :D1 ||'''' ||' d2='||''''||:D 2 ||'' ' |' orderby =' | '''|| : o rderby | " ') ;

    concerning

  • calling a method from javascript bean

    Hi forum,

    I was wondering if it is possible to call a method of bean managed from javascript. Why do I need it? Because I want to implement a simple javascript and light confirm dialogue resulting (Y or N) determines if the call or not a method that could achieve a vo. To be more precise, I hava a table only reading and I want to give the user the option to select a single line and remove it without taking to another page but confirming a javascript dialog box.
    Thank you very much in advance.

    Alberto

    Yes,

    .. You should forget about it. 10.1.3 doesn't have a callback method in controlled beans. In theory, you can create a filter for the faces servlet and pass a parameter of specific application as a flag with the request, so the filter can attempt to access the bean managed and put some information below. However, on the client side you would issue such a XMLHttpRequest

    Frank

  • How to call a dll from another dll functions

    Hi, can someone please tell me some examples or instructions on how you go about calling functions from a dll from another dll including the IUR. The two DLLs were created with labwindows cvi.

    Thank you!

    Hi Sinnas,

    You mention that you use a UIR.  A DLL does not have a file UIR as part of it.

    DLL1

    Instead, when you build the DLL first, we'll call it DLL1, you create a header or the files that contain functions that you want to the client code to call.  When you build DLL1, you must export the file DLL1 function for his client to call code header.  Whatever the calling code is (a GUI or another DLL), you must include in the exported DLL1 project headers AND DLL1 .lib file generated when you generate it.

    DLL2

    DLL2 will contain in its project, the header file exported for DLL1, DLL1 .lib file - that gives it the feature in DLL1.  The code can then call any desired DLL1, but as DLL1, you should now have a header file that exports the functions of DLL2 desired HIS client code to call.  When you build DLL2, you create a .lib for THAT DLL file to include in the code of the final customer.

    GUI

    The final customer code will be a few GUI that you create to call DLL2 functions will have the UIR upper layer file.  It will include the exported DLL2 header file and the file .lib DLL2 in his project.  It can then call any function of DLL2.  It is the most clean way to have 2 dll working together.

    NOTE: You can create a GUI to test the lower level DLL1 functions before placing DLL2 in the system.  In fact, it's a good idea to do it - you want to make sure your lower level DLL1 code works properly before construction above it.

    Simple diagram

    Client code (calls to functions of the DLL2 header files) exported

    --------------------------------------------------------------------------

    DLL2 (DLL1 function calls exported in header files)

    --------------------------------------------------------------------------

    DLL1<--------------------  you="" can="" also="" create="" a="" gui="" that="" only="" calls="" dll1="" exported="" header="" files="" to="" test="" out="">

    A suggestion... I create my dll in debug mode and use them to test my code.  But I also build as static libraries.  When I do the final version of the system, I use static libraries.  They are built with the final executable and don't require additional files to install as do the dll.  When you install your system with DLLs, you must include all THE dll and they must be installed in the folder Windows/System32 of the target computer.

    I hope this helps...

    Judy

  • pushScreen does not not when calling another method of another class

    Hi all

    Earlier today, I was able to get a program that is running and I was actually pretty happy with it despite the fact that he has a lot of bugs.  However, in attempting to remove bugs and me being stupid and forget to backup my previous code that it no longer works. In any case the line of code that I used was

    UiApplication.getUiApplication () .pushScreen (ScanScreen ());

    ScanScreen is a method that I created in another class.

    Any help is greatly appreciated thanks!

    Thanks for all the help!  I just made a new button and pushed the event from there.  He works for now so thank you again for all the help everyone!

  • Populating one table from another table

    Hi Forum...

    I'm trying to populate a table from another table using CFQUERY... I have no problem with the selection of data from the original table, but need help to get the data into the new table. I use MX 6.1 and access as the database server.
    The two arrays have domain names identical to the same place, and I don't want to have to code all the column names in the selection and insert command. for example

    < cfquery name = "GetData" datasource = 'somename' >
    SELECT * FROM AssetTable1 WHERE BarCode = "123456".
    < / cfquery >

    < cfloop query = "GetData" >
    < cfquery name = "InsData" datasource = 'somename' >
    INSERT INTO AssetTable2 (xxxx...)
    VALUES ("#xxxx... #'")
    < / cfquery >
    < / cfloop >

    I hope this makes sense

    Thanks in advance

    Dave

    If your tables are identical structures and their columns are of the same type and position, and both tables are in the same database, then put everything in a single query.


    INSERT INTO AssetTable2
    SELECT *.
    OF AssetTable1
    WHERE bar code = "123456".

    If the columns were in different positions, then you should be listed explicitly in the INSERT and SELECT the parts, but you get the idea.

    INSERT INTO table1 (col1, col2)
    SELECT col1, col2
    FROM table2
    WHERE all that...

    Phil

  • Using a function from another class

    Information: Blackberry JDE 7.1.0

    BlackBerry 9930 Simulator - V 4.0.0.141

    The title of the topic seems simple, but I'm actually trying to use a X of class A function inside a function Y of class B and the GET, the value returned by X to a variable in B.

    Let me start by explaining what I currently have and then go on what I'm doing.

    I am using this class, the code for which I found online, to create a scrollable multi-line textbox.

    public class TextBoxField extends VerticalFieldManager {
    
          //define some variables to be used
          //in the class
          private int managerWidth;
          private int managerHeight;
          private EditField editField;
    
          public TextBoxField(int width, int height) {
                super(Manager.NO_VERTICAL_SCROLL);
                managerWidth = width;
                managerHeight = height;
    
                VerticalFieldManager vfm =
                    new VerticalFieldManager
                      (Manager.VERTICAL_SCROLL);
    
                  editField = new EditField(){
                    public void paint(Graphics g) {
                    getManager().invalidate();
                    super.paint(g);
                  }
                };
    
                vfm.add(editField);
                add(vfm);
              }
    
          public void paint(Graphics g) {
              super.paint(g);
              g.drawRect(0, 0, getWidth(), getHeight());
            }
    
          public void sublayout(int width, int height) {
              if (managerWidth == 0) {
                managerWidth = width;
              }
              if (managerHeight == 0) {
                managerHeight = height;
              }
              super.sublayout(managerWidth, managerHeight);
              setExtent(managerWidth,managerHeight);
            }
    
          public String getText() {
                return editField.getText();
              }
              public void setText(String text) {
                editField.setText(text);
              }
            }
    

    Then in another class that I created a "Set" function that instantiates the class textbox, to create two text boxes and a richfieldtext, add them to a HorizontalFieldManager and return the HorizontalFieldManager.

     HorizontalFieldManager Set(int set){
            HorizontalFieldManager hr1=new HorizontalFieldManager(FIELD_HCENTER);
    
            RichTextField set1 = new RichTextField("SET " + set + ":"){
                protected void layout(int width, int height)
                {
                    super.layout(75,30);//Width and height according to the button name;
                    setExtent(75,30);//width and height according to the button name;
                }
            };
            set1.setPadding(10, 5, 10, 10);
            TextBoxField set1W = new TextBoxField(40,25);
            set1W.setPadding(10, 5, 10, 0);
            TextBoxField set1R = new TextBoxField(40,25);
            set1R.setPadding(10, 5, 10, 0);
    
            hr1.add(set1);
            hr1.add(set1W);
            hr1.add(set1R);
    
            return hr1;
        }
    

    Now in my main class I call this function to add a 'Set' on the screen using:

    add(Set(1));
    

    For the creation of the 'Set' function instead of using the instance of the textbox class in the main class itself, it is because I will create several 'sets '.

    Now, as you can see, there is a public String getText() function in the TextBoxField() that returns the value of the editField. What I need to do, is to get the value in this field, once you press a button.

    I have the code for the function button, so this isn't a matter of concern. However I do not know how to retrieve the editField value when the button is pressed. I can get the value inside the Set()function, using the:

    String getval = set1W.getText();
    

    but can't reach it from the outside. I don't even know if it's possible in the first. If it is not could someone suggest a way where I could retrieve these values.

    Any help is appreciated.

    Thank you.

    Thanks for the suggestion. I found another workaround solution. Essentially implementation of an array of TextBoxFields and then pass them one by one the "Set()" method

    I tried this at the start before posting here, but due to a careless mistake when you declare the array of TextBoxFields, I couldn't make it work.

    In any case, the topic can be closed now, because the problem has been resolved. Thank you.

  • Return one Page to another class?

    Simple question here:

    I have a class that contains my 'main' nagivation pane (menu) for my application.

    For everything that needs to be addded, I have other classes that do all the work (create the page, add content, etc.). The main class, I want to do: navigationPane-> push (classB.createContent ()), and createContent returns a Page object with all the stuff on this subject.

    If I put the return as a Page type, in my header to classB as follows file:

    public:
    Game();
    Page * getPage();

    I have this error in the header file: error: 'Page' does not designate a type.

    Is it possible that I can get this Page object I created in to use in my main class classB, classA? I also tried to use a static variable for the Page, but that no longer works...

    Any help is appreciated, thanks.

    Hello

    Forward-declare the Page in the header file:

    namespace bb { namespace cascades { class Page; } }
    

    And use a display name:

    public:
    bb::cascades::Page *getPage();
    

    Depending on what you're trying to do might be preferable to create a class that inherits from Page and create content in the constructor.

    Adding "using the namespace bb::cascades' would also correct the mistake, but it's not recommended to do this in the header files.

    Also the headers should not be included in any other header files unless that inherit from these classes or their instantiation on-site. Pointers and references may be declared in advance. This will make the compilation faster.

  • Call a function of another class

    Hi!, I have a Flex project with this code inside the package 'package ':

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   backgroundColor="black"
                   creationComplete="init();callLater(showInitTime);" currentState="Inicial"
                   frameRate="24" preloader="paquete.CustomPreloader" >
    ...
    <fx:Script source="Principal.as" />
    ...
    

    File "Principal.as" has this function:

    public function loquesea():void{
         ...
    }
    

    And for the preloader, I have this class:

    package paquete
    {   
        imports ...
        
        public final class CustomPreloader extends DownloadProgressBar
        {
           
            public function CustomPreloader() 
            {
                
               //HOW I CALL FROM HERE loquesea() FUNCTION in Principal.as ????
                super(); 
            }
    
    

    Well, my question is in the code above

    Thank you!

    Hi Raulkirm,

    If you include this script in your main mxml file (remember not in another mxml component) you can call this function using the class of toplevel as shown

    FlexGlobals.topLevelApplication.loquesea ();

    Also don't forgtet to import the namespace corresponding to the...

    Thank you

    Jean Claude

  • How to call a method of one class from another class?

    I have two classes, Class1 and Class2 are saying. They are both public. They are located in the same package, and both are important to each other.

    I am trying to call a 2 function in Class1, but I do not know the syntax.

    I tried:

    Class2.godoThisThingNow ();

    But it gave me an error 1061, call to a method not defined.

    What is the correct syntax for this, and it is even possible in AS3?

    Thank you!

    You can call a public in Class1 2 method IF Class2 has access to an instance/member of Class1.

    for example, in Class2:

    var c1:Class1;

    .

    .

    C1 = new Class1();

    .

    .

    .

    C1.somepublicMethod ();

Maybe you are looking for