Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a main method wait on a smaller method (java)
    primarykey
    data
    text
    <p>i really need to find better ways to word my questions. Basically I've created a program that takes information from a webpage and displays it nicely across the screen.</p> <p>When the user closes the program, they actually hide it. </p> <p>I also have another method which constantly loops checking for information to see if tis been updated. unfortunately the problem im having is that it loops to fast, i only want it to check for information every 40 seconds or so.</p> <p>What i tried was inserting a wait(1000,1000) in the method itself and in the main of the program. but both of these cause IllegalMonitorStateException.</p> <p>Is this the correct way to make the thread wait properly? or is there a better way? note: the only thread i have is the main.</p> <p>MAIN</p> <pre><code>class Marquee { public static void main(String[] args) throws InterruptedException { MyFrame frame = new MyFrame(); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); frame.setVisible(true); frame.setAlwaysOnTop(true); frame.setBackground(Color.BLACK); frame.setResizable(true); while(true) { // this doesnt work frame.wait(1000,1000); frame.notifyAll(); frame.checkForNewUpdate(); System.out.println(" ____________________________next line _______________________________"); } } } </code></pre> <p>CHECK FOR UPDATES</p> <pre><code>public String[] checkForNewUpdate() { //setVisible(true); String tempUpdate = getEngineersUpdate(); if (latestUpdate[0] != tempUpdate) { // do nothign setVisible(false); } else if(latestUpdate[0]==tempUpdate) { latestUpdate[0] = tempUpdate; //show the page again setVisible(true); } else if(latestUpdate[0]!= "NULL") { // do nothing //latestUpdate[0] = tempUpdate; } else { latestUpdate[0] = tempUpdate; } return latestUpdate; } </code></pre> <p>1: WHat am i doing wrong to get this exception</p> <p>2: Is there any other way to make a gap of time in a method</p> <p>3: Am i going to have to put all these methods into another thread? Please say no</p> <hr> <pre><code>// my constructor which I failed to mention has a timer in it. only i dont know hwo to use it class MyFrame extends JFrame implements ActionListener { private ActionListener listener; private Timer t1; private String [] latestUpdate = new String[1]; public MyFrame() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize();// gets the maximum size of the screen setSize(d.width,(d.height/100)*10);//sets it to max. need to change this // this shit find the max size of screen and puts it bottom left GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int)rect.getMinX(); int y = (int)rect.getMaxY()-getHeight(); setLocation(x,y-30); setTitle("ALERT::OUTAGE"); MyPanel panel = new MyPanel(); add(panel); listener = this; t1 = new Timer(50,listener); t1.start(); } </code></pre> <p>by request, here is getEngineersUpdate()</p> <pre><code>public String getEngineersUpdate() //gets data from page and sets it to string. { String update = "blank"; final WebClient webClient = new WebClient(); webClient.setJavaScriptEnabled(false);// javascript causes some serious problems. webClient.setCssEnabled(false); String forChecking; HtmlPage page; try { URL outageURL = new URL("file:\\C:\\Users\\0vertone\\Desktop\\version control\\OUTAGE\\Outages.html"); //local drive at home page = webClient.getPage(outageURL); //All this crap can be gone if we just give the table an id Object[] dates = page.getByXPath("//span[@id='date']/text()").toArray(); Object[] sites = page.getByXPath("//span[@id='site']/text()").toArray(); Object[] issues = page.getByXPath("//span[@id='issue']/text()").toArray(); System.out.println("" + dates[0].toString()); System.out.println("" + sites[0].toString()); System.out.println("" + issues[0].toString()); update = (dates[0].toString() + " " + sites[0].toString() + " " +issues[0].toString()); forChecking = dates[0].toString(); /**some examples of the getCellAt() method*/ //update = table.getCellAt(0,0).asText(); // This returns DATE/Time //update = table.getCellAt(1,0).asText(); // This return the actual date //update = table.getCellAt(0,1).asText(); // This returns, SITE/Sector //update = table.getCellAt(1,1).asText(); // This returns the actual site issue } catch (FailingHttpStatusCodeException a) { System.out.println("Failing HTTP Status Execution"); a.printStackTrace(); } catch (MalformedURLException b) { System.out.println("Malformed URL"); b.printStackTrace(); } catch (IOException c) { System.out.println("IO PROBLEMS!"); c.printStackTrace(); } webClient.closeAllWindows(); return update; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload