wnstronda 0 Denunciar post Postado Abril 20, 2012 Bom primeiramente gostaria de agradecer a todos por este fórum ( já que não tem muitos por aí )... E venho com meu primeiro post querendo entender um problema que acabei me deparando e não encontrei nada na internet que me ajuda-se! Enfim estou criando um browser para entender melhor sobre Java ( já que estou decidido que é este o caminho que seguirei ); Agora me deparei com um problema talvez pequeno, bom não pra mim né haha Quando mando meu browser acessar uma pagina, ele acessa mas ela fica toda estranha e bugada ( toda esparramada e aparece um pequeno painel de busca no canto, que nem sei de onde surgiu ), e também tenho que colocar o http:// para que a pagina seja encontrada! ( caso contrario da erro ); Bom eis aqui meu codigo ( muito de noob mas to aprendendo do zero, sei muito pouquinho sobre o assunto ainda ) package mindxplorer; import java.awt.event.KeyEvent; /** * * @author Tiago Miguel de Brito dos Santos */ //--------------------------CLASSE PRINCIPAL---------------------------- public class mindx extends javax.swing.JFrame { //------------------------CONSTRUTOR Principal----------------------------- public mindx() { super("MindXplorer"); initComponents(); } //-------------------------------METODOS----------------------------------- /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jTextField1 = new javax.swing.JTextField(); jScrollPane2 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTextField1.setSelectionEnd(7); jTextField1.setSelectionStart(7); jTextField1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { jTextField1KeyPressed(evt); } }); jScrollPane2.setViewportView(jEditorPane1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane2) .addComponent(jTextField1)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE) .addContainerGap()) ); jTextField1.getAccessibleContext().setAccessibleName(""); jTextField1.getAccessibleContext().setAccessibleDescription(""); pack(); }// </editor-fold> private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ENTER) { try { jEditorPane1.setPage(jTextField1.getText()); } catch(Exception e) { jTextField1.setText("Erro: "+e); } } } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(mindx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(mindx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(mindx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(mindx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new mindx().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JEditorPane jEditorPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextField jTextField1; // End of variables declaration } Bom não sei se muda muita coisa mas estou criando com JFrame usando o projeto (visual); Uso o NetBeans Obrigado desde já. Compartilhar este post Link para o post Compartilhar em outros sites
hargon 64 Denunciar post Postado Abril 20, 2012 Olá wnstronda, Seja bem vindo ao Fórum. Bom não sei se muda muita coisa mas estou criando com JFrame usando o projeto (visual); Se você quer seguir Java, aconselho utilizar o Eclipse para aprender, pois começar arrastando componentes no Netbeans pode ser ruim para você futuramente e para as pessoas que estão lhe ajudando agora, pois fica um código muito sujo e difícil de interpretar. ---------- Sobre o erro que ocorreu, lhe adianto que no Java não existe um componente padrão que entenda bem o HTML e muito menos Javascript. O JEditorPane aceita somente tags simples do HTML, por este motivo a sua página deu erro. Para fazer o que quer, você terá que pesquisar bastante, buscar por alguma API. Sobre o http:// automático, isso é até simples perto do problema acima, basta você validar o campo endereço e verificar se foi informado https, http, ftp, etc, caso não tenha nada iniciando, complete automaticamente com http://. Segue alguns links que encontrei há alguns meses quando pesquisei sobre este assunto, talvez lhe ajude. Desenvolvendo um Web browser em Java http://www.devmedia.com.br/criando-um-browser-utilizando-swing/1666 API: JRex - The Java Browser Component http://jrex.mozdev.org/ FAQ How do I display a Web page in SWT? http://wiki.eclipse.org/FAQ_How_do_I_display_a_Web_page_in_SWT%3F Creating a web browser in Java http://forums.devx.com/showthread.php?threadid=149187 Compartilhar este post Link para o post Compartilhar em outros sites