你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:杂志经典 / 网络与通信
用Java实现Yahoo天气预报客户端(四)
 

public static class CityItem{

String cname;//城市名称

String ccode;//城市代码

// CityItem内部类构造器

public CityItem(String cname,String ccode)

{this.cname=cname; this.ccode=ccode;}      

//重写toString方法

@Override

public String toString(){return cname;}

}

// YahooWeatherFramePre类构造器

public YahooWeatherFramePre() {

//对标题和logo图片进行初始化

this.setTitle("Yahoo天气预报客户端");

image=new ImageIcon("img/ico.png").getImage();

this.setIconImage(image);        

//对界面中的控件进行摆放

this.setLayout(new FlowLayout(FlowLayout.LEFT,10,6));

jl.setPreferredSize(new Dimension(200,20));

this.add(jl);

jcb.setPreferredSize(new Dimension(150,20));

this.add(jcb);

jb.setPreferredSize(new Dimension(60,20));

this.add(jb);       

//对城市列表初始化

this.initCityList();       

//为“确定”按钮添加监听器

jb.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

    //获取当前选中的城市

CityItem currCI =

(CityItem)jcb.getSelectedItem();

String selectedCityCode = currCI.ccode;

//未来在此处添加创建天气预报信息显示

//窗口的代码……           YahooWeatherFramePre.this.dispose();

} } );

//设置窗体首次出现的大小和位置

Dimension screenSize =

Toolkit.getDefaultToolkit().getScreenSize();

int centerX=screenSize.width/2;//屏幕中央x坐标

int centerY=screenSize.height/2; //屏幕中央y坐标

int w=250;//本窗体宽度

int h=100;//本窗体高度

//设置窗体出现在屏幕中央

this.setBounds(centerX-w/2,centerY-h/2-100,w,h);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setResizable(false);//设置窗体不可修改大小

}

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089