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
| import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.*;
import javax.swing.text.StyledDocument;
public class Test {
public Test() throws MalformedURLException{
JFrame fenetre = new JFrame();
JPanel pan1=new JPanel();
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
//crée un objet URL :
String s="http://www.yahoo.com/";
URL helpURL = new URL(s);
try {
/*s = "file:" + System.getProperty("user.dir")
+ System.getProperty("file.separator")
+ "URL1.html";*/
helpURL = new URL(s);
/* ... utilise l'URL pour initialiser l'editor pane ... */
} catch (Exception e) {
System.err.println("Couldn't create help URL: " + s);
}
try {
editorPane.setPage(helpURL);
} catch (IOException e) {
System.err.println("Attempted to read a bad URL: " + helpURL);
}
pan1.add( editorPane);
fenetre.setTitle("Ma première fenêtre java");
fenetre.setSize(400, 500);
//Nous allons maintenant dire à notre objet de se positionner au centre
fenetre.setLocationRelativeTo(null);
fenetre.add(pan1);
//Terminer le processus lorsqu'on clique sur "Fermer"
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setVisible(true);
}
public static void main(String[] args) throws MalformedURLException{
Test objet1= new Test();
}
} |
Partager