Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've changed your code so it should work as you intended. I'm not clear on what getEngineersUpdate() does, so I can't say for sure if it will work, but I've given you a start. I've included 2 options for how to handle it, with explanation in the comments. You can see how to use a Timer properly in the constructor, also. Finally, I don't have your full code, so I had to rig something together to simulate it.</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); } } class MyFrame extends JFrame { private String [] latestUpdate = new String[1]; private static final int DISPLAY_TIME = 3000; private Timer displayTimer; /* * Option #1: * Ideally, you'd have the thread that generates the "Engineers Update" messages call this * method. If you can't make this event based, then you should use option #2 */ public void newUpdate(String message) { setVisible(true); // change this to whatever you need to. text.setText(message); displayTimer.restart(); } // I used this to test it private JTextField text; public MyFrame() { // gets the maximum size of the screen Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); //sets it to max. need to change this setSize(d.width, (d.height / 100) * 10); // 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); text = new JTextField("Initial Text"); add(text); // this creates a timer that when it goes off, will hide the frame displayTimer = new Timer(DISPLAY_TIME, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); // sets the timer not to repeat displayTimer.setRepeats(false); //This code is for option #2: updateTimer = new Timer(UPDATE_INTERVAL, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { checkForNewUpdate(); } }); updateTimer.start(); } // This is for option #2 private static final int UPDATE_INTERVAL = 1000; private Timer updateTimer; /* * Option #2: * Not ideal, but this should work. */ public String[] checkForNewUpdate() { // I don't know how getEngineersUpdate() works // which would have made it much easier to help you. String tempUpdate = getEngineersUpdate(); // String comparison doesn't work like this in java. // you also had a sleeping NullPointerException here if (!tempUpdate.equals(latestUpdate[0])) { // this is when you have a new update, correct? newUpdate(tempUpdate); latestUpdate[0] = tempUpdate; } else if (tempUpdate.equals(latestUpdate[0])) { // it's the same update as last time, so do nothing } else if (tempUpdate.equals("NULL")) { // You need to handle this according to what getEngineersUpdate() does } return latestUpdate; } // This code is rigged to show how it would work private static int i = 0; private String getEngineersUpdate() { // 1 in 6 chance of returning "NULL" if (Math.random() * 6 - 1 &lt; 0) return "NULL"; // probability of 1 in 4 of generating a new update if(Math.random() * 4 - 1 &lt; 0) return "UPDATE #"+i++; else return "UPDATE #"+i; } } </code></pre>
 

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