How can I call a variable from another class

hi
If I have two classes : one and two
In class two I have a variable called : action
In class one I want to check what is the value of action.
How can I call action?

Thank you scorbett
what you told me worked fine, but my problem is that MyClass2 is an application by itself that I don't want to be executed.
Creating myClass2 as in the following:
MyClass2 myClass2 = new MyClass2();
[/code]
executes myClass2.
Can I prevent the exectuion of MyClass2, or is there another way to call the variable (action)?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How to call a variable from another class?

    Greetings
    I�m designing a program that is called Senior.java, and I want to design it�s menus, for simplicity in reading the code, I want to write a separate java file for each menu. For example I want a file.java, edit.java etc�.
    Since I�m not a professional I�m having problems in calling the variable �bar�, that I created in senior.java,
    In Senior.java I have :
    JMenuBar bar = new JMenuBar();
    setJMenuBar( bar );
    In fileMenu.java I want to add file menu to the menu bar �bar�:
    bar.add( fileMenu );
    When I compile the fileMenu.java I got a �cannot resolve symbol � message, where symbol is the variable bar.
    Can you please help me, knowing that i'm using SDK1.4.1?

    Sun has recommendations for naming conventions. Class names should start with a capital letter. You should avoid using class names that are the same as classes provided in the SDK. Following these conventions will make it easier for people to help you. For example, you should not use file, nor should you use File. It's better to use MyFile, replacing My with something that makes sense to your application (SeniorFile?).
    Also, check the Formatting Help link when posting for a desciption on how to use the code tags for posting code.
    1. You need to establish references between your classes. One way is to have a constructor that has a JMenuBar argument.
    2. You can not add a file to a JMenuBar because a JMenuBar adds a JMenu. I don't think you want file to extend JMenu. It may be better for file to have a JMenu.
    I haven't tried to compile this code so no guarantees - just trying to show you an approach.
    public class Senior extends JFrame {
       public Senior() {
          JMenuBar bar = new JMenuBar();
          MyFile file = new MyFile(bar);
    //whatever else you need
    public class MyFile {
       public MyFile(JMenuBar mbar) {
          JMenu menu = new JMenu();
          mbar.add(menu);

  • How can I update a JTextArea from another class

    I am new to Java so forgive me if this is confusing, or if I seem to be taking an overly complex route to acheiving my goal.
    I've got a JTextArea component added to a JPanel object, which is then inserted into the JFrame. I have a JMenuBar with a JMenu "file" and a JMenuItem "connect" on this same JFrame. When clicked, the actionEvent of JMenuItem "connect" calls a class "ConnectToDb" to establish a connection with the Database. On a successful connection, I want to append the String "Connection Successful" to the JTextArea component, but since the component is a part of the JPanel object, I cannot seem to get access to the JTextArea component to update it. I tried instantiating the JPanel object from within the "ConnectToDb" class and then called a method I created to set the JTextArea. No luck. Can someone give me an idea of what I need to do that would allow me to update the text of the JTextArea component from anywhere in my program? Once it has been contained in the JPanel or JFrame, can it be updated?
    This is the class that establishes the simple Db Connection
    package cjt;
    import java.io.*;
    import java.sql.*;
    * Get a database connection
    * Creation date: (04/01/2002 4:08:39 PM)
    * @author: Yaffin
    public class ConnectToDB {
    public Connection dbConnection;
    // ConnectToDB constructor
    public ConnectToDB() {
    public Connection DbConnect() {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL = new String("jdbc:odbc:CJTSQL");
    Connection dbConnection = DriverManager.getConnection(sourceURL, "Encryptedtest", "pass");
    System.out.println("Connection Successful\n");
    //this is where I originally tried to append "Connection Successful
    //to the JTextArea Object in WelcomePane()          
    } catch (ClassNotFoundException cnfe) {
    //user code
    System.out.println("This ain't working because of a class not found exeption/n");
    } catch (SQLException sqle) {
    //user code
    System.out.println("SQL Exception caused your DB Connection to SUCK!/n");
    return dbConnection;
    This is the JPanel that contains the JTextArea "ivjStatusArea" I am trying to update from other classes. Specifically the "ConnectToDb" class above.
    package cjt;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    * Build Welcome Pane
    * Creation date: (04/01/2002 3:42:50 PM)
    * @author: yaffin
    public class WelcomePane extends JPanel {
         private JTextArea ivjtxtConnect = null;
         private JLabel ivjwelcomeLbl = null;
         private JTextArea ivjStatusArea = null;
    * WelcomePane constructor comment.
    public WelcomePane() {
         super();
         initialize();
    * Return the StatusArea property value.
    * @return javax.swing.JTextArea
    private javax.swing.JTextArea getStatusArea() {
         if (ivjStatusArea == null) {
              try {
                   ivjStatusArea = new javax.swing.JTextArea();
                   ivjStatusArea.setName("StatusArea");
                   ivjStatusArea.setLineWrap(true);
                   ivjStatusArea.setWrapStyleWord(true);
                   ivjStatusArea.setBounds(15, 153, 482, 120);
                   ivjStatusArea.setEditable(false);
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjStatusArea;
    * Initialize the class.
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("WelcomePane");
              setLayout(null);
              setSize(514, 323);
              add(getStatusArea(), getStatusArea().getName());
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    This is the main class where evrything is brought together. Notice the BuildMenu() method where the JMenuItem "connect" is located. Also notice the PopulateTabbedPane() method where WelcomePane() is first instantiated.
    * The main application window
    * Creation date: (04/01/2002 1:31:20 PM)
    * @author: Yaffin
    public class CjtApp extends JFrame {
    private JTabbedPane tabbedPane;
    private ConnectToDB cdb;
    private Connection dbconn;
    public CjtApp() {
    super("CJT Allocation Application");
    // Closes from title bar
    //and from menu
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    tabbedPane = new JTabbedPane(SwingConstants.TOP);
    tabbedPane.setForeground(Color.white);
    //add menubar to frame
    buildMenu();
    //populate and add the tabbed pane
    populateTabbedPane(dbconn);
    //tabbedPane.setEnabledAt(1, false);
    //tabbedPane.setEnabledAt(2, false);
    getContentPane().add(tabbedPane);
    pack();
    * Build menu bar and menus
    * Creation date: (04/01/2002 2:42:54 PM)
    private void buildMenu() {
    // Instantiates JMenuBar, JMenu,
    // and JMenuItem.
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem item1 = new JMenuItem("Connect");
    JMenuItem item2 = new JMenuItem("Exit");
    //Opens database connection screen
    item1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    //call the ConnectToDb class for a database connection
    ConnectToDB cdb = new ConnectToDB();
    dbconn = cdb.DbConnect();
    }); // Ends buildMenu method
    //Closes the application from the Exit
    //menu item.
    item2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    }); // Ends buildMenu method
    //Adds the item to the menu object
    menu.add(item1);
    menu.add(item2);
    //Adds the menu object with item
    //onto the menu bar     
    menubar.add(menu);
    //Sets the menu bar in the frame
    setJMenuBar(menubar);
    } //closes buildMenu
    public static void main(String[] args) {
    CjtApp mainWindow = new CjtApp();
    mainWindow.setSize(640, 480);
    mainWindow.setBackground(Color.white);
    mainWindow.setVisible(true);
    mainWindow.setLocation(25, 25);
    * Add tabs to the tabbedPane.
    * Creation date: (04/01/2002 2:52:19 PM)
    private void populateTabbedPane(Connection dbconn) {
         Connection dbc = dbconn;
         tabbedPane.addTab(
         "Welcome",
    null,
    new WelcomePane(),
    "Welcome to CJT Allocation Application");
         tabbedPane.addTab(
         "Processing",
    null,
    new ProcessPane(dbc),
    "Click here to process an allocation");
         tabbedPane.addTab(
         "Reporting",
    null,
    new ReportPane(),
    "Click here for reports");
    //End
    Thanks for any assistance you can provide.
    Yaffin

    Thanks gmaurice1. I appreciate the response. I believe I understand your explanation. I am clear that the calling code needs access to the WelcomPane() object. I am assuming that the constructor for the calling class must have the JPanel WelcomePane() instance passed to it as an argument. This way I can refer directly to this specific instance of the object. Is this correct?
    Also, where would you create the set method? I tried to create a set method as part of the WelcomePane() class, and then call it from the calling class, but it didn't seem to work. Lastly, a globally accessible object? Can you explain this concept briefly? Thanks again for your help.
    yaffin

  • How can i call one report from another report (Drill Down Approach)

    Hi Friends,
    I've two reports in completely different layout format.
    One is in Crosstab & another is in Tabular.
    Now i want to call my Tabular report(report 1) from my Crosstab (report 2) without using BO's default drill down feature. Or, you can show using BO's feature if it supports my requirement.
    How to do that?
    Is it at all possible?
    Please share your thoughts. Thanks in advance for your time.
    Regards.
    Satyaki De.

    hi
    you can use openDocument for this.
    [http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_url_reporting_opendocument_en.pdf]
    I would suggest to use variables that build the HTML code for the hyperlinks dynamically, and display them in your crosstab. Set the display option for the related cells (ie. the cells where your variables are displayed in) so that the cell's contents as interpreted as HTML code.
    Regards,
    Stratos

  • How can I call a variable from VBA in Diadem report?

    Hello,
    I have a script in Diadem, script that I can control from a VBA application ( from Excell), and I want to send from Excell some details to the report.
    I want in the report, the  Local Test Order field to by the LocalTO from the VBA (Excell), the DVM Test Order fiel to be the DVMTO from Excell, and ..... al the fields from the excell to be in the report.
    And in the Diadem script the filename of the export .pdf file to be the filename from the Excell.
    Attached I put the script from Diadem and the VBA application.
    Thank you for your time.
    Attachments:
    Diadem.zip ‏28 KB

    Hello Marse!
    Sorry that I was not clear enough and add the hwo-to via OLE
    For way 1. you have to add this lines to your Excel VBA code:
    loadscript = IDIACommand.TextVarSet("T1","Value of T1")
    For way 2. it is:
    loadscript = IDIACommand.CmdExecuteSync("GlobalDim('MyGlobalVar'")
    loadscript = IDIACommand.VariantVarSet("MyGlobalVar","Value of MyGlobalVar")
    Inserted before your line
    loadscript = IDIACommand.CmdExecuteSync("scriptstart('C:\BForce\LIBR\BForce2.VBS')")
    Hope it is clear now! Otherwise feel free to ask
    Matthias
    Message Edited by Twigeater on 10-10-2008 09:43 AM
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • Help on Calling a method from another class

    how can i call a method from another class.
    Class A has 3 methods
    i just want to call only one of these 3 methods into my another class.
    How can I do that.

    When i am trying this
    A a=new A;
    Its calling all the methods from class A. I just want
    to call a specfic method.How can it be done?When i am trying this
    A a=new A();
    Its calling all the methods from class A. I just want to call a specfic method.How can it be done?

  • Calling repaint method from another class

    My question in a very simple form :
    how do I call repaint mathod from another class.
    e.g: Let's say class "A.java" is a JFrame .
    Class "B.java" is a JPanel which is added to the JFrame above.
    Class "C.java" is a JDialog containing some JButtons.
    How do I call the repaint method from the class "C.java".
    Thank you in advance!!

    My question in a very simple form :
    how do I call repaint mathod from another class.
    e.g: Let's say class "A.java" is a JFrame .
    Class "B.java" is a JPanel which is added to the JFrame above.
    Class "C.java" is a JDialog containing some JButtons.
    How do I call the repaint method from the class "C.java".
    Thank you in advance!!

  • How can I call a function from a procedure

    I have a function named: f_calc_value which return the variable v_result. This function is part of a package.
    How can I call this function from a new procedure I am creating?
    Thanks

    or refer this theread....calling function from procedure

  • If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?

    If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?  I imported music from a CD into my compter at work and when I got home and went to my iTunes account none of the songs were in my library.  I also noticed that on my Work computer there were a couple songs that I had to click on the little 'cloud' icon before I could listen to them (these were not songs I imported they were songs that were already in my library).  Not sure if this makes semse...help.

    jamie171 wrote:
    My question is since I have imported them into my iTunes library from one computer why can't I access them from my iTunes library from another computer that I have authorized to access whats in my library?  Is there no way to import songs only once into the library and then access them from all my authorized computers?
    Only if you have iTunes Match or of the computers are on the same local network.

  • How can I edit my website from another computer? and how can I create a new website next to the one, I have already? Can anyone help, please?

    How can I edit my website from another computer? and how can I create a new website next to the one, I already have? Can anyone help, please?

    Move the domain.sites file from one computer to the other.
    The file is located under User/Library/Application Support/iWeb/domain.sites.  Move this file to the same location on the other computer and double click and iWeb will open it.  Remember, it is your User Library that you want and not your System Library, as you will not find iWeb there.
    Just create a new site on the same domain file and it will appear below the other site.  If you want them side by side then duplicate your domain file and have one site per a domain file and they can then be side by side.

  • How can I call a RFC from dynpage ?

    Hi!
    I would like to know how can I call a RFC from a Portal aplication, dynpage or jspdynpage. there include some libraries ?
    any idea?
    thanks

    for deploying SAP Jra :
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ad09cd07-0a01-0010-93a9-933e247d3ba4#search=%22how%20to%20use%20jca%20sapjra%20site%3Asap.com%22
    For lookup of SAP Jra use:
    com.sapportals.connector.connection.IConnectionFactory connectionFactory =(IConnectionFactory) initctx.lookup( "deployedAdapters/SAPFactory/shareable/SAPFactory");
    Using SAP Jra
    http://help.sap.com/saphelp_nw04s/helpdata/en/47/13044258bdd417e10000000a1550b0/content.htm
    The important jars required are:
    connector.jar
    Genericconnector.jar
    prtjndisupport.jar
    Thanks

  • How can i call a zreport from my bsp page.

    Hi friends,
    How can i call a zreport from my bsp page.
    Moosa

    Hi Friend,
    These are the codings  to be wirtten in BSP for transferring values to the REPORT
    DATA:wf_date TYPE ztable-ID.
          data:seltab type standard table of rsparams,
           wa_seltab like line of seltab,
         event TYPE REF TO if_htmlb_data.
    DATA:p_value TYPE REF TO CL_HTMLB_INPUTFIELD.
    event = cl_htmlb_manager=>get_event( runtime->server->request ).
    p_requ ?= CL_HTMLB_MANAGER=>GET_DATA(
                                            request  = runtime->server->request
                                            name     = 'inputField'
                                            id       = 'i1'
    if p_requ is not initial.
      wf_date = p_requ->value.
    endif.
    clear wa_seltab.
    if wf_date is not initial.
      wa_seltab-selname = 'P_REQU'.
      wa_seltab-kind = 'P'.
      wa_seltab-option = 'EQ'.
      wa_seltab-low = wf_date.
      append wa_seltab to seltab.
    endif.
    submit *ZSAMPLEAP1* with selection-table seltab AND RETURN  .(ZSAMPLEAP1 refers to the report name and AND RETURN for coming back to the BSP page after the completion of its operation in Report )
    IMPORT int_name TO int_name FROM MEMORY ID '*zid*'.(For importing the obtained value from Report)
    In Report
    REPORT  ZSAMPLEAP1.
    SELECT-OPTIONS: p_requ FOR ztable-id  NO INTERVALS.
    SELECT SINGLE name from ztable into int_name WHERE id = p_requ-low.
    WRITE:int_name.
        EXPORT int_name TO MEMORY  ID 'zsharmila'.
    With Regards,
    SHARMILA BRINDHA.M

  • Calling a method from another class... that requires variables?

    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
         cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
    Any ideas! :D

    f1d wrote:
    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
    cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
    but I'm not sure how!
    setDate(16, 6, 2008);
    I have tried, but then I get errors such as ')' expected?
    Any ideas! :Dyou need to post your code if you're getting specific errors like that.
    but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
    i.e. syntax error

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

Maybe you are looking for

  • Executing Native SQL query for oracle

    Hi, I want to run following native sql query but it is giving me error ora:933, DATA: BEGIN OF WA,       TSP_NAME(255) TYPE C,       PER_USAGE(10) TYPE C,       END OF WA. EXEC SQL PERFORMING loop_output. select t.tablespace_name,'(' || TO_CHAR(ROUND

  • Menu bar no longer appears in full screen mode

    For some reason today my menu bar no longer shows up when I move the mouse to the top of the screen in any application.  I have tried restarting several times, opening and closing applications, taking apps in and out of full screen, ran disk utility.

  • Problem with table maintenance generator

    Hye, When i do create entries in table contents, the column name is shown as (+).... where the problem is ?? how to get resolved....tried recreating the TMG but not use. Thanx & Regards, Manisha Suvarna.

  • What is the solution to the 'error 207"? I need help please.

    For over a month now my computer has been unable to get past the 8% mark on the Progress Bar during the Adobe Creative Cloud update! Error Message often stating Server unavailability! And "Error Code 207". Can someone please help  me get out of the t

  • Flash CS5 will not import mp3 files

    With the latest Flash program and the latest Quicktime version, I still can not import mp3 files to my Flash. No reason is given, it only tells me it can't be done. elliejo