Bonjour à tous,

Je me suis lancé dans un petit projet qui est la programmation d'un navigateur web en Java. J'ai récemment appris le pattern MVC et j'ai donc voulu tester mes compétences.

Cependant, je me heurte à souci : Rien ne s'affiche. J'ai codé une View (la page en tant que tel) et un model (qui prend comme attribut le titre, l'url, un ArrayListe et un JEditorPane). Etant donné qu'il n'y a encore rien à contrôler, je ne l'ai pas encore développé.

J'ai tourné mon code dans plusieurs sens mais rien à faire. A noter également que je n'ai aucune erreur à la compilation ni à l'exécution.

Je suis désolé d'avance de balancer mon code comme ça mais je ne vois pas comment être plus précis =/. Le voici :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
 
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
 
public class NavigatorModel
{
	private URL url;
	private String title;
	private JEditorPane editorPane;
	private ArrayList<HyperlinkListener> listeVues;
 
	public NavigatorModel(URL url, String title)
	{
		this.url = url;
		this.title = title;
		try
		{
			this.editorPane = new JEditorPane(url);
		} catch (IOException ioe)
		{
			ioe.printStackTrace();
		}
		this.editorPane.setEditable(false);
		this.listeVues = new ArrayList<HyperlinkListener>(2);
	}
 
	public URL getUrl()
	{
		return url;
	}
 
	public void setUrl(URL url)
	{
		this.url = url;
	}
 
	public String getTitle()
	{
		return title;
	}
 
	public void setTitle(String title)
	{
		this.title = title;
	}
 
	public void setEditorPane(JEditorPane editorPane)
	{
		this.editorPane = editorPane;
		traiterEvent(new HyperlinkEvent(this, HyperlinkEvent.EventType.ACTIVATED, this.getUrl()));
	}
 
	public JEditorPane getEditorPane()
	{
		return this.editorPane;
	}
 
	public synchronized void addHyperlinkListener(HyperlinkListener chl)
	{
		if (!listeVues.contains(chl))
		{
			listeVues.add(chl);
		}
	}
 
	protected synchronized void traiterEvent(HyperlinkEvent e)
	{
		for (HyperlinkListener listener : listeVues)
		{
			listener.hyperlinkUpdate(e);
		}
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
import javax.swing.JPanel;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
 
public class NavigatorView extends JPanel implements HyperlinkListener
{
 
	private NavigatorModel model;
 
	public void setModel(NavigatorModel model)
	{
		System.out.println("Test Model View");
		if (model == null)
			return;
		this.model = model;
		this.model.getEditorPane().addHyperlinkListener(this);
		hyperlinkUpdate(new HyperlinkEvent(this, HyperlinkEvent.EventType.ACTIVATED, this.model.getUrl()));
	}
 
	@Override
	public void hyperlinkUpdate(HyperlinkEvent e)
	{
		if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
		{
			if (e instanceof HTMLFrameHyperlinkEvent)
			{
				HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
				HTMLDocument doc = (HTMLDocument) this.model.getEditorPane().getDocument();
				doc.processHTMLFrameHyperlinkEvent(evt);
			}
			else
			{
				try
				{
					this.model.getEditorPane().setPage(e.getURL());
				}
				catch (Throwable t)
				{
					t.printStackTrace();
				}
			}
		}
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
import java.awt.BorderLayout;
import java.net.MalformedURLException;
import java.net.URL;
 
import javax.swing.JFrame;
 
public class NavigatorDemo extends JFrame
{
	private NavigatorModel model;
 
	public NavigatorDemo()
	{
		URL url = null;
		try
		{
			url = new URL("http://www.google.be");
		}
		catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
		this.model = new NavigatorModel(url, "Google");
 
		NavigatorView view = new NavigatorView();
 
		view.setModel(this.model);
 
		this.add(view, BorderLayout.CENTER);
 
		this.setTitle("NavigatorDemo :: Page : " + this.model.getTitle());
		this.setSize(1024, 768);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
 
	public static void main(String[] args)
	{
		new NavigatorDemo();
	}
}
Merci d'avance!