Daniel Marti

Ranch Hand
+ Follow
since Jun 08, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Daniel Marti

I'm going to propose a slightly radical change on your code. As you know, you can only see the top of the stack, so exactly why do you want to contain the stack somewhere?
All you need is to envelop each object on the stack with something that makes it behave like a stack, and a single object that represents the top of said stack:

With these 2 very simple classes you can create any stack you want. To improve on it, use templating. You can add a count to MyStackManager to provide the amount of objects in the stack without having to go through all of the elements and count. Also you do not need to make it static, i am just showing the simplest form of it.
13 years ago
Thank you for the fast answer.
I know about key events, what i meant was, instead of being me checking each time a key is pressed, i would only receive the event if the keys i'm interested in are pressed (i am afraid of slightly lagging my typing).
Anyway i'll check JNI and see what i can get from that.
Thanks again.
13 years ago
Hello
I am developing a very small personal project to help me tally up some work related data (db problems solved, time spent debugging a particular piece of code, etc). Anyway, i need to catch certain combination of keystrokes (mainly ctrl+ a numpad key) and increase the counter for the corresponding task, or start/stop the timer.
I know how to grab keystrokes inside my own applications and recognize them, but have no idea how to do that from outside the application in focus.
So my question is 2-fold:
1) How to grab keystrokes when the application is not the one on focus
2) Is there a way to have the event listener only being fired when the key combinations i'm interested are pressed?

A google search gave me the answer in a restrict number of sites saying that it is not possible in java, but i would like to know it from a more trustworthy site like this. If i can't do it in java guess i'll have to do in c#...
Thank you in advance for the help
13 years ago
If the question was something like "Explain how you would build a dictionary using only the core java libraries", that is a likely question (got one similar in an exam).
To start you may want to see what exactly a dictionary is. It seems to me it is a word with the meaning in front of it. So, you have a word, that does not repeat, and a series of words that relates to it. Doesn't that sound like something?
13 years ago
I am not in a place where i can test this for you, but try the following:
In the container that has your myPanel override

Inside it make a check:
if you need to repaint everything call super.paintComponent(g).
If you need to only repaint your myPanel call myPanel.repaint().

I am sure i have a piece of code for the same objective that you have somewhere in my old school projects, if by the time i get home you don't have a satisfactory answer, i'll try to dig it up.
13 years ago
You can copy the string, delete all special characters you want to ignore in the string, and then apply the pattern.
13 years ago
A definition is... well in my opinion it is a word that should not be used on variables.
You can think of a definition when you declare and then assign a value to it if it is a variable or write its behavior when it is a method.
Example:

If you want more info on this, check this thread;

But you will see lots of documentation using define and declare as being the same thing. To be completely honest, you only see the difference between the both when talking about abstract methods.
13 years ago

Michael Rippee wrote:
I was meaning about Scanners being used to define variables as in,
int myVarible = myScanner.nextInt()



You are using "define" wrongly. When you give a variable any kind of value, you are assigning a value to the variable.

equals to

Meaning, you are assigning the value retrieved with myScanner.nextInt() to myVariable. the scanner does nothing regarding the definition of the variable.
13 years ago
To answer your first question, Scanner is an object. You can check the primitive types here, they are only a few and in no time you will know in a glance if something is of a primitive type or not.

What do you mean "scanners define variables"? You can be correct there, if you mean that Scanner can be a type of variable, but i am afraid you are falling into a huge mistake by meaning something else. Please elucidate better.

System.in represent the standard method of input (called standard input stream). Usually it will be the keyboard, but you can redirect System.in to something else, like a file. But as a start, consider System.in as the connection between Java and your keyboard.

About Scanners using different types of input... Scanners can be used to grab data from a lot of different sources. Sockets, Streams, input devices (keyboards, serial readers, usb connections, etc). Where you get the raw data is defined when you instantiate the Scanner.
13 years ago

Rob Spoor wrote:John, can you post the stack trace you're getting? Also, you are aware that both if statements require brackets {} to execute all lines below them? Right now they are only executing the first line directly after them; the other lines are always executed.


How did i miss that? ... That would probably fix your problem right there.
13 years ago
Thanks for the help. I have code to stop the application at a certain keystroke combo, so i can stop the automated mouse movement from there.
While the JScrollPane idea is quite ingenious, I'm afraid it won't work the way i want, because when the info panel first appears, it only appears partially (coming from the side), like in a slide show. I can combine your idea with my way of solving it, and draw the image in a growing rectangle each time i move the JScrollPane scroller. I'll check what happens and report back
13 years ago
Can you please give us the declaration of the atributes you are using?
Sounds like you are making use of a server, a secure connection to a web place, or controlling the access to a field. Showing us the declaration will help us help you .
13 years ago
I believe you are misunderstanding what scanner is doing for you. Please watch this following snip of code:

Your scaner (NumberOfDiceScanner) is retrieving the next int written by the user and storing it in NumberOfDice. After it you are using the Scanner itself, instead of the int where you store the input.
should become
A scanner is just a tool to get the user input/file content/socket stream etc etc etc... It is not the object that holds the content.

Since you are starting, you are in the right place to be taught about good programming:
An attribute/parameter/variable should always start with a lower-case letter (NumberOfDiceScanner -> numberOfDiceScanner).
13 years ago
Hello

I'm doing a just-for-fun personal project and i am facing a small problem.
My application consists of a world-map background and a "panel" foreground. Basically the program fetches news from different sites, identifies where the news refer to and shows the main image of the news and headline with a pointer pointing to the country it refers to. For example: regarding the turmoil in Greece, i would get the main image+headline in a small box and then an arrow pointing to Greece in the background map.

I found 2 problems:

1)The images+headlines are place in a panel with a JLabel + a second JPanel with a bufferedImage. I want that panel to "slide" on the x axis from width to 0. I managed to do it by rewriting paintComponent(Graphics g). Is there an easier/less mistake prone way of handling this?

2)This application will be running on my laptop, which i only use very sporadically at work to make fast direct queries to the server. The problem is that after some time the laptop goes into screensaver/sleep mode. I do not want to remove the screensaver or sleep mode permanently (i often forget the laptop at work...). Is there a way to block the screensaver/sleep from firing while the application is active?

Thanks a lot for the help

Daniel M.
13 years ago

Campbell Ritchie wrote:There is a keyword const in Java™. But it is never used.


I stand corrected. There is a const keyword. Have to say it surprises me that i never even heard of it, not even in very boring and very extensive theoretical java classes(college)... Live and learn!
13 years ago