package wtpaly;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;public class Wtplay extends JFrame { //窗口配置 private JTextArea messageArea; private JButton send; //wt配置 private int tq;//天氣 晴40-2 ?陰60-2 雨0-3 private int wd;//溫度 高10-3 ?中15-1 ?低5-3 private int sd;//濕度 濕 5-4 ? 干10-3 private int fl;//風(fēng)力 無15-2 ?微10-3 ?大0-2 private String[] wt=new String[4]; //產(chǎn)生隨機數(shù) private int ?rad(){ int a=(int)(Math.random()*7); return a; } //產(chǎn)生天氣 public String randwt(){ int a=this.rad();//產(chǎn)生天氣 if(a<2){ this.tq=2; this.wt[0]="晴"; }else if(a<4){ this.tq=3; this.wt[0]="多云"; }else{ this.tq=0; this.wt[0]="雨"; } int b=this.rad();//產(chǎn)生溫度 if(b<1){ this.wd=1; this.wt[1]="低溫"; }else if(b<4){ this.wd=3; this.wt[1]="中等"; }else{ this.wd=2; this.wt[1]="高溫"; } int c=this.rad();//產(chǎn)生濕度 if(c<4){ this.sd=1; this.wt[2]="潮濕"; }else{ this.sd=2; this.wt[2]="干燥"; } int d=this.rad();//產(chǎn)生風(fēng)力 if(d<1){ this.fl=0; this.wt[3]="強風(fēng)"; }else if(d<4){ this.fl=3; this.wt[3]="無風(fēng)"; }else{ this.fl=2; this.wt[3]="微風(fēng)"; } String af="天氣:"+this.wt[0]+"\n溫度:"+this.wt[1]+"\n濕度:"+this.wt[2]+"\n風(fēng)力:"+this.wt[3]+"\n出行指數(shù):"+(this.tq*20+this.wd*5+this.sd*5+this.fl*5); return af; } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == send) { String a=new Wtplay().randwt(); messageArea.setText(a); } } } public Wtplay() { // 設(shè)置客戶端窗口的標題 super("Wtpllay"); // 初始化界面元素 messageArea = new JTextArea(); send = new JButton("明天"); // 設(shè)置界面布局 Container c = this.getContentPane(); JScrollPane jsp = new JScrollPane(messageArea); c.add(jsp); JPanel jp = new JPanel(); jp.add(send); c.add(jp, BorderLayout.SOUTH); // 為連接按鈕注冊監(jiān)聽器 P74 ButtonListener bl = new ButtonListener(); send.addActionListener(bl); } public static void main(String[] args) { Wtplay Wtplay = new Wtplay(); Wtplay.setSize(500, 300); Wtplay.setLocation(200, 200); Wtplay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Wtplay.setVisible(true); String a=Wtplay.randwt(); Wtplay.messageArea.setText(a); }}
如何將天氣的數(shù)據(jù)寫到數(shù)據(jù)庫中,出行指數(shù)根據(jù)天氣的一些數(shù)據(jù)來進行判斷
qq_假如我是一只貓_0
2016-06-20 08:46:36