I am working on simulation and i need to display data to TextArea or JTable, that is generating continuously at run time.

----------------------------simulation class----------------
Class Simulation()
{

when Nubmer Generate
call method ' updateData' in Frame Class to upload on JTextArea.

}

-----------------------------------frame class---------------
Class JFrame()
{
Method updateData(string data)
{
jTextArea1.append(data);
}

thanks in advance for helping me..

Are you having problems with your code? Can you explain what the problem is?
If needed, Please post a small sample program that demonstrates the problem.

------GUI Class (this class suppose to display data in textArea with every update in simulation class------

problem: in simplist form, my simulation class has method 'SimulationData()' when its value update, it call method in GUI call with parameter and it update jTextArea...

now if i use dis gui method from constructor class or if i call it from JButton event then it display data in jTextArea otherwise it dont

Edited 5 Years Ago by khurram01: n/a

------GUI Class (this class suppose to display data in textArea with every update in simulation class------

problem: in simplist form, my simulation class has method 'SimulationData()' when its value update, it call method in GUI call with parameter and it update jTextArea...

now if i use dis gui method from constructor class or if i call it from JButton event then it display data in jTextArea otherwise it dont

public class mainFrame extends javax.swing.JFrame {

public mainFrame() {

initComponents();

         //displayMe("test data inside the 'mainFrame' constructor");

}


@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("press me");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(119, 119, 119)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(108, 108, 108)
.addComponent(jButton1)
.addGap(28, 28, 28)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(28, Short.MAX_VALUE))
);

pack();
}// </editor-fold>



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{
                jTextArea1.append("data 1 2 3");
}


public void displayMe(String data)
{
                jTextArea1.append(data);
}


private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

}

//--------------simulation class------------------//

public class mainClass {

public void SimulationData()
{
   new mainFrame().displayMe("sorted data from simulation method");
}


public static void main(String[] args) 
{
       java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                 new mainFrame().setVisible(true);
}});

           new mainClass().SimulationData();
}
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

if i use dis gui method from constructor class or if i call it from JButton event then it display data in jTextArea otherwise it dont

What happens when you call it from another location?
Are there more than one JTextAreas? One is being shown in the GUI and shows the data added to it. The other is not being shown in a GUI and therefore does not show the data that is added to it.

the above class is just experiment, which i am trying to do.... and I am stuck with it...

all I am trying to do; when my simulation class method generate data (int for example), it call the method in GUI class and that class display that data in JTextArea.

no I have only 1 jtextArea, that is in GUI class

To see if you have more than one text area being created, add println("creating TA") statement next to where you create the text area. Run the program and see how many times the println prints out a message.

Edited 5 Years Ago by NormR1: n/a

I make it working ... with creating new instance of GUI method to display data
display ' new GUI().displayData(newData) ' but when I say in simulation class GUI gui_obj = new GUI(); and then In Simulation class call gui_obj.displayData(newData) then it does't display in textArea.....
i-e

i knw i am missing something but cant think of my head.... once again thanks for guiding me

----------------------code--------------------

Class Simulation()
{
    public void simulationData()
     {    
          String newData = generated Simulation result;

           new GUI().displayData(newData)
}


class GUI()
{
 public void displayData(String data)
{   textArea1.append(data)   }
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Did you try adding a println next to where the text area was created to see how many text areas are created?

This article has been dead for over six months. Start a new discussion instead.