Oppure

Loading
22/10/12 15:58
giordanomalandra
ho creato un webbrowser in java ora il problema è che navigando su questo browser ho scoperto che viene letto solo il codice html della pagina e non il codice javascript come devo fare per far leggere al mio browser anche il codice javascript ecco il codice GRAZIE 1000
 

 
package browser;






import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;

public class Browser {
        private JFrame frame;
        private JPanel panelTop;
        private JEditorPane editor;
        private JScrollPane scroll;
        private JTextField field;
        private JButton button;
        private URL url;

        public Browser(String titolo) {
                initComponents();

                
                frame.setTitle(ttolo);

             
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              
                frame.setSize(800,600);

              
                frame.add(BorderLayout.NORTH, panelTop);

             
                panelTop.add(field);
                panelTop.add(button);

            
                frame.add(BorderLayout.CENTER, scroll);

                
              
                frame.setVisible(true);
        }

        private void initComponents() {
                
                frame = new JFrame();

               
                panelTop = new JPanel();
                
                
                try {
                        url = new URL("http://www.corrieredellosport.it");
                }
                catch(MalformedURLException mue) {
                        JOptionPane.showMessageDialog(null,mue);
                }
                
            
                try {
                        editor = new JEditorPane(url);
                        editor.setContentType("text/html");
                      
                        
                        editor.setEditable(false);
                }
                catch(IOException ioe) {
                        JOptionPane.showMessageDialog(null,ioe);
                }
                
              
                scroll = new JScrollPane(editor);

              
                field = new JTextField();

              
                
               
                SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                           field.setText(url.toString());
                   }
                });

            
                button = new JButton("VAI");
                
               
                button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                try {
                                        editor.setPage(field.getText());
                                }
                                catch(IOException ioe) {
                                        JOptionPane.showMessageDialog(null, ioe);
                                }
                        }
                });
        }

        public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                                new Browser("Simple web browser");
                        }
                });
        }//end main method.
}
aaa
22/10/12 18:55
LittleHacker
Secondo me è qui il problema:
editor.setContentType("text/html");

tu hai impostato il tipo a text e html, quindi lui non ti leggerà mai il javascript, perchè tu gli hai detto(involontariamente) di ignorarlo!
Io non so aiutarti, però fatti una ricerca su google(consigliatissimo), oppure aspetta una risposta dai più esperti(consigliato, ma se vuoi imparare qualcosa non puoi solo chiedere devi anche cercare, scervellarti!)!

Non per incolparti o umiliarti, ma questo codice l'hai copiato da una guida o altro?

:k:
Ultima modifica effettuata da LittleHacker 22/10/12 19:00
aaa
22/10/12 20:22
tasx
Ciao!

Guarda qui -> stackoverflow.com/questions/4153806/…

ciaociao ;)
aaa