然后我们将该对话框于与刚才的天气预报菜单连接找到SampleAction的run函数,如下所示:
public void run(IAction action) {
MessageDialog.openInformation(
window.getShell(),
"Myplugin Plug-in",
"Hello, Eclipse world");
}
替换成如下代码
public void run(IAction action)
{
WeatherDialog wd=new WeatherDialog();
wd.setSize(400, 335);
wd.show();
}
此时,点击菜单运行,我们的对话框看起来象这个样子,在此基础上我们还要在上面增加天气预报信息
2.3增加天气预报功能
下面的部分是重点,我们将使用具有解析Html功能的Swing组件JEditPane,来获取网络上的现成的天气预报信息,根据上图,从 VisualEditor的面板中Swing Components组点击JEditPane,加入到对话框中。并修改对话框代码使得最终的代码如下:
/*
* Created on 2004-9-23
* */
package myplugin;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
/**
* <p>Title: WatherDialog</p>
* <p>Description: 这个是对话框类,用于显示指定城市的当天的天气预报</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company:UF SOFT</p>
* @author 赵勇
* @version 1.0
*/
public class WatherDialog extends JDialog
{
String city="北京";
private JEditorPane jEditorPane = null;
/**
* This method initializes
* /
public WatherDialog(String city)
{
super();
this.city=city;
initialize();
}
/**
* This method initializes this
* @return void
*/
private void initialize()
{
this.setContentPane(getJEditorPane());
try
{
//构建URL对象






