Actually sabzh. In a separate class parsu page, in another I create a GUI. I need to pass the result of the parsing (cycle) to JTextArea. I study the second week for a second, I ask you not to rush with the slippers. Parsing:
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.List; public class parseClass { public void go() throws Exception { List<Article> articleList=new ArrayList<>(); Document doc=Jsoup.connect("http://4pda.ru").get(); Elements divelements=doc.getElementsByAttributeValue("itemprop","description"); divelements.forEach(divelement -> { Element pElement=divelement.child(0); // String url=pElement.attr("style"); String title=pElement.text(); articleList.add(new Article(null,title)); }); articleList.forEach(System.out::println); } public ArrayList<String> getTextList(){ ArrayList<String> textList=new ArrayList<String>(); return textList; } } } class Article{ private String url; private String name; public Article(String url, String name) { this.url = url; this.name = name; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Text= "+name + '\n' ; } } GUI:
import javax.swing.*; import javafx.stage.Screen; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Label; import java.awt.event.*; public class guiParse { JLabel label; JFrame frame; JTextArea jt; JScrollPane scroll; public void gui() { label=new JLabel("text"); jt=new JTextArea(16,58); jt.setText("kakoy to text"); jt.setEditable(false); frame =new JFrame(); JPanel panel=new JPanel(); scroll= new JScrollPane(jt); panel.setLayout(new FlowLayout()); panel.add(scroll); frame.add(panel); //frame.getContentPane().add(BorderLayout.SOUTH,); frame.setTitle("Future App"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400,400); frame.setVisible(true); } } main:
import javax.swing.*; import java.util.ArrayList; import java.util.List; import javafx.stage.Screen; import java.awt.BorderLayout; import java.awt.Label; import java.awt.event.*; class jSoupTest { public static void main(String[] args) throws Exception { parseClass parse=new parseClass(); parse.go(); guiParse gui=new guiParse(); gui.gui(); } }
That is, there is a separate call, I can’t transfer it. I didn’t work with the lists especially, for the first time I apply it, just pass by the String parameter to the gui did not work by itself.