Home Discussion Discuss: Java - Opening a url in new window from an applet

  • heyrjh March 28, 2012 at 1:22 PM

    import java.applet.*; import java.awt.*; import java.net.*; import java.awt.event.*; public class testURL_NewWindow extends Applet implements ActionListener{ public void init(){ String link_Text = "google"; Button b = new Button(link_Text); b.addActionListener(this); add(b); } public void actionPerformed(ActionEvent ae){ //get the button label Button source = (Button)ae.getSource(); String link = "http://www."+source.getLabel()+".com"; try { AppletContext a = getAppletContext(); URL url = new URL(link); a.showDocument(url,"_blank"); // a.showDocument(url,"_self"); // _self to open page in same window } catch (MalformedURLException e){ System.out.println(e.getMessage()); } } }

  • better codepradeep August 12, 2012 at 10:45 PM

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class frame1 extends JFrame{ public frame1() { setTitle("pradeep's"); setSize(200,100); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run() { frame1 ex = new frame1(); JButton google = new JButton("Google"); google.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent d) { try { Runtime rTime = Runtime.getRuntime(); String url= "www.google.com"; String browser ="GIVE PATH OF YOUR BROWSER HERE WITH A SPACE AT END ,(EX:"C:/Users/pradeep/AppData/Local/Google/Chrome/Application/chrome.exe ") "; Process pc= rTime.exec(browser + url); pc.waitFor(); } catch(Exception e){ System.out.println(e); }}}); ex.add(google); } }); } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Applet Questions

applet
applet  applet to open new tab not working.here's my code import... { AppletContext a = getAppletContext(); URL url = new URL(link...*; public class NewURL extends Applet implements ActionListener{ public void init 

Java Server Faces Questions

how to focus on the new window opened from JSF ?
how to focus on the new window opened from JSF ?  Hi guys, I have commandLink with action which using javascript to open a new window(window.open()). Problem is, the new window opens at background behind the current window 

Applet Questions

applet servlet communication - Applet
extends Applet{ URL url = null; URLConnection servletConnection = null; public void init() { try{ url = new URL("http://localhost:8080/examples...()); g.drawString("Applet Servlet Communication",50,50); String str = new String(); str 

Java Interview Questions

applet and servelet
applet and servelet  How will you establish the connection between the servelet and an applet?  Hi, From applet you can use the URL class to call the servlet. URL servletURL = new URL( location ); URLConnection 

Applet Questions

Applet - Applet
------------------------"); g.drawString("Demo of Java Applet Window Event Program"); g.drawString("Java... text="Java Version 1.5.0_16Dos Editor ver 1.0"; JFrame aa=new JFrame("Frame2...Applet   Namaste, I want to create a Menu, the menu name is "Display 

JSP-Tutorials

JSP Window. Open
;       JSP Window. Open  is used to open a new window in JSP. The JavaScript function  window.open( ) open a new browser window for the viewer to use. The syntax of this method is : window.open('url 

Java Beginners

How to open a window from a java program (from code)[ (onclick of something text )]
How to open a window from a java program (from code)[ (onclick of something text )]  When I download the code an put it in Eclipse, the applet is run, but on click of the button displayed in the applet, a new window with google 

Java-Tutorials

The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets...; the browser should be Java enabled.To create an applet, we need to define 

Applet Questions

java applet - Applet
java applet  I want to close applet window which is open by another...); close.addActionListener(this); window = new Frame("Window Event Window"); Label l = new Label("Hello World"); window.add(l 

Applet Questions

applet running but no display - Applet
from a client, the page appears with a blank applet part (just whitescreen... strDefault = "Hello! Java Applet."; public void paint(Graphics g) { String...applet running but no display  Hai, Thanks for the post. I have 

Java Tips and Examples

JFrame - Window
Java: JFrame - Window Description The javax.swing.JFrame class is used... in the class's constructor, and create an instance of the window from the main program... methods JFrame w; // This is the natural Java "window". Container c 

Servlet Interview Questions

servlet to applet communication
text field from servlet and display that value in applet? thanks   We... java.applet.*; public class AppletCallingServlet extends Applet{ URL url = null; URLConnection servletConnection = null; public void init() { try{ url = new URL("http 

Applet Questions

servlet code - Applet
from the servlet to applet. Here is the code of 'ServletExample.java... java.applet.*; public class AppletCallingServlet extends Applet{ URL url = null; URLConnection servletConnection = null; public void init() { try{ url = new 

Applet Questions

Core java - Applet
in the window. Please sent me this Applet code. Thank you From : Sunil...); setContentPane(contentPane); window = new JFrame("Window1... with the following html code: Java Applet Demo Thanks 

WebSevices Questions

reload parent window - WebSevices
window and reload parent window. window.opener.location.href="http... a URL as www.mysite.net If user enters a URL as "mysite.net...; Hi In your code you are passing full url, while its not necessary, you 

Applet Questions

Applet issue
Applet issue  Hello, Can there be any problem in writing a file to the temp directory from a url using applet??? If some security problems are there please do post it for me 

Java Tips and Examples

The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets... should be Java enabled.To create an applet, we need to define a class that inherits 

Applet Questions

Applet Error - Applet
Applet Error  Hi... I had an application where i designed an applet to get the database values into the applet when i clicked a line... It works..... then i'm unable to get the values from the local system... Null values 

Java Technology Tutorials

Java file from url
Java file from url In this section, you will learn how to convert url to file. Description of code: We have already told you the conversion of file to url... urlstring = "file:///C:/java/examples/data.txt"; URL u = new URL(urlstring 

Applet Questions

java applet problem - Applet
java applet problem  i was doing a program using java applet. I want... and to exit from the applet respectively.Now i want to display a message when...*; import java.awt.*; public class Calculator extends Applet implements 

Applet Questions

scrollbar - applet - Applet
ScrollbarDemo extends Applet { public void init() { Scrollbar sb = new... for more information. http://www.roseindia.net/java/example/java/applet/ Thanks...); } } (source code taken from: roseindia.net)   Hi friend, I am 

JSP Tutorials

Popup Window using Ajax In JSP
Database" button. New Pop window winopenradio.jsp will open which... = DriverManager.getConnection(url+db,userName,password); String sql = "delete from Employee where... Popup Window using Ajax In JSP   

Applet Questions

Applet to database error - Applet
Applet to database error  Hi... I had an application where i need to connect to the database for the values to display in the applet.... Following... Applet implements MouseListener{ boolean rect1Clicked,rect1Clicked1,mouseEntered 

Java Tools

The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets... should be Java enabled. To create an applet, we need to define a class 

Applet Questions

Write an applet to display scrolling image in an applet window using thread.
Write an applet to display scrolling image in an applet window using thread.  Write an applet to display scrolling image in an applet window using thread 

Swing AWT

Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet 

Swing AWT

The Window Event - Swing AWT
The Window Event  hey plz i need help here... plz modify..." or "no" and proceed as selected from these options.. thank you.. import... extends JFrame implements ActionListener { JButton exit_button = new 

Java Tips and Examples

First Window
Java NotesExample - First Window This is about the simplest GUI...(String[] args) { JFrame window = new JFrame("My First Window... program must look like this. JFrame is the Java class for a "window 

Java Beginners

java how to get domain name from url
java how to get domain name from url  How to get the domain name from a url string? Example program in java for "how to get domain name from url... = new URL(links); String hostName = linkURL.getHost(); Thanks 

General

The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets...,  the browser should be Java enabled. To create an applet, we need to define 

DMCA.com