opening a html page from applet

R

rajbala.3399

Hello

This is Raj. I was new to java. And want to open a JSP page from applet
when mouse clicked on a image. But when I tried for it I got only
source code of that web page. Can you please help me.

Thank Q in advance

-Raj.
 
A

Andrew Thompson

...want to open a JSP page from applet
when mouse clicked on a image. But when I tried for it I got only
source code of that web page. Can you please help me.

Possibly - depends largely on you (and how much
you can help yourself).
Can you provide ..
- a URL to the web page with the broken applet
- a link, from that page, to the short, self contained code
being used for the applet.

That should do to get the process started..

Andrew T.
 
R

rajbala.3399

Andrew said:
Possibly - depends largely on you (and how much
you can help yourself).
Can you provide ..
- a URL to the web page with the broken applet
- a link, from that page, to the short, self contained code
being used for the applet.

That should do to get the process started..

Andrew T.



Hi,
Thanks for reply and giving confiedence to me.
I tried by using url to get web page like below.

public class URL {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}
}

But it get only html code nothing else beyond that. But that is not my
requirement.
I want to get a JSP page when i click on applet. I want sugesstion for
open a new window when ever i click on aplet.

Thanx.

Raju
 
A

Andrew Thompson

Where is the web page with the applet?
....

Umm.. Ok, good attempt, but since you were discussing
JSP's and applets, it is a surprise to see a 'main(String[] args)',
which applies to neither. But I'll forge on..

