Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating Buttons/Windows (LIVE)  RSS feed

 
Rhino Jimm'O
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking for some code examples that show how I can update a bunch of icons and turn them green/red based on some outside variables (that will keep changing)

Let's say that we have 3 boxes or 3 green icons.

I have another program that will be monitoring file1.txt, file2.txt and file3.txt. When file2.txt changes to non-zero I would like to change box2/icon2 to red.

Seems simple enough to do but I can't seem to find any examples out there.

TIA!
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be larger that you think.

If I've understood you correctly, you want two applications. Application_A will draw three buttons (or whatever you are using) on the screen. Application_B will run in the background and only look for the existance of some files.

When Application_B notices a file, it is supposed to tell Application_B that one of it's buttons is supposed to change color.

If that is correct, then you have a threaded client/server application here.

Application_A will have to draw on the screen, start a server thread, and continue doint whatever the application needs to be doing.

Application_B will have to also be a threaded application running in an infinate loop that will recognize the file's existance, communicate with the server, and contine processing as it was originally designed.

Anyway, it's certianly possible to write this, but I would not call it simple. If you have decent skills, it should only take you a few hours, however if you are new to SWING, network programming, or threads it will take you a bit longer.

Try breaking it down into smaller pieces and implementing them first.

(then again, maybe I've read too much into your original post)
 
Rhino Jimm'O
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it could be 1 program checking the files and making the updates to the boxes/colors/etc. Doesn't matter.

Thanks!
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can have this as an example, but it is not an application I would use in it present state...



This should work without any modifications. As soon as c:\mydata.dat exists, button 1 will turn blue.
 
Rhino Jimm'O
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I threw this in a file and tried the following:

C:\Program Files\Java\jdk1.5.0\bin>javac.exe -Xlint eprecation something.java
something.java:17: class ButtonChanger is public, should be declared in a file n
amed ButtonChanger.java
public class ButtonChanger extends JPanel
^
something.java:49: warning: [deprecation] show() in java.awt.Window has been dep
recated
theFrame.show();
^
1 error
1 warning

C:\Program Files\Java\jdk1.5.0\bin>

Thoughts? Maybe I'm just too new at this!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first error just means that you didn't put that class in a file with the same name as the class. I ran it and it worked fine.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, my dicerorhinus friend,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!