当前位置: 技术问答>java相关
如何实现鼠标点击applet打开指定的URL
来源: 互联网 发布时间:2015-01-27
本文导语: 有人帮我么? | import java.applet.*; import java.util.*; import java.net.*; import javax.swing.*; import javax.swing.event.*; public class Bookmark extends JApplet implements ListSelectionListener { public void init() ...
有人帮我么?
|
import java.applet.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
public class Bookmark extends JApplet
implements ListSelectionListener
{ public void init()
{ int i = 1;
String s;
Vector v = new Vector();
while ((s = getParameter("link_" + i)) != null)
{ v.add(s);
i++;
}
JList links = new JList(v);
Container contentPane = getContentPane();
contentPane.add(links);
links.addListSelectionListener(this);
}
public void valueChanged(ListSelectionEvent evt)
{ if (evt.getValueIsAdjusting()) return;
JList source = (JList)evt.getSource();
String arg = (String)source.getSelectedValue();
try
{ AppletContext context = getAppletContext();
URL u = new URL(/tech-qa-java/arg/index.html);
context.showDocument(u, "right");
} catch(Exception e)
{ showStatus("Error " + e);
}
}
}
基本上差不多,你改一改!
import java.util.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
public class Bookmark extends JApplet
implements ListSelectionListener
{ public void init()
{ int i = 1;
String s;
Vector v = new Vector();
while ((s = getParameter("link_" + i)) != null)
{ v.add(s);
i++;
}
JList links = new JList(v);
Container contentPane = getContentPane();
contentPane.add(links);
links.addListSelectionListener(this);
}
public void valueChanged(ListSelectionEvent evt)
{ if (evt.getValueIsAdjusting()) return;
JList source = (JList)evt.getSource();
String arg = (String)source.getSelectedValue();
try
{ AppletContext context = getAppletContext();
URL u = new URL(/tech-qa-java/arg/index.html);
context.showDocument(u, "right");
} catch(Exception e)
{ showStatus("Error " + e);
}
}
}
基本上差不多,你改一改!
|
left.html
|
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.net.*;
import java.applet.AppletContext;
public class MyApp extends Applet
{
public void init(){
Button b = new Button("www.yeah.net");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
URL url = new URL("http://www.javasoft.com/index.html");
System.out.println("http://www.javasoft.com/index.html");
getAppletContext().showDocument(url);
}
catch(MalformedURLException murl){
System.out.println("bad url !");
}
}
});
add(b);
}
}
import java.awt.event.*;
import java.applet.Applet;
import java.net.*;
import java.applet.AppletContext;
public class MyApp extends Applet
{
public void init(){
Button b = new Button("www.yeah.net");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
URL url = new URL("http://www.javasoft.com/index.html");
System.out.println("http://www.javasoft.com/index.html");
getAppletContext().showDocument(url);
}
catch(MalformedURLException murl){
System.out.println("bad url !");
}
}
});
add(b);
}
}