重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
建议可以用第三方,你参考下spire.doc for java的超链接设置方法,代码方案:Java 添加超链接到Word文档,包括了给文字添加链接,给图片添加链接,添加网页链接、邮箱链接、文档链接不同类型的链接。
赤坎ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class 超链接 extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 107369444274434673L;
JFrame jf = new JFrame("一个超链接实现的例子");
JPanel jp = new JPanel();
JButton butt = new JButton("确定弹出");
MyDialog1 mydialog;
超链接() {
butt.addActionListener(this);
jp.add(butt);
jf.setContentPane(jp);
jf.pack();
jf.setBounds(40, 40, 200, 200);
jf.setVisible(true);
}
public static void main(String[] args) {
new 超链接();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == butt) {
mydialog=new MyDialog1(jf,"提示",true);
mydialog.setVisible(true);
}
}
}
//1.须为有模式对话框
//2。要能在母窗体的中央弹出==未实现
//部分代码可能有更好的实现....总之是要能加入那个自定义的JLabel
class MyDialog1 extends Dialog implements ActionListener{
static final int YES=1,NO=0;
int message=-1;
Button yes,no;
MyDialog1(Frame f,String s,boolean b){
super(f,s,b);
LinkLabel2 label = new LinkLabel2("百度一下,你就知道", "");
yes=new Button("Yes");
yes.addActionListener(this);
no=new Button("No");
no.addActionListener(this);
setLayout(new FlowLayout());
add(label);
add(yes);
add(no);
//setBounds(60,60,100,100);
setSize(350,100);
int winWidth=getBounds().width;//获取窗口的款等于320
int winHeigth=getBounds().height;//获取窗口的款等于350
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = (int)dim.getWidth();//获取屏幕的宽
int screenHeight = (int)dim.getHeight();//获取屏幕的高
setLocation((screenWidth-winWidth)/2, (screenHeight-winHeigth)/2);//定制窗口的位置
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
message=-1;setVisible(false);
}
}
);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==yes){
message=YES;setVisible(false);
}
else if(e.getSource()==no){
message=NO;setVisible(false);
}
}
public int getMessage(){
return message;
}
}
class LinkLabel2 extends JLabel {
private String text, url;
private boolean isSupported;
public LinkLabel2(String text, String url) {
this.text = text;
this.url = url;
try {
this.isSupported = Desktop.isDesktopSupported()
Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
} catch (Exception e) {
this.isSupported = false;
}
setText(false);
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
setText(isSupported);
if (isSupported)
setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
setText(false);
}
public void mouseClicked(MouseEvent e) {
try {
Desktop.getDesktop().browse(
new java.net.URI(LinkLabel2.this.url));
} catch (Exception ex) {
}
}
});
}
private void setText(boolean b) {
if (!b)
setText("htmlfont color=blueu" + text);
else
setText("htmlfont color=redu" + text);
}
}
a href="your target url"Link/a
如果在servlet中:
PrintWriter out = res.getWriter();
out.println("a href='your target url'Link/a");
如果是连接自己项目中的,请注意相对路径的写法。建议加上context path.