Pregunta

I need to create an alarm program in Java:
I don't how to pop up string in the middle of the screen for 30 seconds
in black box.
Just like Rhythumbox notifcation.
Also how on close the program minimized in the notification area (ubuntu)
I just don't know where to start, the alarm code is easy, just those 2 functions.
please help

thank you.

¿Fue útil?

Solución

Start by taking a look at:

  • Creating a GUI With JFC/Swing for details about how to create a UI using Swing
  • How to Use Swing Timers as a possible alternative to other timer mechnisms. The benefit of this is that it is executed within the context of the Event Dispatching Thread, so you don't need to mess to much about re-syncing the UI code with the EDT when the timer goes off. May not suit your requirements, but it's nice to know.
  • How to Use the System Tray

Updated

  • Create a JWindow.
  • Set the background color of the content pane to Color.BLACK
  • Set the alwaysOnTop to true
  • Create a JLabel, set it's text property and change it's foreground color to something like Color.WHITE, adjust what ever other properties you
  • Add a Border to the content if you want to add some padding
  • Add the label to the content pane
  • pack the window
  • set it's locationRelativeTo null, to make it appear in the center of the screen
  • Make the window visible

Possible examples...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top