I managed to do what I wanted when the user copies some text, the data is stored in a arraylist. My problem comes from the GUI ,I've tried several things but I can't manage to display the data of the ArrayList.
My problem is that I don'T know exactly where to create the GUI, in the main class or in the Thread that does all the doing? secondly since the data keeps adding whenever the user copies, the list has to be updated in real time to display the content of the list is there any way to achieve that ? Any tips would be appreciated
Yes and no. It is good to have a project you want to complete; that provides lots of motivation, but without guidance you can go seriously wrong. Even code which appears to work can be written incorrectly. Show us the code and we can help guide you.
Rachid Insa wrote:. . . the best way to learn is to have personal projects to work on.
Please explain more; the clipbouard is an operating system feature and Jaa® as a language is not very good at getting at low‑level operating system stuff.
I've been working on a clipboard manager that keep a history of what the user copies.
Can you display the List at the terminal/command line? You should be able to run any applications from the command line without a GUI and then make the List available to the GUI later.
I managed to do what I wanted when the user copies some text, the data is stored in a arraylist. . . . I can't manage to display the data of the ArrayList.
Don't know. I actually think both those locations may be wrong, however. But GUIs are for later on.
My problem is that I don'T know exactly where to create the GUI, in the main class or in the Thread that does all the doing?
That sounds like a job for a worker thread, which you can use via an instance of the Swing worker class, but get the List sorted out first.
. . . the list has to be updated in real time to display the content of the list is there any way to achieve that ? . . .
Campbell Ritchie wrote:Welcome to the Ranch
Thanks , so my code goes as follows:
So basically whenever there is an update in the content of the clipboard, the content is stored in the ArrayList. At first I make sure to clear the clipboard so that there is no unpleasant surprise. That is the way I found to keep a history of what the user copies. I wanted it to only store 10 piece of data or string in this case and should act as a queue (so FIFO). I can display the ArrayList at the terminal/command line that is the reason why I wanted to go a step further by making the List available to the GUI. And my main class is quite simple:
I had forgotten that a Toolkit object allows you access to the clipboard. I am not familiar with the code which declares those exceptions, least of all line 32. Please consider making your listener class implement Runnable rather that extending Thread. You will have to use a different thread for Swing purposes, so it is probably right that you run the listener in its own thread. And it is right that you haven't yet created a GUI.
Consider using multiple catch with the | operator.
If you want a queue with a limited size, why are you using a List? Go through the Java™ Tutorials and see whether there is a Queue implementation with a limited size. (It might be that the two kinds of blocking queue will do what you want.)
Concerning the rest I will follow what you advise me to do and see how it goes. I removed the GUI elements since I had it all wrong .