Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.ivo.mexete;
- import java.io.IOException;
- import java.util.Scanner;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class Main {
- public static String obterHorarios(String paragem) throws IOException{
- String results = null;
- Document doc = Jsoup.connect("http://www.stcp.pt/pt/itinerarium/soapclient.php?codigo=" + paragem).get();
- Elements smsBusResults = doc.select("#smsBusResults tr:lt(3)");
- for (Element col : smsBusResults) {
- results = col.text();
- }
- if (doc.getElementsContainingText("Por favor, utilize o codigo SMSBUS indicado na placa da paragem") != null) {
- throw new IOException();
- }
- return results;
- }
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Qual a paragem que queres ver?\n");
- System.out.println(obterHorarios(scanner.next()));
- }
- }
- #UI
- package me.ivo.mexete;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import javax.swing.JTextField;
- import javax.swing.JTextPane;
- import javax.swing.JTable;
- import javax.swing.JButton;
- public class UI implements ActionListener {
- private JFrame frame;
- private JTextField textField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- UI window = new UI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public UI() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JLabel lblParagem = new JLabel("Paragem:");
- lblParagem.setFont(new Font("Lucida Grande", Font.PLAIN, 25));
- lblParagem.setBounds(6, 6, 164, 58);
- frame.getContentPane().add(lblParagem);
- textField = new JTextField();
- textField.setBounds(6, 61, 238, 26);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- JButton btnSubmeter = new JButton("Submeter");
- btnSubmeter.setBounds(254, 60, 117, 29);
- frame.getContentPane().add(btnSubmeter);
- btnSubmeter.addActionListener(this);
- JLabel lblResultado = new JLabel("Resultado:");
- lblResultado.setFont(new Font("Lucida Grande", Font.PLAIN, 25));
- lblResultado.setBounds(6, 99, 164, 58);
- frame.getContentPane().add(lblResultado);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- JLabel lblResultados = new JLabel("");
- lblResultados.setBounds(6, 153, 418, 98);
- frame.getContentPane().add(lblResultados);
- try {
- lblResultados.setText(Main.obterHorarios(textField.getText().toString()));
- } catch (IOException e1) {
- JOptionPane.showMessageDialog(null, "Verifica o código da paragem e/ou a ligação à Internet", "ERRO", JOptionPane.ERROR_MESSAGE);
- e1.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement