added new thread
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package main.java.webcrawler;
|
||||
|
||||
import javafx.application.Application;
|
||||
import main.java.webcrawler.crawler.CrawlThread;
|
||||
import main.java.webcrawler.crawler.WebCrawler;
|
||||
import main.java.webcrawler.visualiser.Visualiser;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("Enter a starting URL : ");
|
||||
String startUrl = scanner.nextLine().trim();
|
||||
@@ -20,9 +21,10 @@ public class Main {
|
||||
System.out.print("Do you want to enable debug mode? (Y/N) : ");
|
||||
boolean debug = getChoice(scanner.nextLine());
|
||||
if (debug) System.out.println("[INFO] - Debug mode enabled");
|
||||
WebCrawler crawler = new WebCrawler(amount,save,debug);
|
||||
Application.launch(Visualiser.class);
|
||||
crawler.search(startUrl,word);
|
||||
// Application.launch(Visualiser.class);
|
||||
CrawlThread t = new CrawlThread(amount,save,debug,startUrl,word);
|
||||
t.start();
|
||||
System.out.println(t.getCrawler().getResultPages());
|
||||
}
|
||||
|
||||
private static boolean getChoice(String choice) {
|
||||
|
||||
49
src/main/java/webcrawler/crawler/CrawlThread.java
Normal file
49
src/main/java/webcrawler/crawler/CrawlThread.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package main.java.webcrawler.crawler;
|
||||
|
||||
public class CrawlThread extends Thread {
|
||||
|
||||
private final int amount;
|
||||
private final boolean save;
|
||||
private final boolean debug;
|
||||
private final String startUrl;
|
||||
private final String word;
|
||||
private WebCrawler crawler;
|
||||
|
||||
public CrawlThread(int amount, boolean save, boolean debug, String startUrl, String word) {
|
||||
this.amount = amount;
|
||||
this.save = save;
|
||||
this.debug = debug;
|
||||
this.startUrl = startUrl;
|
||||
this.word = word;
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.crawler = new WebCrawler(amount, save, debug);
|
||||
this.crawler.search(startUrl, word);
|
||||
}
|
||||
|
||||
public WebCrawler getCrawler() {
|
||||
return crawler;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public String getStartUrl() {
|
||||
return startUrl;
|
||||
}
|
||||
|
||||
public String getWord() {
|
||||
return word;
|
||||
}
|
||||
}
|
||||
@@ -12,21 +12,19 @@ import org.jfree.fx.FXGraphics2D;
|
||||
import org.jfree.fx.ResizableCanvas;
|
||||
|
||||
public class Visualiser extends Application {
|
||||
private Stage stage;
|
||||
private double frameTime = 0;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
BorderPane pane = new BorderPane();
|
||||
this.stage = primaryStage;
|
||||
ResizableCanvas canvas = new ResizableCanvas(this::draw, pane);
|
||||
canvas.setWidth(1600);
|
||||
canvas.setHeight(800);
|
||||
pane.setCenter(canvas);
|
||||
FXGraphics2D g2d = new FXGraphics2D(canvas.getGraphicsContext2D());
|
||||
draw(g2d);
|
||||
stage.setScene(new Scene(pane));
|
||||
stage.setTitle("Webcrawler results");
|
||||
primaryStage.setScene(new Scene(pane));
|
||||
primaryStage.setTitle("Webcrawler results");
|
||||
primaryStage.show();
|
||||
|
||||
new AnimationTimer() {
|
||||
|
||||
Reference in New Issue
Block a user