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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| package fr.dinge;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
public class Main {
public static Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
public static int Swidth = (int)size.getWidth();
public static int Sheight = (int)size.getHeight();
public static void main(String[] main) {
Accueil.show();
}
}
class Accueil {
public static int width = 1100;
public static int height = 700;
private static int newX = 0;
private static int newY = 0;
private static int newwidth = width;
private static int newheight = height;
public static void show() {
System.out.println("here");
JFrame frame = new JFrame();
frame.setTitle("SH Project");
frame.setBounds((Main.Swidth/2-width/2), (Main.Sheight/2-height/2), width, height);
frame.setBackground(Color.BLACK);
JPanel content = new JPanel();
content.setBackground(Color.BLACK);
content.setLayout(null);
frame.setContentPane(content);
JPanel Pfriend = Friends();
content.add(Pfriend);
JPanel header = Header();
content.add(header);
JScrollPane contenu = Contenu();
frame.add(contenu);
frame.setUndecorated(true);
frame.setResizable(false);
frame.setVisible(true);
}
private static JPanel Friends() {
int width = 250;
int height = newheight;
int X = newX;
int Y = newY;
JPanel Panel = new JPanel();
Panel.setBounds(X, Y, width, height);
Panel.setBorder(null);
Panel.setBackground(Color.RED);
newwidth -= width;
newX += width;
JButton top = new JButton("BTN");
top.setBackground(Color.YELLOW);
/**/ top.setBounds(X, Y, width, 30);
Panel.add(top /*, BorderLayout.NORTH*/);
return Panel;
}
private static JPanel Header() {
int width = newwidth;
int X = newX;
int Y = newY;
int height = 100;
JPanel Panel = new JPanel();
Panel.setBounds(X, Y, width, height);
Panel.setBorder(null);
Panel.setBackground(Color.GREEN);
newheight -= height;
newY += height;
return Panel;
}
private static JScrollPane Contenu() {
JScrollPane Panel = getHTML.panelfromHTML("C:\\Users\\Utilisateur\\Desktop\\rdm.html");
Panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
JScrollPane ScrollPane = new JScrollPane(Panel);
ScrollPane.setForeground(Color.BLACK);
ScrollPane.setBorder(null);
ScrollPane.setBounds(newX, newY, newwidth, newheight);
ScrollPane.setBackground(Color.BLACK);
ScrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
ScrollPane.getViewport().setViewPosition(new Point(0,0));
return ScrollPane;
}
}
class getHTML {
public static JScrollPane panelfromHTML(String URL) {
try {
File file = new File(URL);
// Créer l'objet File Reader
FileReader fr;
fr = new FileReader(file);
// Créer l'objet BufferedReader
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String line;
while((line = br.readLine()) != null)
{
// ajoute la ligne au buffer
sb.append(line);
}
fr.close();
JScrollPane ScrollPane = HTMLtoPanel(sb.toString());
ScrollPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
return ScrollPane;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
private static JScrollPane HTMLtoPanel(String htmlString) {
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(jEditorPane);
scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
Document doc = kit.createDefaultDocument();
jEditorPane.setDocument(doc);
jEditorPane.setText(htmlString);
}
});
return scrollPane;
}
} |
Partager