website in javaprogramm anzeigen?

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/website_in_javaprogramm_anzeigen_101505/page_1 - zur Vollversion wechseln!


psykoman schrieb am 16.12.2003 um 20:45

tag.
hab mal n doofes problem.
und zwar möcht ich in ner java anwendung ne html seite (website) anzeigen... OHNE dass ich nen browser aufmach ;)
hab schon bissl gegooglt aber nix gfunden...

geht das irgendwie ohne allzu großen aufwand bzw sind euch frameworks o. fertige klassen bekannt mit denen sich das realisieren lasst?

danke für eure konstruktiven antworten ;)
mfg
geri


manalishi schrieb am 16.12.2003 um 20:50

das geht relativ einfach, eine fertig-komponente von swing kanns glaub. ist schon eine weile her :)


psykoman schrieb am 16.12.2003 um 21:41

ach ich könnt mich ohrfeigen... auf swing als suchbegriff komm ich net... :bash:
falls noch wer was darüber weis, bidde trotzdem posten ;)
mfg
geri


Eat my shorts schrieb am 17.12.2003 um 12:03

bitsche hab i mal gmacht zeigt html in an frame an

Code: PHP
public class HlpFrame extends JFrame {
	JEditorPane html;

	public HlpFrame (URL url) {
		displayDocument(url, "new Window");
	}

	
	public HlpFrame (URL url, String target) {
		displayDocument(url, target);
	}


	public void displayDocument (URL url, String target) {
				
		try {
			if (url != null) {
				html = new JEditorPane(url);
				html.setEditable(false);
				html.addHyperlinkListener(createHyperLinkListener());
				JScrollPane scroller = new JScrollPane();
				JViewport vp = scroller.getViewport();
				vp.add(html);
				this.setTitle("Exploring " + url.toString());
				this.getContentPane().add(scroller, BorderLayout.CENTER);
				
			}
		} catch (MalformedURLException e) {
			JOptionPane.showMessageDialog(null, url.toString() + " is not a valid URL");
			return;
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "Error occured while opening "
					+ url.toString());
			return;
		}
		this.pack();
				
		this.setSize(800,600);		
		this.show();
	}


	public HyperlinkListener createHyperLinkListener () {
		return  new HyperlinkListener() {

			public void hyperlinkUpdate (HyperlinkEvent e) {
				if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
					if (e instanceof HTMLFrameHyperlinkEvent) {
						((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)e);
					}
					else {
						try {
							html.setPage(e.getURL());
						} catch (IOException ioe) {
							System.out.println("IOE: " + ioe);
						}
					}
				}
			}
		};
	}
noch Fragen?

mfg
bernhard


psykoman schrieb am 17.12.2003 um 15:46

sehr schönes beispiel, danke!

mfg
geri




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025