⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 report.java

📁 天气预报 可以查询各个省市的天气情况
💻 JAVA
字号:
/*
 * Report.java
 *
 * Created on 2007年2月27日, 下午7:25
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.luckme;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author hanfeng
 */
public class Report extends JFrame{
    
    private Weather weather;
    private JLabel jlabel;
    private JTextField jtextfield;
    private JButton jbutton;
    private String [] array;
    private Resources jp1,jp2,jp3;
    private JMenuBar jmb;
    private JMenu jm;
    private JMenuItem jmi;
    /** Creates a new instance of Report */
    public Report(String str) {
        super(str);
        setSize(300,300);
        setResizable(false);
        weather =new Weather();
        jmb=new JMenuBar();
        jm=new JMenu("说明");
        jmi=new JMenuItem("说明");
        jmi.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                JOptionPane.showMessageDialog(null, "本程序资源来源于问天网,特此感谢", "本程序说明", JOptionPane.QUESTION_MESSAGE);
            }
        });
        jmb.add(jm);
        jm.add(jmi);
        setJMenuBar(jmb);
        array=weather.getResources();
        jlabel =new JLabel("查询的城市:");
        jtextfield =new JTextField("哈尔滨",10);
        jbutton =new JButton("查询");
        jbutton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent event){
               String s=jtextfield.getText();
               inputCity(s);
               array=weather.getResources();
               jp1.reDisplay(0);
               jp2.reDisplay(4);
               jp3.reDisplay(8);
           } 
        });
        JPanel searchpanel=new JPanel();
        searchpanel.add(jlabel);
        searchpanel.add(jtextfield);
        searchpanel.add(jbutton);        
        add(searchpanel,BorderLayout.NORTH);
        JPanel main=new JPanel();
        main.setLayout(new GridLayout(3,1));
        jp1=new Resources(0);
        jp2=new Resources(4);
        jp3=new Resources(8);
        main.add(jp1);
        main.add(jp2);
        main.add(jp3);
        add(main,BorderLayout.CENTER);
    }
    
    public void inputCity(String city){
        weather.reconnect(city);
    }
    private class Resources extends JPanel{
        private JLabel date,icon1,icon2,tem;
        public Resources(int i){
            date=new JLabel(array[i]);
            icon1=new JLabel(new ImageIcon("images\\"+array[i+1]));
            icon2=new JLabel(new ImageIcon("images\\"+array[i+2]));
            tem=new JLabel(array[i+3]);
            add(date);
            add(icon1);
            add(icon2);
            add(tem);
        }
        public void reDisplay(int i){
            date.setText(array[i]);
            icon1.setIcon(new ImageIcon("images\\"+array[i+1]));
            icon2.setIcon(new ImageIcon("images\\"+array[i+2]));
            tem.setText(array[i+3]);
        }
    }
    public static void main(String [] args){
        JFrame report=new Report("WeatherReport");
        report.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        report.setVisible(true);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -