) 내 질문에 더 좋은 방법을 찾아야합니다. 기본적으로 웹 페이지에서 정보를 가져 와서 화면 전체에 멋지게 표시하는 프로그램을 만들었습니다.작은 방법으로 주 방법 대기 (
사용자가 프로그램을 닫으면 실제로 프로그램이 숨겨집니다.
또 다른 방법으로 정보가 계속 업데이트되는지 확인합니다. 불행히도 문제는 인스턴트 메시지를 보내는 것이 빠르고, 단지 40 초마다 정보를 확인하기를 원합니다.
내가 시도한 것은 메서드 자체와 프로그램의 메인에 대기 (1000,1000)를 삽입하는 것이 었습니다. 그러나 이들 모두는 IllegalMonitorStateException의 원인이됩니다.
스레드를 올바르게 대기시키는 올바른 방법입니까? 또는 더 좋은 방법이 있습니까? 참고 : 내가 가지고있는 유일한 스레드는 기본입니다. UPDATES
에 대한주요
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 _______________________________");
}
}
}
CHECK
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;
}
1 : 시간의 차이를 만드는 다른 방법이 있나요 :이 예외
2를 얻을 수 잘못하고 무엇을 생각합니다 메소드 내
3 :이 모든 메소드를 다른 스레드에 넣어야합니까? 요청에 의해 더
// 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();
}
말을주세요, 여기 getEngineersUpdate()이다
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;
}
GUI와 관련된 모든 호출은 스윙 이벤트 발송 스레드 (EDT)에서 발생해야합니다. SwingUtilities.invokeLater를 보거나 웹 검색을 통해 자세한 내용을 확인하십시오. 비록 당신이 단지 하나의 스레드를 가지고있는 것처럼 보일지라도 EDT는 GUI를 생성함으로써 시작될 때 실행 중이다. ==를 사용하여 문자열을 비교하고 대신 string.equals (otherString)을 사용하십시오. –
스윙을 사용하므로 메인이 유일한 스레드가 아닙니다. 최소한 이벤트 디스패치 스레드가 있습니다 –