[Java] Web Browser Project Summary





Summary of the web browser project

This project consists of two parts. The first part is creating a web browser with simple menus and the second part is adding more features, such as add/remove bookmarks by using text file, displaying html/XML if user wants, and go back/forward menus.

I could thoroughly understand how (general) Java and JavaFX are interacting together and it was very interesting project. The cool thing was not just displaying the output on the console in Eclipse, able to create actual application.

Here is what I've learnt from this project.



ArrayList with File (FileNotFoundExcetiption)

public static ArrayList<String> getURLsFromFile(String fileName) {
ArrayList<String> arrayListOb = new ArrayList<>();

try {
File f = new File(fileName);
Scanner URLString = new Scanner(f);
while (URLString.hasNext())
arrayListOb.add(URLString.next());
URLString.close();
} catch (FileNotFoundException e) {
}
return arrayListOb;


ObservableList<Type>

final WebHistory history = we.getHistory();
ObservableList<WebHistory.Entry> entryList=history.getEntries();
int currentIndex=history.getCurrentIndex();


ListView<Type>

public static ListView<WebHistory.Entry> historyList(WebEngine we){
WebHistory history = we.getHistory();
ObservableList<WebHistory.Entry> obsList = history.getEntries();
ListView<WebHistory.Entry> listView = new ListView<WebHistory.Entry>(obsList);
return listView;
}


GoBack button algorithm without error

Platform.runLater(() -> 
{ history.go(entryList.size() > 1 && currentIndex > 0 ? -1: 0); });        


JavaFX Keycombination (shortkey)

mnuItm.setAccelerator(KeyCombination.keyCombination("Ctrl+R"));



EventHandler setOnAction  (only left mouse click)

mnuItm.setOnAction((ActionEvent e) -> Platform.exit());


EventHandler setOnMouseClicked (left and right click)

custom.getContent().setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
if (e.getButton()==MouseButton.PRIMARY)
goToURL(URL);
if(e.getButton()==MouseButton.SECONDARY) { .. };




Comments

Popular Posts