Como fazer para chamar um site através de um aplicativo?
O procedimento é o mesmo se for através de um Applet?
Obrigado
RenatoBach
Como fazer para chamar um site através de um aplicativo?
O procedimento é o mesmo se for através de um Applet?
Obrigado
RenatoBach
renato, tente isso no seu applet:
try {
Url url = new URL( "http://www.portaljava.com" );
AppletContext appletContext = getAppletContext();
appletContext.showDocument( url );
} catch ( MalformedURLException e ) {
urlException.printStackTrace();
}
Na verdade eu preciso fazer isso através de um aplicativo, utilizando o java web start. É possível?
Obrigado,
RenatoBach
Oi
renatobach, de uma olhada neste exemplo, ele não está sendo usado no java web start, mas é um aplicativo stand-alone
[code]package src;
import java.awt.Container;
import java.awt.Cursor;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.JEditorPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.Document;
/** CLASSE help<br>
------------------------------------<br>
Projeto…: medicSystem<br>
Descrição: Abre a ajuda do sistema em formato HTML
Direitos.: Paulo César Machado Jeveaux (c) 22/08/2003<br>
@autor…: Paulo César Machado Jeveaux<br>
*/
public class help extends JInternalFrame {
public help() {
super("Tópicos de ajuda", true, true, true, true);
setFrameIcon( (Icon)UIManager.get("Tree.openIcon"));
setBounds( 200, 25, 400, 400);
HtmlPane html = new HtmlPane();
setContentPane(html);
}
}
class HtmlPane extends JScrollPane implements HyperlinkListener {
JEditorPane html;
public HtmlPane() {
try {
File f = new File ("src/HelpFiles/toc.htm");
String s = f.getAbsolutePath();
s = "file:"+s;
URL url = new URL(s);
html = new JEditorPane(s);
html.setEditable(false);
html.addHyperlinkListener(this);
JViewport vp = getViewport();
vp.add(html);
} catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
} catch (IOException e) {
System.out.println("IOException: " + e);
}
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
linkActivated(e.getURL());
}
}
protected void linkActivated(URL u) {
Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));
}
class PageLoader implements Runnable {
PageLoader(URL u, Cursor c) {
url = u;
cursor = c;
}
public void run() {
if (url == null) {
html.setCursor(cursor);
Container parent = html.getParent();
parent.repaint();
} else {
Document doc = html.getDocument();
try {
html.setPage(url);
} catch (IOException ioe) {
html.setDocument(doc);
getToolkit().beep();
} finally {
url = null;
SwingUtilities.invokeLater(this);
}
}
}
URL url;
Cursor cursor;
}
}[/code]
A única coisa é que eu uso um arquivo HTML remoto, mas vc pode mudar a linha “URL url = new URL(s);” por “URL url = new URL(“http://www.algumacoisa.com.br”);”
T+