A voir également:
- Applet Java: afficher une image depuis un DD
- Frédéric cherche à faire le buzz sur les réseaux sociaux. il a ajouté une image de manchots sur une image de plage. retrouvez l'image originale de la plage. que cachent les manchots ? ✓ - Forum Windows
- Ce programme est écrit en python. il construit un mot secret dans une variable mais il ne l'affiche pas. modifiez-le pour qu'il affiche le mot secret. exécutez-le. quel est ce mot secret ? ✓ - Forum Python
- Recherche par image - Guide
- Image iso - Guide
- Jeux java itel ✓ - Forum Jeux vidéo
2 réponses
KX
Messages postés
16668
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
17 mars 2023
3 004
26 mars 2012 à 13:28
26 mars 2012 à 13:28
Tu ne peux pas toucher aux fichiers à moins que tu ne disposes d'un certificat de sécurité (ce dont je doute...)
What Applets Can and Cannot Do :
[Unsigned applets] cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.
What Applets Can and Cannot Do :
[Unsigned applets] cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.
j'ai finalement finis par trouver ce code qui fonctionne parfaitement pour afficher une image depuis le disque (avec le jar évidemment signé)... maintenant je dois récupérer cette image et faire un "drag n drop" pour l'envoyer dans un champ html...
Si vous avez une idée je suis toujours preneur ;)
Si vous avez une idée je suis toujours preneur ;)
<html>
<head>
</head>
<body bgcolor="#ffffff">
<applet codebase="./" code="test.class" archive="test2.jar" name="myApplet" width="500" height="500"></applet>
<!-- Fonction de test de récupération de données de l'applet -->
<a href="javascript:alert(document.myApplet.getString());">chemin du répertoire</a>
</body>
</html>
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.net.URLDecoder;
public class test extends Applet {
String sFileName;
ImageIcon icon;
Image img;
String sjsFileName;
String sjsFilePath;
public test() {
Panel p = new Panel();
Font f;
String osname = System.getProperty("os.name","");
if (!osname.startsWith("Windows")) {
f = new Font("Arial",Font.BOLD,10);
} else {
f = new Font("Verdana",Font.BOLD,12);
}
p.setFont(f);
p.add(new Button("Parcourir"));
p.setBackground(new Color(255, 255, 255));
add("North",p);
}
public boolean action(Event evt, Object arg) {
if (arg.equals("Parcourir")) {
System.out.println("OPEN CLICKED");
// cette méthode fonctionne
Frame parent = new Frame();
FileDialog fd = new FileDialog(parent, "Répertoire de l'image:", FileDialog.LOAD);
fd.show();
String selectedItem = fd.getFile();
if (selectedItem == null) {
// no file selected
} else {
// read the file
//System.out.println("reading file " + fd.getDirectory() + File.separator + fd.getFile() );
sFileName = fd.getDirectory() + File.separator + fd.getFile();
displayFile(sFileName);
}
} else return false;
return true;
}
public void paint(Graphics g)
{
int width, height;
if (img!=null) {
width = img.getWidth(this);
height = img.getHeight(this);
if (width < height) {
if (height <= 500) {
g.drawImage(img, 0, 40, this);
}else {
double ratio = 500 / (double) height;
double temp2 = width*ratio;
int temp = (int) temp2;
g.drawImage(img, 0, 40, temp, 500, this);
}
} else {
if (width <= 500) {
g.drawImage(img, 0, 40, this);
}else {
double ratio = 500 / (double) width;
double temp2 = height*ratio;
int temp = (int) temp2;
g.drawImage(img, 0, 40, 500, temp, this);
}
}
}
}
public void displayFile (String sFileName){
System.out.println("file name : " + sFileName);
try {
String slocalFileName = URLDecoder.decode(sFileName, "UTF-8");
System.out.println("slocalFileName : " + slocalFileName);
icon = new ImageIcon(slocalFileName);
img = icon.getImage();
repaint();
}
catch (Exception e)
{
System.out.println("erreur " + e.toString());
}
}
// quand j'appelle cette fonction directement de la page html, ça génère l'exception
public void displayFile2 (String sPathName){
System.out.println("path name : " + sPathName);
try {
String slocalFileName = URLDecoder.decode(sPathName, "UTF-8");
System.out.println("slocalFileName : " + slocalFileName);
icon = new ImageIcon(slocalFileName);
img = icon.getImage();
repaint();
}
catch (Exception e)
{
System.out.println("erreur " + e.toString());
}
}
public String getString() {
return sFileName;
}
public void setFileName(String s) throws Exception
{
try {
sjsFileName = new String( s );
System.out.println("sjsFileName : " + sjsFileName);
return ;
}
catch (Exception e)
{
System.out.println("erreur " + e.toString());
}
}
public void setFilePath(String s) throws Exception
{
try {
sjsFilePath = new String( s );
System.out.println("sjsFilePath (encodé): " + sjsFilePath);
System.out.println("sjsFilePath (décodé): " + URLDecoder.decode(sjsFilePath, "UTF-8"));
sjsFilePath = new String( URLDecoder.decode(sjsFilePath, "UTF-8") );
return ;
}
catch (Exception e)
{
System.out.println("erreur " + e.toString());
}
}
}