forked from mridaaa/NEWS-SCRAPER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentFrame.java
49 lines (41 loc) · 2.06 KB
/
ContentFrame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.Scanner;
public class ContentFrame extends JFrame {
public ContentFrame() throws IOException {
setTitle("BING NEWS SCRAPER");
setSize(new Dimension(1080,1080));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
String newsKeyword = customDialogBox();
setTitle(newsKeyword.toUpperCase() + " TOP 3 BING NEWS RESULTS ");
NewsScraper ns = new NewsScraper();
String url = Constants.NEWS_SITE_URL + newsKeyword.replace(" ", "+");
String html = ns.getHTML(url);
News news = ns.getHeadlines(html, "<div class=\"news-card newsitem cardcommon\"");
HeadlinePanel panel1 = new HeadlinePanel(news.firstItem.getCover(), news.firstItem.getHeadline(), news.firstItem.getSummary(), news.firstItem.getPostTime());
HeadlinePanel panel2 = new HeadlinePanel(news.secondItem.getCover(), news.secondItem.getHeadline(), news.secondItem.getSummary(), news.secondItem.getPostTime());
HeadlinePanel panel3 = new HeadlinePanel(news.thirdItem.getCover(), news.thirdItem.getHeadline(), news.thirdItem.getSummary(), news.thirdItem.getPostTime());
JPanel p= (JPanel) getContentPane();
Color bgColor = new Color(255,252,235);
p.setBackground(bgColor);
p.setLayout(new GridLayout(3,3)); //set your own layout
p.add(panel1);
p.add(panel2);
p.add(panel3);
}
private String customDialogBox() {
UIManager.put("OptionPane.messageFont" , new Font("Verdana", Font.BOLD, 14));
Icon icon = new ImageIcon("tempicon.jpeg");
UIManager.put("OptionPane.messageIcon", icon);
Object[] selectionValues = {"Enter"};
String userInput = (String)JOptionPane.showInputDialog(
null, "Search Bing News", "Bing News Scraper", JOptionPane.QUESTION_MESSAGE, icon, null, null
);
return userInput;
}
public static void main(String[] args) throws IOException {
ContentFrame f = new ContentFrame();
}
}