How to refresh a JTable of a class from another thread class?

there is an application, in server side ,there are four classes, one is a class called face class that create an JInternalFrame and on it screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert into db,then notify the face class to refresh the JTable,but in the thread class I used JTable's revalidate() and updateUI() method, the JTable does not refresh ,how should i do, pls give me help ,thank you very much
1,first file is a class that create a JInternalFrame,and on it there is a table
public class OutFace{
public JInternalFrame createOutFace(){
JInternalFrame jf = new JInternalFram();
TableModel tm = new MyTableModel();
JTable jt = new JTable(tm);
JScrollPane jsp = new JScrollPane();
jsp.add(jt);
jf.getContentPane().add(jsp);
return jf;
2,the second file is the main face ,there is a button,when press the button,screen the JInternalFrame. there is also a thread is beggining started .
public class MainFace extends JFrame implements ActionListener,Runnable{
JButton jb = new JButton("create JInternalFrame");
jb.addActionListener(this);
JFrame fram = new JFrame();
public void performance(ActionEvent e){
JInternalFrame jif = new OutFace().createOutFace(); frame.getContentPane().add(JInternalFrame,BorderLayout.CENTER);
public static void main(String[] args){
frame.getContentPane().add(jb,BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
ServerSokct ss = new ServerSocket(10000);
Socket skt = ss.accept()'
new ServerThread(skt).start();
3.the third file is a thread class, there is a serversoket ,and accept the client side data,and want to refresh the JTable of the JInternalFrame
public class ServerThread extends Thread{
private skt;
public ServerThread(Sokcet skt){
this.skt = skt;
public void run(){
OutputObjectStream oos = null;
InputObjectStream ios = null;
try{
Boolean flag = flag;
//here i want to refresh the JTable,how to write??
catch(){}
4.second is the TableModel
public class MyTableModel{
public TableModel createTableModel(){
String[][] data = getData();
TableModel tm = AbstractTableModel(
return tm;
public String[][] getData(){
}

Use the "code" formatting tags when posting code.
Read this article on [url http://www.physci.org/codes/sscce.jsp]Creating a Simple Demo Program before posting any more code.
Here is an example that updates a table from another thread:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=435487

Similar Messages

  • Help! how to refresh the JTable of a class from another thread class

    there is an application, in server side ,there are two classes, one is a class called face class that screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert into db,then notify the face class to refresh the JTable,but in the thread class I used JTable's revalidate() and updateUI() method, the JTable does not refresh ,how should i do, pls give me help ,thank you very much

    thank you very much !
    i tried it ,but the TableModel i used like this ,and how to change the TableModel?
    here the files of mine ,pls give me some help,thank you very much
    1,first file is a class that create a JInternalFrame,and on it there is a table
    public class OutFace{
    public JInternalFrame createOutFace(){
    JInternalFrame jf = new JInternalFram();
    TableModel tm = new MyTableModel();
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane();
    jsp.add(jt);
    jf.getContentPane().add(jsp);
    return jf;
    2,the second file is the main face ,there is a button,when press the button,screen the JInternalFrame. there is also a thread is beggining started .
    public class MainFace extends JFrame implements ActionListener,Runnable{
    JButton jb = new JButton("create JInternalFrame");
    jb.addActionListener(this);
    JFrame fram = new JFrame();
    public void performance(ActionEvent e){
    JInternalFrame jif = new OutFace().createOutFace(); frame.getContentPane().add(JInternalFrame,BorderLayout.CENTER);
    public static void main(String[] args){
    frame.getContentPane().add(jb,BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
    ServerSokct ss = new ServerSocket(10000);
    Socket skt = ss.accept()'
    new ServerThread(skt).start();
    3.the third file is a thread class, there is a serversoket ,and accept the client side data,and want to refresh the JTable of the JInternalFrame
    public class ServerThread extends Thread{
    private skt;
    public ServerThread(Sokcet skt){
    this.skt = skt;
    public void run(){
    OutputObjectStream oos = null;
    InputObjectStream ios = null;
    try{
    Boolean flag = flag;
    //here i want to refresh the JTable,how to write?? }
    catch(){}
    4.second is the TableModel
    public class MyTableModel{
    public TableModel createTableModel(){
    String[][] data = getData();
    TableModel tm = AbstractTableModel(
    return tm;
    public String[][] getData(){
    }

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How sholud we call one jframe class from another jframe class

    Hi
    In my application i am calling one jframe class from another jframe clas.
    how sholud we make previous jframe inactve when another jframe is invoked?(user sholud not able to make any changes on on parent jframe window when another jframe is invoked)
    Pls reply.

    Sorry for me it is not possible to change existing code,
    pls suggest me any other solution so that i can inactive parent jframe when child jframe execution is going on.

  • Referencing WMI Manageable class from another WMI Class

    Hi,
    I am trying to have WMI manageable class referring to another WMI manageable class
    Something like
    [ManagementEntity]
    Class A
    [ManagementEntity]
    Class B
            [ManagementReference(Type = "A")]
            [ManagementProbe]
            public A AClass;
    When trying to install the class, I am getting “Type unsupported”
    I tried the Microsoft
    ManagementReference sample,
    http://msdn.microsoft.com/en-us/library/system.management.instrumentation.managementreferenceattribute.aspx
    (working fine but the LetterPhonetic class won’t show on the WMI Object Browser)
    Ideas will be highly appreciated
    My Sample code
    using System;
    using System.Management.Instrumentation;
    using System.Collections.Concurrent;
    using System.Collections;
    [assembly: WmiConfiguration("root\\ConsoleC", HostingModel = ManagementHostingModel.Decoupled)]
    namespace ConsoleDecoupled
        [System.ComponentModel.RunInstaller(true)]
        public class TheInstaller : DefaultManagementInstaller
        public class Program
            public static void Main(string[] args)
                for (int i = 0; i < 10; ++i)
                    TestEnumWmi ms = TestEnumWmi.CreateTestEnumWmi();
                    ms.teststring = i.ToString();
                InstrumentationManager.RegisterType(typeof(TestEnumWmi));
                InstrumentationManager.RegisterType(typeof(RuntimeConfigSettings));
                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
                InstrumentationManager.UnregisterType(typeof(TestEnumWmi));
                InstrumentationManager.UnregisterType(typeof(RuntimeConfigSettings));
        [ManagementEntity(Singleton = true, Name = "ConfigurationSample")]
        [ManagementQualifier("Description", Value = "Configuration Sample Application")]
        public class RuntimeConfigSettings
            [ManagementProbe]
            public string[] ReadMe;
            private int myVar;
            [ManagementConfiguration]
            public int MyProperty
                get { return myVar; }
                set { myVar = value; Console.WriteLine(value); }
            [ManagementReference(Type = "TestEnumWmi")]
            [ManagementProbe]
            public TestEnumWmi MSS;
            [ManagementBind]
            public RuntimeConfigSettings()
                ReadMe = new string[10];
                for (int i = 0; i < 10; ++i)
                    ReadMe[i] = "blah " + i;
        [ManagementEntity(Name = "TestEnumWmi")]
        public class TestEnumWmi
            private TestEnumWmi()
            static internal TestEnumWmi CreateTestEnumWmi()
                TestEnumWmi ms = new TestEnumWmi();
                ms._id = Guid.NewGuid().ToString();
                ms.teststring = "blah";
                ms.TestInt = new Random().NextDouble();
                instantlist.TryAdd(ms._id, ms);
                return ms;
            [ManagementConfiguration()]
            public double TestInt { get; set; }
            [ManagementConfiguration()]
            public string teststring { get; set; }
            [ManagementKey(Name = "ID")]
            public string _id;
            [ManagementBind]
            static public TestEnumWmi GetInstant([ManagementName("ID")] string ID)
                TestEnumWmi ms = null;
                if (instantlist.TryGetValue(ID, out ms))
                    return ms;
                else
                    throw new InstanceNotFoundException();
            [ManagementEnumerator]
            static public IEnumerable EnumerateTestEnumWmis()
                foreach (var i in instantlist)
                    yield return i.Value;
            static internal ConcurrentDictionary<string, TestEnumWmi> instantlist = new ConcurrentDictionary<string, TestEnumWmi>();

    Hi,
    The Microsoft ManagementReference sample you mentioned contains a bug:
    Instead of:
    inst.LetterNumber = "Letter = " + i;
    inst.PhoneticNumber = "Phonetic = " + i;
    The exact text (where spaces in the string are important and must be removed) should be:
    inst.LetterNumber = "NumberLetter.Number=" + i;
    inst.PhoneticNumber = "NumberPhonetic.Number=" + i;
    With this fix, the hierarchy can now be navigated properly.
    c.f. my response to the following blog post:
    http://juggledthoughts.blogspot.co.uk/2008/06/wmi-association-classes.html
    I have also
    logged a bug on MSDN Feedback so please vote on this if you'd like them to fix the sample.

  • How I call a JApplet class from another JApplet class ?

    I have a Japplet class named ConnectionClient and I want to open another JApplet window when I clicked a button.
    I tried that call init() method but it is not accomplished. Please help me !

    for example:
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.Window;
    import java.awt.Dialog.ModalityType;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    public class MyApplet extends JApplet
      public void init()
        try
          javax.swing.SwingUtilities.invokeAndWait(new Runnable()
            public void run()
              createGUI();
        catch (Exception e)
          System.err.println("createGUI didn't successfully complete");
      private void createGUI()
        getContentPane().add(new AppletPanel().getComponent());
    class AppletPanel
      private JPanel mainPanel = new JPanel();
      public AppletPanel()
        JButton showDialog = new JButton("Show Dialog");
        mainPanel.add(showDialog);
        showDialog.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            JButton btn = (JButton)e.getSource();
            Window win = SwingUtilities.getWindowAncestor(btn);
            JDialog dialog = new JDialog(win, "My Dialog", ModalityType.APPLICATION_MODAL);
            dialog.getContentPane().add(new DialogPanel().getComponent());
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
      public JComponent getComponent()
        return mainPanel;
    class DialogPanel
      private static final int SIDE = 9;
      private JPanel mainPanel = new JPanel();
      public DialogPanel()
        JPanel btnPanel = new JPanel(new GridLayout(SIDE, SIDE, 5, 5));
        for (int i = 0; i < SIDE; i++)
          for (int j = 0; j < SIDE; j++)
            JButton btn = new JButton("[" + i + ", " + j + "]");
            btnPanel.add(btn);
        JLabel titleLabel = new JLabel("JDialogs Can Be Complex", SwingConstants.CENTER);
        titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 32));
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(titleLabel, BorderLayout.NORTH);
        mainPanel.add(btnPanel, BorderLayout.CENTER);
      public JComponent getComponent()
        return mainPanel;
    }

  • How do I call an Application Module method from a EntityImpl class?

    Guys and Gals,
    Using Studio Edition Version 11.1.1.3.0.
    I've got a price update form, that when submitted, takes the part numbers and prices in the form and updates the corresponding Parts' price in the Parts table. Anytime this Parts view object's ReplacementPrice attribute is changed, an application module method needs to be called which updates a whole slew of related view objects. I know you can modify view objects via associations (How do I call an Application Module method from a ViewObjectImpl class? but that's not what I'm trying to do. These AppModuleImpl methods are the hub for all price updates, as many different operations may affect related pricing (base price lists, price buckets, etc) and hence, call the updatePartPricing(key) method.
    For some reason, the below code does not call / run / activate the application module's method. The AppModuleDataControl exists and recordPartHistory(key) is registered and public. At runtime, the am.<method> code is simply ignored, and as a weird side-effect, I cannot navigate out of my current page flow.
      public void setReplacementPrice(Number value)
        setAttributeInternal(REPLACEMENTPRICE, value);
        AppModuleImpl am = (AppModuleImpl)this.getDBTransaction().findApplicationModule("AppModuleDataControl");
        Key key = new Key(new Object[]
            { getPartNumber() });
        am.recordPartHistory(key);  // AppModuleImpl method which records pricing history
        am.updatePartPricing(key); // AppModuleImpl method which updates a whole slew of related pricing tables
      }Any ideas?

    Thanks Timo.
    Turns out the code provided was correct, but the AppModuleImpl method being called was not. A dependent ViewObject wasn't returning the row I was expecting. I then tried to perform some operations on that row, which in turn ... just stopped everything, but didn't give me an error.
    It was the lack of the error that threw me off. I had never messed with calling an AppModuleImpl method from the EntityImpl so I assumed that's what was messing up.
    You are correct. It is available from the ViewRow, but I thought it better to put it in the EntityImpl. This method will be called every time the replacement cost is modified. If I didn't put it in the EntityImpl, I'd have to remember to call it every time a replacement cost changed.

  • How to pass a "object" as a prameter from one java class to another java

    hi experts, I want to know "How to pass and get object as a parameter from one java class to another java class". I tried follwoing code just check it and give suggetions..
    import Budget.src.qrybean;
    public class ConfirmBillPDF extends HttpServlet
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");
    }Here i want to pass db with simplePDFTableShow method. simplePDFTableShow is in another java class. So how can i do this.
    And also i want to know, how this obj will get.
    please help me.
    Edited by: andy_surya on Jul 14, 2010 7:51 AM

    Hi andy_surya
    what is this i am not understand
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");but i am try to solve your problem try this
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow(db);and access like this in SimplePDFtable class update your method
    simplePDFTable(qrybean tempDB)
    // write your code
    }

  • How to access private attribute of a class from its Friend Class

    Hi Experts ,
    I am coding in Method (DO_SAVE) of class /BOBF/CL_TRA_TRANSACTION_MGR.
    I need to access private variable ( MO_BOPF) of class /BOBF/CL_TRA_SERVICE_MGR ( Friend of /BOBF/CL_TRA_TRANSACTION_MGR ).
    Please help me to understand how can i access private attribute of one class from its friend class.
    Regards- Abhishek

    Hi Reny,
    You should be able to access by creating object of friend class.
    Sample:
    data lo_frnd     TYPE REF TO  /BOBF/CL_TRA_SERVICE_MGR.
    data lo_compl  type REF TO /BOBF/IF_TRA_TRANS_MGR_COMPL.
       create OBJECT lo_frnd
         exporting
                   iv_bo_key = '111'
                   IO_COMPL_TRANSACTION_MANAGER = lo_compl.
    "access the private object of friend class
       clear lo_frnd->MO_BOPF.
    Note: need to provide iv_bo_key & IO_COMPL_TRANSACTION_MANAGER while creating object.
    Hope this helps you.
    Regards,
    Rama

  • How Do I Run A Class From Another Class?

    Hiya everyone, id like to know how to run a class from another class.
    Ive got a Login class which extends a JFrame and a Personnel class which also extends a JFrame. When i press the login button (in Login class), ive got it to decide if password/login are acceptable and if they are, I want the Login class to close then run the Personnel class.
    Im just after the code which says to close this class and run the Personnel class. How do i do that?
    Ive researched this but couldnt get an understandable answer!
    Help would be much appreciated, Ant...

    This is the Login Class:
    public class MainMenu extends javax.swing.JFrame {
        Statement statement = null;
        int currentRecord;
        ResultSet rs = null;
        String name = null, job = null, mission = null, login = null, password = null;
        String loginVal;
        String passwordVal;
        /** Creates new form MainMenu */
        public MainMenu() {
            initComponents();
            try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String filename = System.getProperty("user.dir") + "/src/Personnel.mdb";
                String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + filename;
                Connection conn = DriverManager.getConnection( database , "","");
                statement = conn.createStatement();
                System.out.println("Connected...ok");
            } catch (Exception e) {
                System.err.println("Got a connection Problem!");
                System.err.println(e.getMessage());
        private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                        
            loginVal = txtLogin.getText();
            passwordVal = txtPassword.getText();
            String name = null, job = null, mission = null, login = null, password = null;
            try{
                rs = statement.executeQuery("SELECT Login,Password FROM Personnel WHERE Login = '" + loginVal + "' ");
                System.out.println("TRYING SELECT CLAUSE");
                if(rs.next()){
                    System.out.println("THERE IS A NEXT RECORD");
                    login = rs.getString(1);
                    password = rs.getString(2);
                    System.out.println("GOT THE NEXT RECORD");
                    System.out.println(login + password);
                System.out.println("Query Complete");
            }catch(Exception s){
                //s.printStackTrace();
                System.out.println("NO RECORDS EXIST FOR THIS LOGIN ID");
            if(passwordVal.equals(password)){
                System.out.println("Access Granted"); //CLOSE MAIN AND RUN CONTROL CLASS
            } else{
                System.out.println("Access Denied"); //RE-RUN CLASS
        }                 

  • How to kill one class from another class

    I need to dipose one class from another class.
    So that first i have to find what are all threads running in that class and then to kill them
    Assist me.

    Subbu_Srinivasan wrote:
    I am explaining you in clear way
    No you haven't been.
    >
    In my application i am handling many JInternalFrame.Simultaneously i am running working on more than one frame.
    Due to some poor performance of some thread in one JInternalFrame,the thread is keeps on running .
    i could not able to proceed further on that screen.
    So i have to kill that JInternalFrame.Yoinks.
    To be begin with your problem sounds like you are doing everything in one thread. So stop doing that. Second when you get it split up and if a task is taking too much time then interrupt it. No kill. Interrupt. This means the worker thread needs to check sometimes if it has been interrupted.

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

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

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

  • Importing a class from another context?

    Hi JSP techies,
    Im using RESIN and having a simple problem of figuring out how to import classes from another context, if Im using the right word.
    ie.
    My .jsp files are under $home/resin/doc/test dir. And in the jsp file, I would like to import a servlet class or a plain java class. But the servlet classes and all other classes are located under $home/resin/webapps/project/WEB-INF/classes/a/b/c
    Hence when I say
    <% page import="a.b.c.*" %>
    I get an error saying "a" not found.
    1. When I say "servlet classes are in a different CONTEXT", is that right? or is it just another directory?
    2. How can I make the jsp file import the classes from the servlets class path?
    Note: Ofcourse, when I copy the package to the
    $home/resin/doc/WEB-INF/classes dir, everything works fine. But thats simply not an efficient way to get around. Could anyone clear my doubts on this regd.?
    Thanks in advance.
    Arun

    Oh... I get it now. I'm sorry, I had you poorly misunderstood. You are trying to import servlets from another web app or servlet context. I would suggest you put servlets that are common to all web apps in the system classpath and not tie them to any particular web app. In other words create a package directory structure from the system's root directory or any where outside of any web apps and point the system classpath to the beginning of that directory structure. I have a similar thing going with Tomcat. I have a folder in my root called Java_Class which is in my classpath. I build all common utilities in this directory. So I have a com/craig/web structure that holds my AppServlet which is in package com.craig.web. This servlet is visible to all web apps via the Windows classpath. Servlets particular to an application like say an MusicOrderProcess servlet would reside in a package under the webserverhome/webapps/MusicStore/WEB-INF/classes directory where webserver home is the home directory of the webserver you are using. I've tested this across webservers as well (orionserver and Tomcat) and it works.
    From the prompt you include in your posts I am guessing that you are running on UNIX. Move your common servlets out of their respective web apps and into a common directory structure. Configure the UNIX $CLASSPATH (or is it $classpath?) environment variable to point to this sturcture and you'll be on your way!
    Post again if you have more questions!

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

Maybe you are looking for

  • How do i put classes in package in NetBean Environment

    Hello, I install NetBean IDE for developing website using JSP and Servlet. I am using Internal Tomcat provided by this IDE. Problem is this i put java classes in the Class folder of Web-INF folder, but i am not able to access these classes from JSp p

  • File to Idoc Nodes mapping

    My sender File structure is like this.. MT_Sender -Recordset 0 to Unbound --Header 1 to 1 ---field1 ---field2 ---fieldx --GL_Account 0 to Unbound ---field1 ---field2 ---fieldx ---Cust_Item 0 to Unbound field1 field2 fieldx Curr_Item 0 to Unbound fiel

  • Need info on livecycle pdf generator

    Hi,    My requirment is:                           Convert different image file and word document file (.doc,.docx) to pdf and merge to a single pdf and display it to the client over the net.       I think I can use Livecycle Pdf generator to fulfill

  • Xcode 3.1.2 and applescript studio...

    Hi everyone! I have been previously unable to upgrade to Xcode 3.1 because when I open my script there is so much empty spacing now inserted between lines and characters and I'm not sure if it's going to be a problem or not. I just tried to upgrade t

  • Stacks not sorting correctly

    In the documents folder I have it set to sort by date modified, but it doesn't seem to refresh the sorted order of the stack after I modify a file. The only way that I can get it to refresh the stack is to log out and back in. Does anyone know how to