Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.WindowEvent;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class Main {
- public static void main(String[] args) throws Exception {
- int sleep;
- while (true) {
- if (anyoneThere()) {
- sleep = infoBox()-1;
- while (sleep > 0) {
- Thread.sleep(60 * 1000);
- sleep--;
- }
- }
- Thread.sleep(60 * 1000);
- }
- }
- public static int infoBox()
- {
- boolean doneGood=false;
- int n=0;
- String[] options = {"OK"};
- do{
- try{
- JFrame frame = new JFrame();
- frame.setUndecorated( true );
- frame.setVisible( true );
- frame.setLocationRelativeTo( null );
- JPanel panel = new JPanel();
- JLabel lbl = new JLabel("Turn off this pop-up for how many minutes?");
- JTextField txt = new JTextField(10);
- panel.add(lbl);
- panel.add(txt);
- JOptionPane.showOptionDialog(frame, panel, "A player is playing FlightMC!", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]);
- frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
- n=Integer.parseInt(txt.getText());
- doneGood=true;
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null, "You don't like listening to instructions, do ya?");
- }
- }while(!doneGood);
- return n;
- }
- public static boolean anyoneThere() throws Exception {
- URL flight = new URL("http://198.27.90.130/flightmc/Flight");
- String inputLine;
- BufferedReader in = new BufferedReader(new InputStreamReader(
- flight.openStream()));
- while ((inputLine = in.readLine()) != null) {
- // System.out.println(inputLine);
- if (inputLine.contains("Online now!")) {
- return true;
- }
- }
- in.close();
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement