建議可以用第三方,你參考下spire.doc for java的超鏈接設(shè)置方法,代碼方案:Java 添加超鏈接到Word文檔,包括了給文字添加鏈接,給圖片添加鏈接,添加網(wǎng)頁鏈接、郵箱鏈接、文檔鏈接不同類型的鏈接。
赤坎ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信: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("一個(gè)超鏈接實(shí)現(xiàn)的例子");
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.須為有模式對(duì)話框
//2。要能在母窗體的中央彈出==未實(shí)現(xiàn)
//部分代碼可能有更好的實(shí)現(xiàn)....總之是要能加入那個(gè)自定義的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");
如果是連接自己項(xiàng)目中的,請注意相對(duì)路徑的寫法。建議加上context path.
標(biāo)題名稱:java代碼中加入鏈接,添加鏈接代碼
網(wǎng)站URL:http://chinadenli.net/article30/hohhpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、企業(yè)建站、動(dòng)態(tài)網(wǎng)站、微信公眾號(hào)、網(wǎng)站策劃、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)