Applet Java et url

dimitryous Messages postés 7 Date d'inscription mardi 13 mars 2007 Statut Membre Dernière intervention 13 mai 2010 - 5 avril 2007 à 23:38
dimitryous Messages postés 7 Date d'inscription mardi 13 mars 2007 Statut Membre Dernière intervention 13 mai 2010 - 6 avril 2007 à 11:11
Je cherche un applet capable d'aller récupérer dans une textbox le résultat (une ligne) d'une url du genre "http/www.monsite.com/questions.php?valeur=1".

Il faut que je puisse afficher le résultat après avoir appuyé sur un bouton ou bien modifié l'url se trouvant dans une zone de saisie.

Je vous remercie d'avance.

4 réponses

gmi19oj19 Messages postés 545 Date d'inscription lundi 10 mai 2004 Statut Membre Dernière intervention 28 septembre 2011 2
6 avril 2007 à 09:38
Salut,

S'il s'agit d'une textbox de la pag HTML, j'ai peur que ce soit impossible. S'il s'agit de la barre d'adresse de nuavigateur, tu peux y arriver en bidouillant avec JNI mais j'ai peur que ça ne fonctionne pas bien en applet...

Quoi qu'il en soit, bon courage^^

gmi19oj19
0
dimitryous Messages postés 7 Date d'inscription mardi 13 mars 2007 Statut Membre Dernière intervention 13 mai 2010
6 avril 2007 à 11:01
Voilà ce que je suis arrivé à faire :

import java.applet.AppletContext;
import javax.swing.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;

public class ShowDocument extends JApplet
implements ActionListener {
the_URLWindow the_URLWindow;

public void init() {
//Execute a job on the event-dispatching thread:
//creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
}

private void createGUI() {
JButton button = new JButton("Bring up the_URL window");
button.addActionListener(this);
add(button);

JFrame.setDefaultLookAndFeelDecorated(true);
the_URLWindow = new the_URLWindow(getAppletContext());
the_URLWindow.pack();
}

public void destroy() {
//Execute a job on the event-dispatching thread:
//creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
destroyGUI();
}
});
} catch (Exception e) { }
}

private void destroyGUI() {
the_URLWindow.setVisible(false);
the_URLWindow = null;
}

public void actionPerformed(ActionEvent event) {
the_URLWindow.setVisible(true);
}
}

class the_URLWindow extends JFrame
implements ActionListener {
JTextField the_URL_Field;
JComboBox choice;
AppletContext appletContext;

public the_URLWindow(AppletContext appletContext) {
super("Show a Document!");
this.appletContext = appletContext;

JPanel contentPane = new JPanel(new GridBagLayout());
setContentPane(contentPane);
contentPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;

JLabel label1 = new JLabel("the_URL of document to show: ",
JLabel.TRAILING);
add(label1, c);

the_URL_Field = new JTextField("http://fr.finance.yahoo.com/d/quotes.txt?m=PA&f=sl1d1t1c1ohgv&e=.csv&s=AF.PA&s=LVMH.PA", 20);
label1.setLabelFor(the_URL_Field);
the_URL_Field.addActionListener(this);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
add(the_URL_Field, c);

JLabel label2 = new JLabel("Window/frame to show it in: ",
JLabel.TRAILING);
c.gridwidth = 1;
c.weightx = 0.0;
add(label2, c);

String[] strings = {
"(browser's choice)", //don't specify
"My Personal Window", //a window named "My Personal Window"
"_blank", //a new, unnamed window
"_self",
"_parent",
"_top" //the Frame that contained this applet
};
choice = new JComboBox(strings);
label2.setLabelFor(choice);
c.fill = GridBagConstraints.NONE;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(5,0,0,0);
c.anchor = GridBagConstraints.LINE_START;
add(choice, c);

JTextField box = new JTextField("Results");
//box.setLines(10);
box.setColumns(100);

c.fill = GridBagConstraints.NONE;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(5,100,100,0);
c.anchor = GridBagConstraints.LINE_START;
add(box, c);

JButton button = new JButton("Show document");
button.addActionListener(this);
c.weighty = 1.0;
c.ipadx = 10;
c.ipady = 10;
c.insets = new Insets(10,0,0,0);
c.anchor = GridBagConstraints.PAGE_END;
add(button, c);
}

public void actionPerformed(ActionEvent event) {
String the_URL_String = the_URL_Field.getText();
URL the_URL = null;
try {
the_URL = new URL(the_URL_String);
} catch (MalformedURLException e) {
System.err.println("Malformed URL: " + the_URL_String);
}

if (the_URL != null) {
box.setText(showDocument(the_URL)); // *********************** ici ce la bloque à la compilation ........
/*
URLConnection conn = the_URL.openConnection();
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
*/
/*
if (choice.getSelectedIndex() == 0) {
appletContext.showDocument(the_URL);
} else {
appletContext.showDocument(the_URL,
(String)choice.getSelectedItem());
}
*/

}
}
}
0
dimitryous Messages postés 7 Date d'inscription mardi 13 mars 2007 Statut Membre Dernière intervention 13 mai 2010
6 avril 2007 à 11:07
Avec l'URL que j'ai mis dans mon code je voudrais récupérer dans la JtextBox des infos du style
LVMH.PA;84,28;4/3/2007;17h38;+1,16;83,80;84,58;83,32;1963844
etc...
0
dimitryous Messages postés 7 Date d'inscription mardi 13 mars 2007 Statut Membre Dernière intervention 13 mai 2010
6 avril 2007 à 11:11
Après je vais faire un split(";") sur ce que j'ai récupéré dans la box pour avoir un vecteur et je vais attaquer ma base de données avec pour la mettre à jour.
0
Rejoignez-nous