Passing Arguments in a Multiple JFrame project

I am trying to pass Arguments from MainApp.java to SubApp.java.
Is there someone that have an example or fix the sample program included?
tks a lot
sage49
I based my program on the following 2 programs that I got from this forum!!
The following is the MainApp.java
import javax.swing.*;
import java.awt.event.*;
class MainApp extends JFrame {
    MainApp() {
        super( "Main Application" );
        JButton button = new JButton( "Show Sub Application" );
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
//  need to pass a string to SubApp in the following line
                JFrame app = new SubApp();
                dispose(); 
        getContentPane().add( button );
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        pack();
        show();
    public static void main( String[] args ) {
        MainApp app = new MainApp();
}The following is the SubApp.java
import javax.swing.*;
import java.awt.event.*;
class SubApp extends JFrame {
// need to accept a String as Arguments
    SubApp() {
        super( "Another Application" );
        JButton button = new JButton( "Show Main Application" );
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                JFrame app = new MainApp();
                dispose();
        getContentPane().add( button );
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        pack();
        show();
    public static void main( String[] args ) {
        SubApp app = new SubApp();
}

Hi,
I have done what you suggested, Now I get an error on the subApp on the main.
see What I tried in the code.
MainApp.java
import javax.swing.*;
import java.awt.event.*;
class MainApp extends JFrame {
    MainApp() {
        super( "Main Application" );
        final String a ="this is the string";
        JButton button = new JButton( "Show Sub Application" );
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                JFrame app = new SubApp(a);
                dispose(); 
        getContentPane().add( button );
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        pack();
        show();
    public static void main( String[] args ) {
        MainApp app = new MainApp();
}The SubApp.java
import javax.swing.*;
import java.awt.event.*;
class SubApp extends JFrame {
        private String mystring;
        SubApp(String mystring) {   
        super( "Another Application" );
        this.mystring = mystring;
        JButton button = new JButton( "Show Main Application" );
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                JFrame app = new MainApp();
                dispose(); 
        getContentPane().add( button );
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        pack();
        show();
    public static void main( String[] args ) {
       // tried    =    SubApp app = new SubApp(mystring);
       // tried    =    SubApp app = new SubApp(a);
       // tried    =    SubApp app = new SubApp(String a);  
       // tried    =    SubApp app = new SubApp(String);                 
        SubApp app = new SubApp();                // this is the line I get the error
}I get the following error:
Cannot find Symbol
symbol  : constructor SubApp()
location: class SubApp
        SubApp app = new SubApp();Tks a lot
sage49

Similar Messages

  • How to pass arguments into a Captivate project

    Hello,
       We use dotNetNuke (DNN) as our Content Management System. We are using tokens in DNN to personalize the screens. We have access to the uses first name and email. I would like to pass this information into a Captivate project. I have seen references in my research to using Javascript to invoke the Captivate project, but I have not found any samples of the source code, nor examples of how to use the passed values in the Captivate presentation.  Can someone validate that this functionality exists for Captivate 8 and perhaps point me to a few examples?
    Thanks,
    Peter

    Sorry. I think I was a bit too vague in my answer.
    And I don't know about how you are getting your token value, but that part is up to you.
    Just make sure to put it in place of where I wrote "whateveryourtokenvalueiscalled".
    1.
    create a variable in cp to hold your value. (e.g. holdName)
    2.
    Add this inside the <head></head> tags of your page (after you export it):
    <script>
         function = getMyValues () {
              if(window.cpAPIInterface)
                   //assign your token value to the cp variable you created in the project
                   window.cpAPIInterface.setVariableValue("holdName",whateveryourtokenvalueiscalled);
    </script>
    3.
    Back in your cp project, call to the function at some point.
    For example, on page 2, add to the page's action
    On Enter:
         Execute Javascript
    Then in the script window, type this to start up the function:
    getMyValues();
    I hope that makes sense.  I'm not really great at explaining scripting unfortunately.

  • Trying to pass arguments into a method call and failing

    Hi everyone, I'm fairly new to programming, and newer to Java. I'm currently working on a project that pulls fields from a database based on a name, and I'm having some trouble getting the connection string set up.
    Statically defined, the database connects and the program logic that follows works just fine. The problem is that to future-proof this application, I need to pass the database URL, port, db instance, username, and password into the program as arguments from the batch file that will then be scheduled to run the program on a job-by-job basis.
    Product Version: NetBeans IDE 6.1 (Build 200805300101)
    Java: 1.6.0_06; Java HotSpot(TM) Client VM 10.0-b22
    System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
    Userdir: C:\Documents and Settings\xxxxxxxxxxx.SPROPANE\.netbeans\6.1
    Here's my current working source (with the network addresses obfuscated):
    package processsqrjob;
    import java.io.*;
    import java.sql.*;
    import java.util.Date;
    public class Main {
         * @param args jobname, jobparameters, HYPusername, HYPpassword, HYPservername, HYPport, oracleDBURL, oracleport (default 1512), SID (dbb?), oracleusername, oraclepass
         * @throws exeption
        // jobname [0], jobparams[1], hypusername [2], hyppassword [3], hypservername [4], hypport[5], oracledburl[6], oracleport[7], sid[8], oracleusername[9], oraclepass[10]
        public static void main(String[] args) throws SQLException
            DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@oracleserver.local.intranet.com:1521:dbname", "username", "pass");
            Statement stmt = con.createStatement();
            Date date = new Date(); //get the system date for output to both the error log and the DB's lastrun field
            System.out.println(date); //print the date out to the console
            System.out.println(args[0]); //print the job name to the console
            String sourcefolder=""; //we're going to load the job source folder into this variable based on the job's name
            String destfolder="";//same with this variable, except it's going to get the destination folder
            try {
                ResultSet rs = stmt.executeQuery("SELECT * FROM myschema.jobs WHERE NAME =\'"+args[0]+"\'");
                while ( rs.next() ) {
                    sourcefolder = rs.getString("sourcefolder");
                    destfolder = rs.getString("destfolder");
                stmt.executeQuery("UPDATE myschema.jobs SET lastrun ='"+date+"' WHERE name ='"+args[0]+"'");//put this after hyp code
    //            System.out.println(sourcefolder);
    //            System.out.println(destfolder);
    //            System.out.println(description);
                stmt.close(); //close up the socket to prevent leaks
            }catch(SQLException ex){
                System.err.println("SQLException: " + ex.getMessage());
                logError(args[0], ex.getMessage());
    }That works, and it connects to the database and everything. But when I pass the variables in from the project properties run settings, I get the following exception:
    Exception in thread "main" java.sql.SQLException: invalid arguments in call
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:235)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:440)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:207)
            at processsqrjob.Main.main(Main.java:42)
    Java Result: 1That is with Connection con = DriverManager.getConnection("jdbc:oracle:thin:@oracleserver.local.intranet.com:1521:dbname", "username", "pass"); changed to Connection con = DriverManager.getConnection("jdbc:oracle:thin:@"+args[6]+":"+args[7]+":"+args[8]+"\", \""+args[9]+"\", \""+args[10]+"\"");{code}, with args 6 7 8 and 9 set to url, port, dbinstance, username, and password respectively.
    Perhaps it's the way I'm escaping the quotation marks, but I put that same line inside a System.out.println() and it output it exactly as I had typed it in statically before, so I don't know what it could be.
    I would really appreciate any advice. Thanks in advance for your time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I think you're mixing up SQL and Java. The Java method expects the user name and password as separate parameters, not encoded in one String. So you shouldn't be concatenating args[9] and args[10] at all, they should remain as separate parameters.
    The call should be:DriverManager.getConnection("jdbc:oracle:thin:@" + args[6] + ":"+ args[7] + ":" + args[8], args[9], args[10]);
                                                     parameter 1                                  2         3

  • Passing arguments to VBScript Program Object - Without WScript.Arguments?

    I am trying to create a program object with a VBScript that will change the name of a PDF created by a scheduled report. I need to be able to tack on the string "OH_2010_Qtr_1" (or whatever state - OH is used as an example) before the file extension - the VBScript creates that string based on the date the report is run. I want to be able to pass parameters to this script but when I try to do so I get the error "Variable is undefined 'WScript'" when trying to run the program object. I tried creating a batch file that would pass in the parameters and I get a generic error.
    How can I pass arguments to my VBScript? The arguments are necessary because this is for multiple instances of the same report, run for different states.

    For VBScript Program Objects, some injected objects:
    For Each arg in Script.Args
        ' Do something interesting with String arg here
        Script.Writeln(arg) ' Output to stdout
    Next
    and
    ' Get InfoStore
    Set infoStore = Session.Service("", "InfoStore")
    Sincerely,
    Ted Ueda

  • Passing arguments/data for a tab click

    Hi,
    Is there a way to modify state, or pass arguments (set item values) when a tab is clicked?
    The intent is to make specific data values (e.g.. items on the source page) available to the tab target page - and only the tab target page since there are multiple tabs available.
    Thanks for all and any help !!
    sinclair

    You cannot specify a URL (javascript: or any other) for a tab target, it has to be a page in the application.
    Don't think of session state as a bunch of global variables that you have to avoid, this is not a programming language. Session state is managed automatically by the HTML DB engine, once an item is saved into session state, its value is available for use by any other application component.
    Restating my earlier response...
    Values in session state can be referenced from any other page in the application. Why do you need to set values only when the tab is clicked?
    Another idea is to create OnLoad computations on your tab's target page that set whatever values you need.

  • Passing arguments in Visitor Pattern

    Does anybody have a nice solution to passing arguments in Visitor pattern?
    The Visitor pattern is used to process an object structure (such as an abstract syntax tree) in many different ways without cluttering definitions of the objects with methods needed for all different kinds of processing. Instead, each object has only one method, "void accept(Visitor v)". The method calls back a method in the Visitor that is appropriate for the object. Different kinds of processing use different Visitors, each with its own set of object-processing methods.
    My problem is that I need to pass arguments or receive results from the object-processing methods, different for different kinds of processing.
    One solution is to have many "accept" methods with different signatures. This beats the idea that we do not need to modify definitions of the objects if we want to introduce new kind of processing.
    Another is to provide "accept" with an Object result and a sufficient number of Object arguments, to be used as necessary by different Visitors. It results in clumsy and unreadable code. Detestable.
    Alternatively, one could provide fields in the objects to pass the information when needed. This frees the invocations of "accept" from dummy arguments/results, but does not seem nice.
    One can also forget all about Visitor pattern, and let the processing method test the object class using "instanceof" and call the right method. But this is a pure blasphemy against everything called OO.
    Is there any better way that I am too blind to see?

    Sounds to me like you've got a case of combining different concerns into the same design. I think you're looking at multiple problems, all of which require you to process an object structure.
    I'd make a general framework for processing my structure, and then use a specific interface for each problem. I would avoid re-using the Visitor pattern for multiple concerns as it leads to exactly the problems you're facing.
    If you're dead-set on using the Visitor; how about having a mediator or adapter between the visited class and the Visitor that deals with the specifics of each invocation?
    Personally, I think the Visitor pattern violates basic encapsulation and polymorphism - but that's just my opinion. I try to avoid using it unless I'm stuck with NO other solution.
    Good luck.

  • Warning: passing argument 2 of 'setValue:forKey:' from distinct Objective-C

    I want to keep my projects warning free. In the following line
    [tempValues setValue:@"Some Text" forKey:[NSNumber numberWithInt:0]];
    the compiler complains with an
    "warning: passing argument 2 of 'setValue:forKey:' from distinct Objective-C type" warning.
    tempValues is an NSMutableDictionary.
    Any idea how to resolve this warning?

    Essentially, the typical rationale behind this particular warning is: The compiler must not let you write code that seeks to modify a non-modifiable object without giving some warning.
    Are you in effect trying to modify a non-modifiable object?
    Remember...(and I quote because I'm too lazy otherwise) "When you have a variable of type NSMutableArray*, then anyone would think that the array it points to can be modified. So if this variable contains a pointer to an actual non-mutable array, that would be a recipe for disaster, because any attempt to actually modify the array would fail in some way. For that reason, Objective-C must not just allow an assignment assigning an NSArray* to an NSMutableArray* variable.
    The other way round is harmless: Anyone looking at a variable of type NSArray* would think the array cannot be modified and therefore won't try to modify it. If the actual object is an NSMutableArray, no harm is done."

  • Hi, i am facing problem as to how to pass arguments received by my swf file to an .exe that i have c

    hi, i am facing problem as to how to pass arguments received by my swf file to an .exe that i have created from a C++ project...do i need to tweak the code in the C++ project in some way that it accepts the input from the .swf file?

    Hi there and welcome to our community
    What you need to do is click the link below, then choose the forum most appropriate to the product you are using. In this forum we discuss the operation of the forums themselves.
    http://forums.adobe.com/index.jspa
    Best of luck to you in solving your issue! Rick

  • Multiple libraries, projects and reorganizing for the new year

    I have used Aperture since 1.0 and really like it but the growing pains are still present - over time of use, I've ended up with multiple libraries [2 main ones and 2-3 little ones that probably can be safely archived]. I want to start fresh in the new year and have a new Library that is my main one, my only one in fact == is it possible/feasible/desireable to export projects from Library A and B and then import the ones i want into my 2007 Library the way my new organizing system will be? I mainly have images according to geography and people [e.g. people in locations versus family and friends]. Can I consolidate all my Libraries into one new one for use in the future ?? Will exporting each project and then importing into my new master Library work??

    I've been thinking just a little about what features I would like the next rev of aperture to have. Though I haven't thought through the specifics, easier and more efficient use and management of multiple libraries, projects etc would be nice. Whole aperture projects referenced from multiple libraries or some such? (I said I hadn't thought it through!)
    It's over a year since aperture came out, macworld is coming up, and I suspect that 2.0 will be released eventually some time in the future, perhaps with changes (maybe even improvements!) in library and project workflow.
    So while I too am considering how to organize my own aperture materials I am currently holding off for bit just in case there might maybe possibly be (Conjecture Warning!!!) something new announced soon....
    MBP17 2.16 ghz 2gb 120gb   Mac OS X (10.4.8)  
    MBP17 2.16 ghz 2gb 120gb   Mac OS X (10.4.8)  

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • How to pass argument to the Java Plugin JVM w/o using the Control Panel?

    I want to deploy an applet to be loaded by the Java Plug In
    and fix some settings of its Java Virtual Machine.
    The JPI Control Panel offers two ways to pass arguments to the JVM,
    none satisfactory.
    1. while interactive via the Control Panel Window.
    This cannot be a solution for a deployed applet.
    or
    2. by editing the system generated file that stores
    the settings of the Plugin Control Panel, using a property
    named javaplugin.jre.params.
    The problem with this method is that if forces to access
    and edit this property file which is stored at various locations
    depending the client platform. Then, it may collide with other
    settings for other applets.
    Is there a way to pass the arguments to the JVM
    from within the html file?
    Has anyone found a solution to this question?
    JPS

    I am interested in this issue as well.
    Did anyone find a reliable way to specify the runtime parameters that should be used by the Java Plug-in in order to execute a given Java applet?
    I believe a good place to specify these runtime parameters would be the applet's JAR manifest: only digitally signed applets should be able to set the desired runtime parameters...
    Any comments / suggestion would be greatly appreciated.
    Regards,
    Marco.

  • How to pass argument in manifest file

    Hi,
    I want to pass argument to main class in jar. Is there any option in manifest file.

    Hmm..
    Seems that my sentence above isn't so correct.
    It possible to add custom attribute: value pairs into manifest file and
    read it later from Java class.
    Here is code sample:
    public class ManifestTest {
        public static void main(String[] args) {
            try {
                java.util.jar.JarFile jar = new java.util.jar.JarFile(System.getProperty("java.class.path"));
                for (java.util.Iterator it = jar.getManifest().getMainAttributes().keySet().iterator();it.hasNext();) {
                    Object curKey = it.next();
                    System.out.println("key: " + curKey + ", value: " + jar.getManifest().getMainAttributes().get(curKey));
            } catch (Throwable t) {
                System.out.println("exception occured: " + t);
    }

  • How can I pass arguments to a TestStand sequence with LabWindows 6 ?

    Hi
    I have created sequences in a TestStand file.
    I want to program a sequence with Labwindows 6 which would call all these existing sequences (containing parameters).
    I don't have any problems to create the steps "SequenceCall" but i don't know how to pass arguments to the sequences with the TS API.
    I have used the look-up strings "TS.SData.SFPath", "TS.SData.SeqName", "TS.SData.ThreadOpt" to program the sequence file / sequence and the multithread option. But now how to program the arguments passing ? I think there is something with the lookup string "ST.SData.ActualArgs"...
    Thank u very much for any help

    I'm not sure if you want to pass values from TestStand to LabWindows or if you want to pass values in TestStand from a sequence call step to a called sequence.
    To get TestStand variables from LabWIndows, use the following function:
    tsErrChk (TS_PropertyGetValNumber(testData->seqContextCVI, &errorInfo, "Locals.StartPoint", 0, &dStartPt));
    iStartPt = (int)dStartPt;
    The TS_PropertyGetValNumber gets the TestStand variable Locals.StartPoint and puts it into the LabWindows variable called dStartPoint. Numbers to and from Test Stand are always a double type. The next line converts it to an integer.
    To put a LabWindows value to TestStand, use TS_PropertyPutValNumber.
    To pass values from a sequence call step to a called sequence, create variables in the Parameters t
    ab on your main sequence. Create same variables on the Parameters tab of the called sequence. In main, specify module to be called in calling step. There is a paramters section on the Edit Sequence Call dialog box which appears. Check the Use Prototype of the Selected Sequence box. You can then list all the parameter variables in the parameters section.
    Hope this is what you want.
    - tbob
    Inventor of the WORM Global

  • Multiple JFrames

    Hi. I have a situation where I need to display multiple JFrames. I have an application with a control panel that has the ability to launch another application (via a JButton). The only problem is, the only handle I have to that other application is another JButton, so I end up with something that looks like:
    JButton launchButton = new JButton();
    launchButton.setAction(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //SomeOtherApp extends JFrame
            SomeOtherApp app = new SomeOtherApp();
            app.setVisible(true); 
    });This works, but I run into all sorts of repainting problems. Since SomeOtherApp is so large, it seems to be hogging the Event-Dispatching Thread, and the app never repaints my control panel JFrame correctly. Any thoughts on how to improve this performance?
    Thanks,
    Jeff

    Only one frame ever has focus at a time and therefore only one frame ever responds to events at a time. So neither frame should be affecting the other.

  • OOD With multiple jFrames

    Hello All,
    I am writting an application which contains a nubmer of GUI classes which operate on the same data class. For example I have classes A, B, and C which extend jFrame and contain an ActionEvent which creates the next appropriate user interface class. In other words I have class A which will create object b, and class B which will create object c. Now my problem is I have a data class, Data, which after instatiate in A, will need to be accessed in B and C. Do I the data object from class to class through a constructor? Do I need to create a file and read it back when I need to manipulate the attributes or the Data class? Do I create a Data class with all the GUI classes as inner classes? What would be the best design??
    Thanks,
    Mike

    I have more than one instance of Data, therefore a
    Singelton Pattern is out. My problem with passing a
    reference is the jFrame class which instaciates the
    next jFrame needs to contain a reference to the Data
    Class. In other words if I have user interface
    classes D and E and if D does not need access to the
    Data attributes, it still need to contain a reference
    to the Data class if the next jFrame, E will need
    access to the attributes (if it the reference is
    passed via the constructor).
    I'm confused. Before you said that all of the classes need the Data object, but not are you saying that one of them doesn't? I think if you want decent advice you're going to have to give us more information about what you're doing. We aren't going to be able to help if we only get an incredibly vague, and somewhat confusing description of what's going on.

Maybe you are looking for

  • How do you import music from your ipod to your itunes???

    I just got a new computer and I can't figure out how to get my music from my ipod to my new itunes, does anyone know how?

  • Use subflow or redirect step when calling another script

    I have a main AA script and it calls another script when caller press option 6.  When a caller presss 6 it is only transferring the call to the sub script.  it does not return any values to the main script. In this situation, is it better to use subf

  • Releasing Licenses Crystal Reports 2008

    We are considering to migrate our infrastructure  to Crystal Reports Server 2008. We have setup a test server with 5 CAL, and in order to make our reports work here,  we had to modify our code slightly to use a different viewer (Interactive viewer is

  • How can I install the Amazon Universal Wish List ?

    I want to install the Amazon wish list button . This makes it possible to add items from any site to ones Amazon wish list. However , in order to do this one must " drag " the button on the wish list site to the bookmark icon. My knowledge being limi

  • Report RFIDYYWT - Generic Withholding Tax Reporting

    In the above mentioned report, is not bringing some Vendor Credit Memo, with items posted in the Withholding account. I'd like to know if someone has some clue about why a document doesn't appear at this report. Thank you Barbara Santos