怎么在基于java swing的菜单项中设置超链接??(新手) 在JAVA运行的程序中的一个菜单项上设置超链接。。怎么写?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 final String google = "www.google.cn"; String news = "<html><a href=" + google + ">www.google.cn</a></html>"; JMenuItem jMenuItem = new JMenuItem(news);jMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // 你所要实现的代码 Desktop desktop = Desktop.getDesktop(); //链接到google try { desktop.browse(new URI(google)); } catch (IOException e1) { e1.printStackTrace(); } catch (URISyntaxException e1) { e1.printStackTrace(); } } }); m1.add(jMenuItem); 使用字符流完成java socket编程 实现两个不同的接口时,两个接口时存在同名的方法,如何处理。 想用java模拟不同的IP地址打开网站的工具? 救命!!毕业设计网络五子棋。 JScrollPane滚动窗口方法? 关于字符串中取值的问题? 关于applet对服务器的访问 在NetBeans下连接SVN验证失败 请“john_sheep(彩虹勇士(楼主,没事就把贴子结了吧.)) ”进来接分100 新手上路,请帮忙 今天高兴,Swing做的QQ,散分.给大家看看......... "AWT-EventQueue-0" java.lang.NullPointerException 问题
final String google = "www.google.cn";
String news = "<html><a href=" + google + ">www.google.cn</a></html>";
JMenuItem jMenuItem = new JMenuItem(news);
jMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
// 你所要实现的代码 Desktop desktop = Desktop.getDesktop(); //链接到google
try {
desktop.browse(new URI(google));
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
} }); m1.add(jMenuItem);