I have a code where I'm taking input from user and after clicking on SUBMIT button it executes my logic and shows user a JTextArea on a new frame but the problem is it shows after program executes totally. I have used System.out.println and consoleText.append to see if it's happening on both eclipse and JTextArea but console on eclipse was updating with the code executes but JTextArea only shows when code executes totally.
Here's the code -
MainApp.java
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.skillnetinc.marker.utility.InputUtility;
public class MainApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
showGUI();
}
});
}
protected static void showGUI() {
JFrame inputFrame = new JFrame("Marker Deletion Script");
inputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inputFrame.setSize(800, 300);// 800 width and 500 height
inputFrame.setLayout(null);// using no layout managers
inputFrame.setVisible(true);// making the frame visible
inputFrame.setLocationRelativeTo(null);
InputUtility.showUserInputFields(inputFrame);
InputUtility.buttonActivity(inputFrame);
}
}
& InputUtility.java
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class InputUtility {
public static JFrame tableFrame;
public static JTextArea markerDesc, consoleText;
public static JLabel labelMarkerDesc;
public static void showUserInputFields(JFrame inputFrame) {
labelMarkerDesc = new JLabel("<html>Marker<br>Description</html>");
labelMarkerDesc.setBounds(50, 115, 100, 30);
markerDesc = new JTextArea(10, 20);
markerDesc.setBounds(150, 15, 300, 230);
markerDesc.setBorder(BorderFactory.createLineBorder(Color.gray));
inputFrame.add(markerDesc);
inputFrame.add(labelMarkerDesc);
}
public static void buttonActivity(JFrame inputFrame) {
JButton submit = new JButton("SUBMIT");
submit.setBounds(520, 50, 150, 40);
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
consoleText = new JTextArea();
consoleText.setEditable(false);
consoleText.setVisible(true);
JScrollPane sp = new JScrollPane(consoleText);
tableFrame = new JFrame("Script Result");
tableFrame.add(sp);
tableFrame.setSize(800, 300);
tableFrame.setVisible(true);
tableFrame.setLocationRelativeTo(null);
testConsole(consoleText);
}
});
inputFrame.add(submit);
}
public static void testConsole(JTextArea consoleText) {
String marker[] = InputUtility.markerDesc.getText().split("\n");
for (int i = 0; i < marker.length; i++) {
String posName = marker[i].split(" ")[0];
File file = new File("\\\\" + posName + "\\C$\\environment\\marker");
consoleText.append("\nChecking for marker inside " + file);
System.out.println("\nChecking for marker inside " + file);
File[] files = file.listFiles();
if (file.canRead()) {
consoleText.append("Found Total " + files.length + " markers inside " + file);
System.out.println("Found Total " + files.length + " markers inside " + file);
}
}
}
}
Input from user will be something like
192.168.75.18 startup.err
192.168.87.99 startup.err
192.168.66.38 startup.err