相信上班族对公司内部的微信里面每间隔一天或者几个小时就会推送一条短报文,有的是晨报,有的是晚报。很多人都很好奇,这样一篇晨报,晚报,怎么实现出来的呢?接下来,博主阿鑫带你使用Java来简单制作一个晨报快速生成器!好的,废话不多说,直接上效果图:
总的项目的思路脑图如下:
项目的包结构:
需要的工具包下载链接:
1.Jsoup(点击下载)
2.SWT(点击进入选择下载)
废话不多说,老规矩,直接上干货!
(1)爬出百度热搜榜的代码:(简单版)
package com.sinsy.fntp.baiduRank;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class GetTheListOfBaiDu{
public Document getDocument (String url){
try {
return Jsoup.connect(url).timeout(5000).get();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
System.out.println(new GetTheListOfBaiDu().GetNewsBySevenDays());
}
public String getNewsBynow(){
// GetTheRankList t = new GetTheRankList();
Document doc = new GetTheListOfBaiDu().getDocument("http://top.baidu.com/buzz?b=1");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=list-table]");
int count = thefirstElement.select("[class=list-title]").size();
//今天
int number = 1;
String news = "";
for(int i = 0;i<count;i++) {
Elements elements2 = thefirstElement.select("[class=list-title]");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
news+=" [ "+number+" ] "+today+"\n";
number++;
}
// System.out.println(count);
return news;
}
public String GetNewsByToday() {
Document doc = new GetTheListOfBaiDu().getDocument("http://top.baidu.com/buzz?b=341&c=513&fr=topbuzz_b1_c513");
Elements thefirstElement = doc.select("[class=list-table]");
int count = thefirstElement.select("[class=list-title]").size();
int number = 1;
String news = "";
for(int i = 0;i<count;i++) {
Elements elements2 = thefirstElement.select("[class=list-title]");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
news+=" [ "+number+" ] "+today+"\n";
number++;
}
return news;
}
public String GetNewsBySevenDays() {
Document doc = new GetTheListOfBaiDu().getDocument("http://top.baidu.com/buzz?b=42&c=513&fr=topbuzz_b341_c513");
Elements thefirstElement = doc.select("[class=list-table]");
int count = thefirstElement.select("[class=list-title]").size();
int number = 1;
String news = "";
for(int i = 0;i<count;i++) {
Elements elements2 = thefirstElement.select("[class=list-title]");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
news+=" [ "+number+" ] "+today+"\n";
number++;
}
return news;
}
/**
* GetTheRankList t = new GetTheRankList();
Document doc = new GetTheListOfBaiDu().getDocument("http://top.baidu.com/buzz?b=1");
// 获取目标HTML代码
Elements thefirstElement = doc.select("[class=list-table]");
int count = thefirstElement.select("[class=list-title]").size();
//今天
int number = 1;
for(int i = 0;i<count;i++) {
Elements elements2 = thefirstElement.select("[class=list-title]");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
number++;
}
// System.out.println(count);
*/
}
(2)爬出网易的热榜代码:(简单版)
package com.sinsy.fntp.WangyiRank;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class GetTheWangyiRankList{
public Document getDocument (String url){
try {
//5000是设置连接超时时间,单位ms
return Jsoup.connect(url).timeout(5000).get();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
System.out.println(new GetTheWangyiRankList().GetWangyidianji());
}
public String GetWangyidianji() {
Document doc = new GetTheWangyiRankList().getDocument("https://news.163.com/rank/");
// 获取目标HTML代码
Elements e1= doc.select("[class=tabContents active]").select("table");
String news = "";
int count = e1.select("[class=red]").size();
int number=1;
for(int i = 0;i<20;i++) {
Elements elements2 = e1.select("a");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
news +=" [ "+number+" ] "+today+"\n";
number++;
}
return news;
}
public String GetWangyiNo2() {
Document doc = new GetTheWangyiRankList().getDocument("https://news.163.com/rank/");
// 获取目标HTML代码
Elements e1= doc.select("[class=tabContents active]").select("table");
String news = "";
int count = e1.select("[class=red]").size();
int number=1;
for(int i = 0;i<20;i++) {
Elements elements2 = e1.select("a");
String today = elements2.get(i).text();
System.out.println(" [ "+number+" ] "+today);
news +=" [ "+number+" ] "+today+"\n";
number++;
}
return news;
}
}
(3)获得时间的代码:(简单):
package com.sinsy.fntp.date;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetCurrentDate {
public static void main(String[] args) {
System.out.println(new GetCurrentDate().GetDate());
}
public String GetDate() {
Date date = new Date();
SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日");
System.out.println(simple.format(date));
return simple.format(date);
}
}
(4)获得每日一句的代码:
package com.sinsy.fntp.sayhello;
import java.io.IOException;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.sinsy.fntp.baiduRank.GetTheListOfBaiDu;
public class sayHello {
public static void main(String[] args) {
System.out.println(new sayHello().SplitTheJson2(new sayHello().randomnumber()));
}
public int randomnumber() {
int cache=0;
Random rm = new Random();
for(int i=0;i<100;i++)
{
cache=rm.nextInt(100)+1;
}
return cache;
}
public String SplitTheJson2(int head) {
String json="1.任何业绩的质变都来自于量变的积累。\r\n" +
"2.如果不想做点事情,就不要想到达这个世界上的任何地方。\r\n" +
"3.没有哪种教育能及得上逆境。\r\n" +
"4.障碍与失败,是通往成功最稳靠的踏脚石,肯研究、利用它们,便能从失败中培养出成功。\r\n" +
"5.让我们将事前的忧虑,换为事前的思考和计划吧!\r\n" +
"6.如果本来就生活在底层,那就不必担心混得没有底气。\r\n" +
"7.目光远大,目标明确的人往往非常自信,而自信与人生的成败息息相关。\r\n" +
"8.坚强者能在命运之风暴中奋斗。\r\n" +
"9.没有灯的小路一样可以行走,只要心还在。\r\n" +
"10.嘲讽是一种力量,消极的力量。赞扬也是一种力量,但却是积极的力量。\r\n" +
"11.命运是不存在的,它不过是失败者拿来逃避现实的借口。\r\n" +
"12.你若将过去抱的太紧,怎么能腾出手来拥抱现在?\r\n" +
"13.如果我坚持什么,就是用大炮也不能打倒我。\r\n" +
"14.路的尽头,仍然是路,只要你愿意走。\r\n" +
"15.与其在别人的生活里跑龙套,不如精彩做自己。\r\n" +
"16.要克服生活的焦虑和沮丧,得先学会做自己的主人。\r\n" +
"17.一朵花的凋零,荒芜不了整个春天,一次挫折也荒废不了整个人生。\r\n" +
"18.勇敢的面对阳光,阴影自然都在身后。\r\n" +
"19.山不辞土,故能成其高;海不辞水,故能成其深!\r\n" +
"20.成功与不成功之间有时距离很短——只要后者再向前几步。\r\n" +
"21.那些尝试去做某事却失败的人,比那些什么也不尝试做却成功的人不知要好上多少。\r\n" +
"22.在世界的历史中,每一伟大而高贵的时刻都是某种热忱的胜利。\r\n" +
"23.恐惧自己受苦的人,已经因为自己的恐惧在受苦。\r\n" +
"24.当一个人真正觉悟的一刻,他放弃追寻外在世界的财富,而开始追寻他?刃氖澜绲恼嬲?财富。\r\n" +
"25.成功没有快车道,幸福没有高速路。所有的成功,都来自不倦的努力和奔跑;所有幸福,都来自平凡的奋斗和坚持。\r\n" +
"26.如果你的生活已处于低谷,那就,大胆走,因为你怎样走都是在向上。\r\n" +
"27.不要因为众生的愚疑,而带来了自己的烦恼。不要因为众生的无知,而痛苦了你自己。\r\n" +
"28.生命要得到丰盛的收获,必需阳光;同时,也需要“雨”的浇灌。\r\n" +
"29.人总是在失去了才知道珍惜!\r\n" +
"30.要铭记在心:每天都是一年中最美好的日子。\r\n" +
"31.生活远没有咖啡那么苦涩,关键是喝它的人怎么品味!每个人都喜欢和向往随心所欲的生活,殊不知随心所欲根本不是生活。\r\n" +
"32.如果错过了太阳时你流泪了,那么你也要错过群星了。\r\n" +
"33.不如意的时候不要尽往悲伤里钻,想想有笑声的日子吧。\r\n" +
"34.没有人能替你承受痛苦,也没有人能抢走你的坚强。\r\n" +
"35.如果你看到面前的阴影,别怕,那是因为你的背后有阳光。\r\n" +
"36.幻想总是美好的,现实总是残酷的。\r\n" +
"37.优点一天比一天多,缺点一天比一天少。\r\n" +
"38.有人嫉妒你绝对是一件好事,但你要努力做到对得起这份嫉妒。\r\n" +
"39.世上没有绝望的处境,只有对处境绝望的人。\r\n" +
"40.泪水不代表着谁的失败,微笑不意味着谁的成功。\r\n" +
"41.要随波逐浪,不可随波逐流。\r\n" +
"42.遍体鳞伤后才知道,成功不是不够努力,成功是决不放弃。\r\n" +
"43.生活就是:生出来活下去。\r\n" +
"44.收起羡慕别人的目光自己去努力。\r\n" +
"45.如果上帝没有帮助你那他一定相信你可以。\r\n" +
"46.走好自己的路,让别人说去。\r\n" +
"47.真正的爱,应该超越生命的长度、心灵的??度、灵魂的深度。\r\n" +
"48.当你快乐的时候,生活是美好的,当有人因你而快乐的时候,生活才是最美好的。\r\n" +
"49.不论你在什么时候开始,重要的是开始之后就不要停止。\r\n" +
"50.在你穷的时候,要少在家里,多在外面。在你富有的时候,要多在家里,少在外面。这就是生活的艺术。穷得时候,钱要花给别人,富的时候,钱要花给自己。很多人,都做颠倒了。\r\n" +
"51.不要慨叹生活底痛苦——慨叹是弱者。 \r\n" +
"52.通往光明的道路是平坦的,为了成功,为了奋斗的渴望,我们不得不努力。\r\n" +
"53.人生,短短三万天,有高潮,有低谷;有成功,有失败;有生,有死。\r\n" +
"54.如果不想做点事情,就不好想到达这个世界上的任何地方。\r\n" +
"55.不好心平气和,不好容你自我昏睡!趁你还年轻,强壮灵活,要永不疲倦地做好事。\r\n" +
"56.如果不想做点事情,就甭想到达这个世界上的任何地方。\r\n" +
"57.坚持把简单的事情做好就是不简单,坚持把平凡的事情做好就是不平凡。所谓成功,就是在平凡中做出不平凡的坚持。\r\n" +
"58.这个世界并不是掌握在那些嘲笑者的手中,而恰恰掌握在能够经受得住嘲笑与批评忍不断往前走的人手中。\r\n" +
"59.让咱们将事前的忧虑,换为事前的思考和计划吧!坚持不懈。\r\n" +
"60.收起了无力的笑脸,卸下了虚伪的话语,用疲惫写完了这天的工作日记,不知道是否还有勇气去追赶明天那开不完的烦人会议,现实,咱们用什么鼓励自我,活着。\r\n" +
"61.在世界的历史中,每一伟大而高贵的时刻都是某种热忱的胜利。\r\n" +
"62.注意你的思想,它会变成你的言语;注意你的言语,它会变成你的行动;注意你的行动,它会变成你的习惯;注意你的习惯,它会变成你的性格;注意你的性格,它会变成你的命运。\r\n" +
"63.道路坎坷事不期,疾风劲草练男儿。\r\n" +
"64.没有什么事情有象热忱这般具有传染性,它能感动顽石,它是真诚的精髓。\r\n" +
"65.我大好的一个人,凭什么跑到别人的生命里去当插曲。\r\n" +
"66.只要有信心,人永远不会挫败。\r\n" +
"67.尽管社会是这样的现实和残酷,但我们还是必须往下走。\r\n" +
"68.愚痴的人,一直想要别人了解他。有智慧的人,却努力的了解自己。\r\n" +
"69.只要比竞争对手活得长,你就赢了。\r\n" +
"70.平静的湖面只有呆板的倒映,奔腾的激流才有美丽的浪花!幸福不是靠别人来布施,而是要自己去赢取!生命的意义在不断挑战自己,战胜自己!\r\n" +
"71.你接受比抱怨还要好,对于不可改变的事实,你除了接受以外,没有更好的办法了。\r\n" +
"72.输了就是输了,没什么好去解释的,不过是一盘棋,何必去计较。\r\n" +
"73.学会奉承领导,多摆笑脸,不做恶人,三缄其口,三思而后行。\r\n" +
"74.追求让人充实,分享让人快乐。\r\n" +
"75.能把在面前行走的机会抓住的人,十有八九都会成功。\r\n" +
"76.人性最可怜的就是:我们总是梦想着天边的一座奇妙的玫瑰园,而不去欣赏今天就开在我们窗口的玫瑰。\r\n" +
"77.智慧总是在孤独中生根。\r\n" +
"78.最简短的回答就是行动。\r\n" +
"79.都在说放弃,可是,当放弃时又学会了珍惜,毕竟一切都来之不易。\r\n" +
"80.以岁月的名义,照亮你体内小小的倔强和忧郁。\r\n" +
"81.我将一切回忆掩埋,只想拥有一个美好的未来。\r\n" +
"82.人生的无奈不在于没有选择的余地,而恰恰是因为需要作出太多的抉择。\r\n" +
"83.天才是百分之一的灵感加上百分之九十九的努力。\r\n" +
"84.目标的坚定是性格中最必要的力量源泉之一,也是成功的利器之一。没有它,天才也会在矛盾无定的迷径中徒劳无功。\r\n" +
"85.在真实的生命里,每桩伟业都由信心开始,并由信心跨出第一步。\r\n" +
"86.觉得自己做的到和不做的到,其实只在一念之间。\r\n" +
"87.不好问别人为你做了什么,而要问你为别人做了什么。\r\n" +
"88.一个人除非自己有信心,否则无法带给别人信心。\r\n" +
"89.为别人鼓掌的人也是在给自己的生命加油。\r\n" +
"90.失败是什么?没有什么,只是更走近成功一步;成功是什么?就是走过了所有通向失败的路,只剩下一条路,那就是成功的路。\r\n" +
"91.开始一种恐慌,停留与不可复制的回忆。\r\n" +
"92.经验是由痛苦中粹取出来的。\r\n" +
"93.自己要先看得起自己,?e人才会看得起你。\r\n" +
"94.人生需要耐心和等待。在等待中煎熬,在等待中获取所求,在等待中成就,在的等待中喜悦!\r\n" +
"95.人生试题一共有四道题目:学业、事业、婚姻、家庭。平均分高才能及格,切莫花太多的时间和精力在任一题目上。\r\n" +
"96.用时间和心看人,而不是用眼睛。\r\n" +
"97.生命的道路上永远没有捷径可言,只有脚踏实地走下去。\r\n" +
"98.只要还有明天,今天就永远是起跑线。\r\n" +
"99.人人都会错过,人人都曾经错过,真正属于你的,永远不会错过。\r\n" +
"100.我努力赚钱的目的,就是想让我爸妈在给自己买东西的时候能像给我买东西的时候一样干脆。";
String regex = head+".(.*?)。";
String param ="";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(json);
while (m.find()) {
int i = 1;
param+=m.group(i)+"\n";
i++;
}
return param;
}
}
(5)获得位置信息的代码:(返回结果包含天气)
这是一个很有意思的问题,之前一位老哥想直接在应用里面调用天气API但是发现,天气API是通过autolocation实现的自动获取当前位置天气,调用的是原生js,问题来了,如果直接post或者get这个api,在无法满足模拟浏览器访问的前提下,需要提供城市代码来获取天气信息,难道要让使用者自己输入城市名称或者城市代码吗?这么做,很麻烦,再或者,让用户自己选择城市?也会增加开发量,代码冗余,这让他很困惑,不知所措。
其实我首先想到的也是直接post,只不过方式不同,其实可行的方法有很多,稍微想一下,大致有三种途径。
第一种,借助jar。国内很多网站提供自定义封装的jar可以解决识别位置的问题,在大材小用一点,用百度或者腾讯的SDK也是可以解决问题,因为地图信息就可以解决位置问题,返回的结果集也是包含天气的JSON。
第二种,借助网站。这种比较复杂,首先通过模拟浏览器进入网站,获取当前位置信息来,通过结果回调来查询天气,这种连续post同一个网站的方法相比上一种采用jar的方法要稍微复杂一点点。也就是说,先通过网站拿到当前访问该网站的外网IP,再通过该网站的api用ip查询天气。原理清晰可见,步骤稍有繁琐。
第三种,最直接简单的方法,直接post一个自动获得ip的天气api,通过util提供的url工具类接受一下buffer,不就解决了。。。。。。。下面就是最直接的方法:(好了废话不多说,直接上代码)
package com.sinsy.fntp.where;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Location{
public static void main(String[] args) {
System.out.println(new Location().getV4IP());
System.out.println(new Location().SplitTheJson());
// System.out.println(new Location().loadJson("https://free-api.heweather.net/s6/weather/now?location=auto_ip&key=db86a5196f304e52a4369818c5182e60"));
// System.out.println(new Location().SplitTheJson2(param));
}
public String getV4IP(){
String ip = "";
String chinaz = "http://ip.chinaz.com";
StringBuilder inputLine = new StringBuilder();
String read = "";
URL url = null;
HttpURLConnection urlConnection = null;
BufferedReader in = null;
try {
url = new URL(chinaz);
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedReader( new InputStreamReader(urlConnection.getInputStream(),"UTF-8"));
while((read=in.readLine())!=null){
inputLine.append(read+"\r\n");
}
//System.out.println(inputLine.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Pattern p = Pattern.compile("\\<dd class\\=\"fz24\">(.*?)\\<\\/dd>");
Matcher m = p.matcher(inputLine.toString());
if(m.find()){
String ipstr = m.group(1);
ip = ipstr;
//System.out.println(ipstr);
}
return ip;
}
public static String loadJson (String url) {
StringBuilder json = new StringBuilder();
try {
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return json.toString();
}
public String SplitTheJson() {
String json=new Location().loadJson("https://free-api.heweather.net/s6/weather/now?location=auto_ip&key=db86a5196f304e52a4369818c5182e60");
json=json.replace("{","[");
json=json.replace("\"", "");
json=json.replace("[HeWeather6:[[basic:[", "");
String regex1 = ",admin_area:(.*?),";
String regex2 = ",location:(.*?),";
String regex3 = ",cond_txt:(.*?),";
String regex4 = ",tmp:(.*?),";
String location = "",weather="";
Pattern pattern1 = Pattern.compile(regex1);
Matcher m = pattern1.matcher(json);
while (m.find()) {
int i = 1;
location+=m.group(i);
i++;
}
Pattern pattern2= Pattern.compile(regex2);
Matcher m2 = pattern2.matcher(json);
while (m2.find()) {
int i = 1;
location+=m2.group(i)+" ";
i++;
}
Pattern pattern3= Pattern.compile(regex3);
Matcher m3 = pattern3.matcher(json);
while (m3.find()) {
int i = 1;
weather+=m3.group(i)+" ";
i++;
}
Pattern pattern4= Pattern.compile(regex4);
Matcher m4 = pattern4.matcher(json);
while (m4.find()) {
int i = 1;
weather+=m4.group(i)+" ℃";
i++;
}
return location+weather;
}
public String SplitTheJson2(String json) {
String regex = "[(.*?)]";
String param ="";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(json);
while (m.find()) {
int i = 1;
param+=m.group(i)+"\n";
i++;
}
return param;
}
}
(6)SWT的核心代码:
package com.sinsy.fntp.news;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.wb.swt.SWTResourceManager;
import com.sinsy.fntp.baiduRank.GetTheListOfBaiDu;
import com.sinsy.fntp.date.GetCurrentDate;
import com.sinsy.fntp.sayhello.sayHello;
import com.sinsy.fntp.where.Location;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class newsmanwindows {
protected Shell shell;
private Text shuchu;
private Text weiba;
private boolean flag=false;
private boolean currentdate_open= false;
private boolean hello = false;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
newsmanwindows window = new newsmanwindows();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(482, 577);
shell.setText("\u946B\u8F6F\u6668\u62A5\u751F\u6210");
Composite composite = new Composite(shell, SWT.NONE);
composite.setBounds(10, 10, 444, 110);
Label lblNewLabel = new Label(composite, SWT.BORDER);
lblNewLabel.setImage(SWTResourceManager.getImage(newsmanwindows.class, "/img/2.png"));
lblNewLabel.setBounds(0, 0, 444, 110);
Composite composite_1 = new Composite(shell, SWT.BORDER);
composite_1.setBounds(10, 126, 444, 64);
Combo combo = new Combo(composite_1, SWT.NONE);
combo.setItems(new String[] {"\u70ED\u641C\u699C", "\u5173\u6CE8\u5EA6", "\u8BC4\u8BBA\u91CF"});
combo.setBounds(338, 22, 92, 28);
combo.setText("\u4F18\u5148\u9009\u62E9");
Combo newssources = new Combo(composite_1, SWT.NONE);
newssources.setItems(new String[] {"\u767E\u5EA6\u70ED\u699C", "\u65B0\u6D6A\u70ED\u699C", "\u7F51\u6613\u70ED\u699C"});
newssources.setBounds(240, 22, 92, 28);
newssources.setText("\u9009\u62E9\u6765\u6E90");
weiba = new Text(composite_1, SWT.BORDER);
weiba.setBounds(107, 22, 127, 26);
Label label = new Label(composite_1, SWT.NONE);
label.setBounds(10, 25, 91, 20);
label.setText("\u8BF7\u60A8\u8F93\u5165\u5C3E\u5DF4");
Composite composite_1_1 = new Composite(shell, SWT.BORDER);
composite_1_1.setBounds(10, 196, 444, 78);
Button weather = new Button(composite_1_1, SWT.CHECK);
weather.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(weather.getSelection())
flag=!flag;
}
});
weather.setBounds(10, 30, 84, 20);
weather.setText("\u663E\u793A\u5929\u6C14");
Button currentdate = new Button(composite_1_1, SWT.CHECK);
currentdate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(currentdate.getSelection())
currentdate_open = !currentdate_open;
}
});
currentdate.setBounds(109, 30, 121, 20);
currentdate.setText("\u663E\u793A\u65F6\u95F4\u65E5\u671F");
Button sayhello = new Button(composite_1_1, SWT.CHECK);
sayhello.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(sayhello.getSelection())
hello = !hello;
}
});
sayhello.setBounds(238, 30, 99, 20);
sayhello.setText("\u663E\u793A\u95EE\u5019\u8BED");
Button btnNewButton = new Button(composite_1_1, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// 断报报文
String news=new GetTheListOfBaiDu().getNewsBynow();
// 小尾巴
String wb=weiba.getText();
// 位置与天气
String locationandweather = new Location().SplitTheJson();
// 当前日期
String date = new GetCurrentDate().GetDate();
// 励志语句
String sayhello = new sayHello().SplitTheJson2(new sayHello().randomnumber());
if(flag&¤tdate_open&&hello)
shuchu.setText(wb+"\n"+date+"\n"+locationandweather+"\n"+news+"【今日微语录】:"+sayhello);
}
});
btnNewButton.setBounds(352, 25, 78, 30);
btnNewButton.setText("\u4E00\u952E\u751F\u6210");
Composite composite_1_2 = new Composite(shell, SWT.NONE);
composite_1_2.setBounds(10, 280, 444, 240);
shuchu = new Text(composite_1_2, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
shuchu.setBounds(0, 0, 444, 240);
}
}
好啦!本期的鑫软教程到此结束啦!文字不多,请各位看官慢品!