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
|
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.URL;
import javax.imageio.*;
import javax.swing.*;
class EditorP extends JEditorPane
{
EditorP(String str1, String str2){super(str1,str2);}
public Dimension getPreferredScrollableViewportSize()
{
return (new Dimension(600,100));
}
/*
public boolean getScrollableTracksViewportHeight()
{
return true;
}
public boolean getScrollableTracksViewportWidth()
{
return true;
}
*/
}
public class ScrolFan extends JPanel
{
BufferedImage img1=null;
JScrollPane scrol1=null;
JEditorPane pan1 = null;
ScrolFan()
{
try {
setLayout(null);
img1 = readImage("maison.jpg");
pan1 = new EditorP("text/html","<html> <body><strong>Ca y est, c'est les vacances. Nathalie et ses parents ont choisi de passer quelques jours à la campagne. Il fait très beau, Nathalie a décidé daller se promener autour de la maison.</font></strong></p></body></html>");
scrol1=new JScrollPane(pan1);
scrol1.setLocation(100,400);
// scrol1.setBounds(200,600,100,100);
add(scrol1);
} catch(Exception ex) {}
}
public Dimension getPreferredSize() {
return new Dimension(1020,700);
}
protected void paintComponent(Graphics g)
{
g.drawImage(img1, 0, 0, getWidth(),getHeight(), this);
}
public BufferedImage readImage(String img) throws IOException
{
URL url = getClass().getResource(img);
if (url == null)
{
IOException ioe= new IOException("bad image file name");
throw ioe;
}
return ImageIO.read(url);
}
public static void main(String[] args) throws IOException {
ScrolFan app = new ScrolFan();
app.setBackground(Color.WHITE);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(app);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setLocation(0,0);
}
} |
Partager