急死了,HyperlinkEvent 事件不能触发

tangxiao890923 2009-11-29 12:13:26

/*
* News.java
*
* Created on __DATE__, __TIME__
*/

package test;

import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import com.sun.syndication.io.FeedException;

import bean.Center;
import bean.Close;
import bean.Linknet;
import bean.MyJButton;
import bean.MyJPanel;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

/**
*
* @author __USER__
*/
public class News extends javax.swing.JFrame implements HyperlinkListener {

/**
*
*/
private static final long serialVersionUID = 1L;

/** Creates new form News */
public News() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setResizable(false);
// this.setUndecorated(true);
// this.getRootPane().setWindowDecorationStyle(
// JRootPane.INFORMATION_DIALOG);
Image image = this.getToolkit().createImage(
this.getClass().getResource("image/liaotian.jpg"));
this.setIconImage(image);
jPanel1 = new MyJPanel();
((MyJPanel) jPanel1).setImageFilename("image/loginingback.jpg");

close = new MyJButton();
((MyJButton) close).setImageFilename("image/close3.jpg");
Minimize = new MyJButton();
((MyJButton) Minimize).setImageFilename("image/minimize1.jpg");
jTabbedPane1 = new javax.swing.JTabbedPane();
jScrollPane1 = new javax.swing.JScrollPane();
news = new javax.swing.JEditorPane("text/html","");
jScrollPane2 = new javax.swing.JScrollPane();
Military = new javax.swing.JEditorPane("text/html","");
jScrollPane3 = new javax.swing.JScrollPane();
fun = new javax.swing.JEditorPane("text/html","");
jScrollPane4 = new javax.swing.JScrollPane();
car = new javax.swing.JEditorPane("text/html","");
jScrollPane5 = new javax.swing.JScrollPane();
games = new javax.swing.JEditorPane("text/html","");
this.news.addHyperlinkListener(this);
this.Military.addHyperlinkListener(this);
this.fun.addHyperlinkListener(this);
this.car.addHyperlinkListener(this);
this.games.addHyperlinkListener(this);

setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

jScrollPane1.setViewportView(news);

jTabbedPane1.addTab("国际", jScrollPane1);

jScrollPane2.setViewportView(Military);

jTabbedPane1.addTab("体育", jScrollPane2);

jScrollPane3.setViewportView(fun);

jTabbedPane1.addTab("科技", jScrollPane3);

jScrollPane4.setViewportView(car);

jTabbedPane1.addTab("社会", jScrollPane4);

jScrollPane5.setViewportView(games);

jTabbedPane1.addTab("播客", jScrollPane5);

close.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeActionPerformed(evt);
}
});

Minimize.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MinimizeActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jTabbedPane1,
javax.swing.GroupLayout.DEFAULT_SIZE,
506,
Short.MAX_VALUE)
.addContainerGap())
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout
.createSequentialGroup()
.addComponent(
Minimize)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
close)))));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel1Layout.createSequentialGroup().addGroup(
jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false).addComponent(close,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE).addComponent(Minimize,
javax.swing.GroupLayout.DEFAULT_SIZE, 17,
Short.MAX_VALUE)).addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTabbedPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 308,
Short.MAX_VALUE).addContainerGap()));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
//this.setLocation(Center.createRight(250)[0],Center.createRight(250)[1]
// );
this.setLocation(Center.createCenter(this.getSize().width,
this.getSize().height).getX(), Center.createCenter(
this.getSize().width, this.getSize().height).getY());
pack();
this.setVisible(true);
try {
this.write1();
} catch (Exception ee) {

}
}// </editor-fold>

// GEN-END:initComponents

private void MinimizeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setExtendedState(MainFrame.ICONIFIED);
}

private void closeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
Close.close();
}

...全文
187 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
amdgaming 2009-11-29
  • 打赏
  • 举报
回复
你写的有问题啊。,

稍等
tangxiao890923 2009-11-29
  • 打赏
  • 举报
回复
为什么我点超链接
而不触发HyperlinkEvent事件
tangxiao890923 2009-11-29
  • 打赏
  • 举报
回复

/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new News();
}
});

}