(otherwise it was a nice, short, descriptive example.)
public class URL {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
.....
Do you have Yahoo's permission to access their
pages programmatically?
...But it get only html code

What was it you were expecting?
Try the same URL with this code..
...nothing else beyond that. But that is not my
requirement.
I want to get a JSP page when i click on applet.

You do realise that JSP becomes HTML once
served, right? If Yahoo uses JSP, and you request
an address from them, you will get HTML.
... I want sugesstion for
open a new window when ever i click on aplet.

applet.getAppletContext().showDocument(url, "_blank");

Note their are major issues with that approach,
and it sounds quite unlike what you have so far
attempted, but I still do not quite understand the
complete requirement.

If you want to access information in other pages
from within Java - the showDocument will not work.
If you simply want to show the end user a web
page - it will work well for some (though
'not at all' for others).

Andrew T.
 
R

rajbala.3399

Andrew said:
Where is the web page with the applet?
...

Umm.. Ok, good attempt, but since you were discussing
JSP's and applets, it is a surprise to see a 'main(String[] args)',
which applies to neither. But I'll forge on..

(otherwise it was a nice, short, descriptive example.)
public class URL {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
....
Do you have Yahoo's permission to access their
pages programmatically?
...But it get only html code

What was it you were expecting?
Try the same URL with this code..
...nothing else beyond that. But that is not my
requirement.
I want to get a JSP page when i click on applet.

You do realise that JSP becomes HTML once
served, right? If Yahoo uses JSP, and you request
an address from them, you will get HTML.
... I want sugesstion for
open a new window when ever i click on aplet.

applet.getAppletContext().showDocument(url, "_blank");

Note their are major issues with that approach,
and it sounds quite unlike what you have so far
attempted, but I still do not quite understand the
complete requirement.

If you want to access information in other pages
from within Java - the showDocument will not work.
If you simply want to show the end user a web
page - it will work well for some (though
'not at all' for others).

Andrew T.

hi,
thankq again.I had has per your sugesstion.I got the run time
error. Like

Exception in thread "main" java.io.IOException: Server returned HTTP
response code: 403 for URL:
http://groups.google.com/group/comp.lang.java.programmer/msg/d4a724ad...
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:814)

but when tried for "URL yahoo = new URL("http://www.gmail.com/");".It
doesn't give any error.but same.. it give html tags only.

ok I want to exaplain about my task.I had creted tree
strcture in jsp and i had performed some fuction that. And now i
created a Applet program which has function like copy of images on the
applet. When i click on the image of the applet i want to get my jsp
tree structure program and i also want to perform same function what
ever wroten in JSP. Only opening pages of jsp is not my requirement i
also want to perform some action on it.

-Raju
 
A

Andrew Thompson

....
thankq again.I had has per your sugesstion.

No, I suggested something different!
...I got the run time error. Like

Exception in thread "main" java.io.IOException: Server returned HTTP
response code: 403 for URL:
http://groups.google.com/group/comp.lang.java.programmer/msg/d4a724ad...

(sighs) I'll try again..

(or - the Java code *shown* on this usenet thread)
....
ok I want to exaplain about my task.I had creted tree
strcture in jsp and i had performed some fuction that. And now i
created a Applet program which has function like copy of images on the
applet. When i click on the image of the applet i want to get my jsp
tree structure program and i also want to perform same function what
ever wroten in JSP. Only opening pages of jsp is not my requirement i
also want to perform some action on it.

It sounds like this project is attempting to 'screen scrape',
which ads up to stealing information from other web sites.

Stop that! If there is a worthy link, put a link on the
web page or open the page in a new window.

Andrew T.
 
R

rajbala.3399

Andrew said:
No, I suggested something different!


(sighs) I'll try again..


(or - the Java code *shown* on this usenet thread)


It sounds like this project is attempting to 'screen scrape',
which ads up to stealing information from other web sites.

Stop that! If there is a worthy link, put a link on the
web page or open the page in a new window.

Andrew T.

Hi,
Here is my code in which we able to get an image anywhere on
applet by using mouse click and someother functions.Here we got a
JoptionPane by giving rightclick.But instead of that we need to call a
jsp tree structure in new window by giving right click. I hope you will
help me in next mail by giving appropriate code for getting jsp tree
structure .

Thanks for ur help.


Code:


package netbeanprojects;

import java.applet.*;
import java.awt.event.*;
import java.awt.event.InputEvent;
import java.net.MalformedURLException;
import java.net.URL;
import java.awt.*;
import java.awt.Image;
import javax.swing.*;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.ImageIcon;
/*
<applet code="ImageDemo" width="1100" height="400">
</applet> */
public class ImageDemo extends Applet implements MouseListener,
ActionListener{
int x = 100,y = 100;
Image img,image1,image2,OSC;
JButton BS,SS,GTW,rou;
Graphics OSG;

public void init()
{

setLayout(new GridLayout(0, 8));
setBackground(Color.white);

Panel pan1= new Panel();
pan1.setLayout(new GridLayout(5, 1, 0, 80));
ImageIcon image1 = new
ImageIcon("/usr/share/pixmaps/gnome-home.png");
BS = new JButton(image1);

ImageIcon image2 = new
ImageIcon("/usr/share/icons/Bluecurve/48x48/apps/kandy.png");
SS = new JButton(image2);

JButton mk = new JButton("Link");

ImageIcon image3 = new
ImageIcon("/usr/share/icons/Bluecurve/48x48/apps/panel-logout.png");
GTW = new JButton(image3);
ImageIcon image4 = new
ImageIcon("/usr/share/icons/Bluecurve/48x48/apps/sawfish-workspaces.png");
rou = new JButton(image4);
pan1.setBackground(Color.GRAY);
try {
img = getImage(new
URL("file:///usr/share/pixmaps/gnome-mini-commander.png"));
} catch (Exception ex) {
ex.printStackTrace();
}

BS.addActionListener(this);

SS.addActionListener(this);

mk.addActionListener(this);
GTW.addActionListener(this);
rou.addActionListener(this);
addMouseListener(this);
pan1.add(BS);
pan1.add(SS);
pan1.add(mk);
pan1.add(rou);
pan1.add(GTW);
add(pan1);

}

boolean Link = false;

public void actionPerformed(ActionEvent e){
Link = false;
String s = e.getActionCommand();
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
try {

if(e.getSource() == BS)
{
img = getImage(new
URL("file:///usr/share/pixmaps/gnome-home.png"));

}
else if(e.getSource() == SS){
img = getImage(new
URL("file:///usr/share/icons/Bluecurve/48x48/apps/kandy.png"));
}
else if(e.getSource() == GTW) {
img = getImage(new
URL("file:///usr/share/icons/Bluecurve/48x48/apps/panel-logout.png"));

}
else if(e.getSource() == rou) {
img = getImage(new
URL("file:///usr/share/icons/Bluecurve/48x48/apps/sawfish-workspaces.png"));

}
else if(s.equals("Link"))
{
Link = true;
OSC = createImage(getSize().width,getSize().height);
OSG = OSC.getGraphics();
}
} catch (Exception ex) {
// ex.printStackTrace();
System.out.print(ex);
}


}

int prevDragX; // During dragging, these record the x and y
coordinates of the
int prevDragY; // previous position of the mouse.

public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mousePressed(MouseEvent e)
{
int modifiers = e.getModifiers();
if((modifiers & InputEvent.BUTTON3_MASK) ==
InputEvent.BUTTON3_MASK)
{
String response = JOptionPane.showInputDialog(null + "Type
your name and click a button.");

}
if(Link)
{

prevDragX = e.getX();
prevDragY = e.getY();
}
}
public void mouseReleased(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(Link){
Graphics g = getGraphics();
g.drawLine(prevDragX,prevDragY,x,y);
g.dispose();

}

setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}
public void mouseClicked(MouseEvent e)
{
x = e.getX();
y = e.getY();
System.out.print(x+""+y);
repaint();
}
public void update(Graphics g){
paint(g);
}

public void paint(Graphics g){
g.drawImage(img,x,y,this);
img = null;
}
}


I had tried url and showDocument() function it.But i failed to get my
treestructure which is either it html or jsp file. Please help me for
getting my requirement by giving code.

-Raju
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,098
Members
48,773
Latest member
Kaybee

Latest Threads

Top