ASK Access jList in other  .java files

I'm using Netbeans.
I create new project, let's just say the name abc.
In project abc, I create a.java and b.java
There's jList in a.java, let's just say the name is jList1.
I use this code to add text to jList1
((DefaultListModel)jList1.getModel()).addElement("Sample text");In b.java, also got jList, let's just say the name is jList2
I run the program from a.java
I want to ask how to add text to jList2 located at b.java while I'm running a.java ?

d_rev wrote:
I'm not really good in Java.
Can you please give me, just a simple code of what you mean to help me understand?No, not without seeing your whole program, which if it's a netbeans-generated program, no one here wants to see. The solution here is to get better at Java. Please have a look here: [http://java.sun.com/docs/books/tutorial/reallybigindex.html]

Similar Messages

  • How to compile other java files and run them from my own programs?

    I'm developing a unit testing tool for AspectJ, which can originally generate the stubs for aspect unit to be tested. All these stubs are java files. After generation of stubs, how can I program the code to compile this unit together with these stubs, i.e. how can I put the functionality of compilation and run, e.g. command "javac *.java" and "java *", into my own code.
    Hope you can understand what I mean.
    Thank you in advance.

    When I use Runtime.getRuntime().exec(command) for executing the AspectJ compile command "ajc", "IOException createProcess error=2" always occurs, while it is ok for Java comiple command "javac".
    Why this happens when I use Runtime.getRuntime().exec("ajc Hello.java Test.aj")? Is it the reason that Runtime.exec(String) may not support any command in DOS?
    (ajc is the compile command for the java file and aj file.)
    Thank you in advance.

  • How to run java source files from other java files??

    hello all,
    i need to run 3 to 4 .java files (first.java,second.java,third.java) from one file.
    i tried the
    Runtime.getRuntime().exec(cmd); but here cmd must be an exe file.
    NOTE THAT i need to run the first.java file ,second.java file each time to generate their .class files(ie I NEED TO COMPILE THEM ALL TIMES AND THEN RUN THEM)
    PLZ. help me if this can be done,
    warm regards,
    Vishal.

    One way to do this is to put all your commands into a batch file (this is Windows?) try unix shell otherwise. Anyway here's an example .bat file called cmplrun.bat:
    @echo off
    javac -classpath . TestCase*.java
    java -cp . TestCase01
    java -cp . TestCase02
    java -cp . TestCase03Then the Java pgm can look like this:
    import java.io.*;
    public class RunProcess {
      public static void main(String[] arg) {
        try {
          Process myProcess;
          myProcess = Runtime.getRuntime().exec("cmd /c cmplrun");
          String s = null;
          DataInputStream in = new DataInputStream(
                               new BufferedInputStream(
                                   myProcess.getInputStream()));
          while ((s = in.readLine()) != null) {
            System.out.println(s);
          System.exit(0);
        catch (IOException e) {
          System.out.println("Exception: "+ e);
          System.exit(-1);
    }Just one way to do this, all caveats apply and HTH;
    ~Bill

  • Is it possible to compile & run other java files from one file

    hi friends,
    i need to run 2,3 java sourse files(first.java,second.java etc) from one file.i tried the Runtime.getRunTime().exec( cmd) but here cmd must be a executable file
    what is need is to compile and run the files (first.java,second.java) from one other source file
    pls. help me in this matter,
    with warm regards,
    Vishal

    Sure:public class Test {
       public static void main(String[] args) {
          try {
             Runtime r = Runtime.getRuntime();
             r.exec("javac Test2.java");
          } catch (Exception e) {
    public class Test2 {
       public static void main(String[] args) {
          System.out.println("Hello World!");
    }Note that Test and Test2 are in two seperate files.

  • BUG: error rebuilding SQLJ files along other java files with generic

    I have done a rebuild on a package containing some SQLJ files, and (consistently) got the following error:
    C:\TeleMessage\trunk\src\telemessage\db\impl\dbAdmin.sqlj
        Error(44,18): Java Parsing. Encountered: <
        Expected: <IDENTIFIER> ...; "[" ...; The error at the cursor in the given file is not possible, since there was no '<' there, and besides - if I non-aggresively changed the file, e.g. narrowed imports, changed whitespace or added comments - the error remained in the same location.
    I went and done a search using regex in the package, for a line starting with 17 chars followed by a '<'.
    I found it in one of the normal JAVA files (not-SQLJ), at line 44 (surprise!) - in a Java 5 generics declaration, e.g. Map<String,Integer>. the 18th character was indeed the '<'.
    I'm guessing that the SQLJ translator (accidentally?) parses non-SQLJ files.
    If this cannot be fixed, it is really bad - it is one thing that JDeveloper cannot support Java 5 language features because of its dependancy in the SQLJ translator (which is not known to be upgraded until version 11g if at all), but the inability to compile SQLJ files in a project containing other non-SQLJ java files with Java 5 features is hard.
    I could only workaround this by rebuilding SQLJ files one at a time!
    I also have another type of error, when rebuilding the same project in a higher-level pacakge (root or "Application Sources"):
    C:\TeleMessage\trunk\src\dbtools\CallbackNumberFiller.sqlj
        Error(24,8): Missing semicolon.
        Error(24,8): Unbalanced curly braces.Again, the specified file could not be the one to blame - the location of the error is in the middle of the public modified keyword in a method declaration; nothing is neither missing nor unbalanced.
    This appears to be different, as it pops in the log near the end of the build process, when the JSPs are being built, specfically during the time the message log fills with "writing <...>" lines (after "translating <...>" and "compiling <...>".
    I can consistently reproduce both cases - please advise how I can help you find out what causes this.
    Regards,
    Yaniv Kunda

    First of all, this bug not JDeveloper's problem, but the SQLJ team's.
    You can read more posts about this:
    Re: BUG: Cannot translate SQLJ files with Java5 generics code
    Re: How to use SQLJ with Java 1.4 and 1.5?
    Re: SQLJ discontinued??
    And if we're at it, this is strange - I can't seem to find the oracle doc you quoted...
    SQLJ 11g? The latest release is a part of JPublisher 10.2 available from
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
    I also didn't find anything on google on 11g, nor about the part number you specified.
    Didn't find any Java 1.5 supporting SQLJ translators from other vendors as well.
    Do you have any link to this statement?
    But if we examine this bug again, the problem involves JDeveloper passing Java 5 featured JAVA files to the SQLJ translator.
    Isn't there a way to instruct the translator to use CLASS files compiled by a normal Java 5 compiler, instead of trying to compile the files itself?
    Regards,
    Yaniv Kunda

  • Is it possible to write a Java file that creates/compiles other Java files?

    My goal is to write a program that writes files containing Java code depending on the user's input. That's the easy part. The tough part, I think, is to get the Java file to use the Java compiler to compile, and run, those newly created files.
    I know this sounds crazy, but I really want to get this to work.
    Can someone please tell me how to do this?

    You could use the eclipse compiler
    http://help.eclipse.org/help31/index.jsp?topic=/org.ec
    lipse.jdt.doc.isv/guide/jdt_api_compile.htm
    Or the one from the JDK (com.sun.javac.Main located
    in the JDKs /lib/tools.jar). But that won't work with
    an JRE unless you ship the tools.jar too. And it
    isn't what i would call an official API. So i would
    rather use the eclipse compiler. I did this once and
    it worked fine.it isn't what sun call an official API, either, which is somewhat more important! the license even used to restrict re-distribution of tools.jar (I think that's changed now)

  • Imports (importing other java files)

    Hi there. this is sorta urgent.
    It works at uni, but not here, don't know why.
    I am using JDK 1.4.1_01 and jcreater lite as an IDE
    I have made a program, its for the course, but everytime I compile it says that the packages could not be found.
    for example:
    import Date.java;
    import Calander.java;
    public class mainapplication {
         public static void main(String[] args)
    ..It gives me an error:
    C:\coursework2\mainapplication.java:16: package Date does not exist
    import Date.java;
    ^
    C:\coursework2\mainapplication.java:17: package Calander does not exist
    import Calander.java;
    ^
    C:\coursework2\Date.java:15: package Calander does not exist
    import Calander.java;
    ^
    3 errors
    And if I take out the .java; from the imports commands, then it still won't compile, saying it's expecting a '.'!
    What should I do? I even tried going into MSDOS and typing javac mainapplication.java but i still get the same errors
    Please help, I know it's a simple solution, but need your help.
    Thanks

    It works at uni, but not here, don't know why.
    It does not work at uni, if you don't believe me go test it.
    The "import" statement only gives you the option to use short names for classes. Thanks to it you don't need to type the fully qualified class name, such as "javax.security.auth.kerberos.KerberosKey", every time you want to use the class ("KerberosKey"). It only exists to help you, the programmer, write shorter code and type less.
    That said, you cannot "import java files". It just makes no sense.
    Date and Calendar are both in the package java.util, maybe you want to "import java.util.Date" and "import java.util.Calendar".
    Hi there. this is sorta urgent.
    I hate people who use that word...

  • How to access profile value in java file

    We have an FND profile named XXAB_SITE_DETERMINE_URL. how can I access the value of it in my java class?
    Thanks for your help.

    Assuming you are in iStore framework, you should be able to get the value using the following method which returns a string value of the profile.
    String xxABUrl = IBEUtil.getProfile("XXAB_SITE_DETERMINE_URL");
    good luck..
    Vkky

  • How to initialized a variable in java file by taking the value from web.xml

    suppose i declare parameter in web.xml file
    i want to access if from a java file .
    how can i do this . plz help me its urgent...............

    In your Servlet class you can use the getInitParameter("configfile") method.

  • Compiling java files in DOS window

    Hi,
    I have been writin a small Client Server Application. I am attempting to use java packages in order to put certain class files into particular directories, and then import the packages when needed.
    So far, i have started my 1st attempt at a very small application just to send / receive messages. My problem is however, that i can compile all the java files into specific directories & packages no problem, but when i try to compile the java files which make use of these classes, i keep getting the same error.
    OK, i will try to simplify,
    My Server program (called MyServer.java) uses 2 classes (called ProcessTransaction, and NumberValidator), I have compiled the generated class files from ProcessTransaction.java and NumberValidator.java files into a DIR called C:\JavaForm\serverstuff. i.e. my server program imports the package "serverstuff,*;" The problem is that when i try to compile my server program i get the error message:
    "cannot access ProcessTransaction
    bad class file: c:\JavaForm\ProcessTransaction.java
    file does not contain class ProcessTransaction
    Please remove or make sure it appears in the correct subdirectory of classpath"
    I am using the command:
    javac -classpath c:\JavaForm c:\JavaForm\MyServer.java to compile the server file
    All the java and class files are stored in the C:\JavaForm folder
    I dont understand why the ProcessTransaction call cannot be accessed because it is most definitely in the compiled java file!!!
    Any help would be much appreciated!!!
    Cheers
    Iain

    it's OK, i figured out that to compile the Server program successfully, you have to remove all the other java files from the DIR which the Server.java files exists, or else there is a conflict!!!! I dont know why, but that's what you have to do!!!!

  • How to link two .java files together?

    hello everybody,
    is it possible to link two or more .java files together? I mean is if I have 3 .java files. (a.java, b.java, c.java) then I have 3 .class files too. How do I use the method in other .java files. For example :
    public a extends Applet {
    // call b.class
    b();
    public b extends Applet implements ActionListener {
    void title1() {
    How to call the b.class? How to call the title1() method?
    Is it related to JAR or package??
    Thanks for helping me. v(^_^)v

    O.K, you do not link ".java" files together.
    You compile them into class files and they can create new instances of each other and and access their variables and work together.
    I recommend "Sam's Teach Yourself Java in 21 Days".
    It will start you out with the basics.
    --Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • Compiling / Running a Java file in JSP

    Hi,
    ok, I have a jsp page, which we will call page 1. Once I go to that page, I all I want it to do is compile a certain file.java, and then run the file.java. The user doesn't actually know that this is going on in the background. Page 1 automatically redirects the user to page 2 (also a jsp page).
    The java program that I created (that was previously compiled and ran) creates a special javascript file. After running the file.java in page #1, the java file creates a javascript file that will be used in page 2 to display a tree node (group of information).
    so, right now, I'm trying to figure out how to write the jsp code that will tell how to compile and run a java file. I was thinking about using javabeans before, but I think you HAVE to actually display the contents of the java file into the jsp (I think). Anyhow, thanks for the help!

    sorry about being ambiguous before. What I mean by
    running a java file was that I already created a java
    file. I don't want to hava my java statements inside
    the jsp file. I just want the jsp file have a command
    in it that would call a java file, tell the java file
    to compile and run. All the jsp file would do
    (hopefully) is just give commands for a seperate java
    file to compile and run. Thanks again for any help!Ok, so this other java file has some entry-point method, like main(), right? So call it...
    <%
    YourJavaClass.main(appropriateArgumentsGoHere);
    %>
    or better yet, it's an object you can use:
    <%
    YourJavaClass x = new YourJavaClass();
    x.callSomeMethodHere(withAppropriateArgumentsHere);
    x.callAnotherMethodMaybe();
    %>
    You don't need the jsp file to "compile" this java file, you'd already have compiled it beforehand, and it's class bytecode needs to be in your classpath (on the server side) of course.

  • Converting a java file to a web service

    How can i convert a java file to a web service,And then invoke that service by making my other java file.

    You can convert your java file into a WSDL with the WSDL2Java utility in Axis. This will create a definition that will be accessible by potential clients.
    To deploy your java class, you can use Axis in a Web Server of your choice (Tomcat, Apache). All you need to do is run the Axis Admin Client for a deploy.wsdd file and point your client to the IP:PORT.
    Very straightforward.
    http://ws.apache.org/axis/java/user-guide.html
    Hope it helps.
    SBO

  • Java application compiles java files in memory

    how can I use java application program (that may call method runtime exec or some other techniques) to compile the other java files that were already loaded in memory. (I can not copy those target files to the hard disk with extension java, then compile for security reason).

    And once they are compiled, where do you plan to put the compiled .class files? Same security problem, right? Perhaps you planned to load and use them "from memory" somehow? This would be a different security problem. Perhaps you need to rethink what you are doing.

  • How to break up a large .java file into several?

    Hi,
    I have a pretty large .java file containing many private methods. I rather not have to always work in this very large file. Is there a way to separate this into several smaller files, but to maintain the same relationship of all these private methods being part of the same class?
    Thanks in advance,
    Steve

    I thought that would be the answer. This is my first
    Java app. It uses Swing and I use NetBeans as my
    IDE.
    I knew it was getting too large, but I was trying to
    avoid having to reimplement the whole thing. I have a
    few more features to add and I can see this file
    growing by another 300-400 lines.You'll find it a lot simpler to write the second time round. You really don't want to have classes that big
    I do in fact have a couple other .java files where I
    created separate classes. Its just that I really need
    to rethink or redesign this whole thing.You do. Sounds like you've got one class that does too many things. What does this big class do? Adding new features shouldn't bloat your code this way

Maybe you are looking for