public void write1() throws IllegalArgumentException, FeedException {
java.lang.StringBuffer news = new java.lang.StringBuffer(),news1 = new java.lang.StringBuffer(),
news2 = new java.lang.StringBuffer(),
news3 = new java.lang.StringBuffer(),
news4 = new java.lang.StringBuffer();
java.util.Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "mywebcache.com");
systemSettings.put("http.proxyPort", "8080");
System.setProperties(systemSettings);
// String urlStr = "http://172.16.158.16/news.xml";
String urlStr = "http://rss.sina.com.cn/news/marquee/ddt.xml";
// String urlStr = "http://www.hnyyzx.com/rssFeed.aspx";
java.net.URLConnection feedUrl;
try {
feedUrl = new java.net.URL(urlStr).openConnection();
feedUrl.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
com.sun.syndication.io.SyndFeedInput input = new com.sun.syndication.io.SyndFeedInput();
com.sun.syndication.feed.synd.SyndFeed feed = input
.build(new com.sun.syndication.io.XmlReader(feedUrl));
List<?> list = feed.getEntries();
for (int i = 0; i < list.size(); i++) {
com.sun.syndication.feed.synd.SyndEntry entry = (com.sun.syndication.feed.synd.SyndEntry) list
.get(i);
if(entry.getTitle().trim().startsWith("[国际]"))
news.append(" "+"<a href=\""+entry.getLink().trim()+"\">"+entry.getTitle().trim() +"</a> <br/>");
else if(entry.getTitle().trim().startsWith("[体育]"))
news1.append(" "+"<a href=\""+entry.getLink().trim()+"\">"+entry.getTitle().trim() +"</a> <br/>");
else if(entry.getTitle().trim().startsWith("[科技]"))
news2.append(" "+"<a href=\""+entry.getLink().trim()+"\">"+entry.getTitle().trim() +"</a> <br/>");
else if(entry.getTitle().trim().startsWith("[社会]"))
news3.append(" "+"<a href=\""+entry.getLink().trim()+"\">"+entry.getTitle().trim() +"</a> <br/>");
else //if(entry.getTitle().startsWith("[播客]"))
news4.append(" "+"<a href=\""+entry.getLink().trim()+"\">"+entry.getTitle().trim() +"</a> <br/>");
}
this.news.setText(news.toString());
this.news.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){

}

});
this.Military.setText(news1.toString());
this.fun.setText(news2.toString());
this.car.setText(news3.toString());
this.games.setText(news4.toString());


} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
URL url = hyperlinkEvent.getURL();
System.out.println(url.toString());
if (type == HyperlinkEvent.EventType.ACTIVATED) {
Linknet.open(url.toString().trim());
}

}


// GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JEditorPane Military;
private javax.swing.JButton Minimize;
private javax.swing.JEditorPane car;
private javax.swing.JButton close;
private javax.swing.JEditorPane fun;
private javax.swing.JEditorPane games;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JEditorPane news;
// End of variables declaration//GEN-END:variables

}
tangxin123 2009-11-29
  • 打赏
  • 举报
回复
LZ 没加setEditable(false);
tangxiao890923 2009-11-29
  • 打赏
  • 举报
回复
LZ 没加setEditable(false);
tangxiao890923 2009-11-29
  • 打赏
  • 举报
回复
LZ 没加setEditable(false);
tangxiao890923 2009-11-29
  • 打赏
  • 举报
回复
呵呵 自己解决了
问题是没加setEditable(false);
代码下载链接: https://pan.quark.cn/s/a8fbca3925b4 《鸿蒙OS开发环境构建》指南系统性地阐述了配置和筹备鸿蒙OS开发所需的各种工具和条件的具体方法。鸿蒙OS,亦称HarmonyOS,是由华为研发的一款面向全场景的分布式操作系统,其目标是提供跨平台、多设备间无缝协作的使用体验。本指南涉及了从Linux服务器到Windows工作站的完整开发流程。指南中提及了MobaXterm,这是一款用于连接Linux源码服务器的软件,使得开发人员能够在Windows环境中远程访问Linux服务器。同时,HiTool作为烧录工具,用于将编译后的系统镜像写入开发板。IPOP.EXE则是一款串口终端软件,用于执行串行通信和调试任务。Embedded Studio用于开发设备驱动程序,而DevEco Studio是华为提供的图形化应用程序开发平台,支持C/C++语言,拥有代码编辑、编译、烧录和调试功能,被视为OpenHarmony智能设备开发者的首选集成开发环境。在硬件配置方面,指南列出了必需的设备,包括Linux服务器(推荐Ubuntu 16.04及以上版本),Windows工作台(兼容XP/7/10),以及Hi3518EV300 IoT Camera单板。开发期间,Windows工作台通过USB线与单板相连接,以实现数据传输。此外,为了开展开发工作,还需要安装putty、IPOP、tftp服务器等辅助软件,以及HiTool用于烧录操作。在软件系统要求方面,Linux服务器需要安装bash、Python3.7+、gn、ninja、LLVM等构建工具,这些工具对于生成和执行编译脚本具有关键作用。在Windows工作台上,建议采用Visual Studi...

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