Onward to Java

Onward to Java

Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
1) Already mentioned in chat for no adequately thought-through reason:
Eclipse gives me this warning in one of my classes:
Quote:
The serializable class does not declare a static final serialversionuid field of type long


I googled it, and it has to do with serialization (surprisingly...). Now apparently, I can simply ignore this, but is serialization something useful/important enough that I should read up on it, or can I simply ignore this warning?



2) I'm making a simple program that starts as a window (JFrame) with 4 buttons (each of type MyButton). MyButton is a subclass of JButton with an ActionListener that opens a new window when the button is pressed, depending on what title was passed as the MyButton argument. E.g. if you click the button titled Calculator, it'll open a new window with a calculator (another JFrame window that I'll be creating later).

However, I want it to work so that if that window is already opened, it doesn't open another one, but simply activates the already opened window.

So a) how do I check if a window is already opened?
and b) how do I activate that window?
Also c) what exactly does it mean if something is "visible"? If I setVisible(false) a window, does it close or just become invisible?
And if I setVisible(false) a text field, does it deactivate (ie. you can't write anything into it anymore) or does it just become hidden?

3) Is there a way to remove content from a window? Ie. the opposite of add(element).
EDIT: found remove(element)

4) How do I deactivate an element (not delete or make invisible, just make it gray and inoperative)?
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Feb 23 at 23:53 UTC — Ed. 2012 Feb 25 at 17:41 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
Mate de Vita said:
2) I'm making a simple program that starts as a window (JFrame) with 4 buttons (each of type MyButton). MyButton is a subclass of JButton with an ActionListener that opens a new window when the button is pressed, depending on what title was passed as the MyButton argument. E.g. if you click the button titled Calculator, it'll open a new window with a calculator (another JFrame window that I'll be creating later).

However, I want it to work so that if that window is already opened, it doesn't open another one, but simply activates the already opened window.

So a) how do I check if a window is already opened?
and b) how do I activate that window?
Also c) what exactly does it mean if something is "visible"? If I setVisible(false) a window, does it close or just become invisible?
And if I setVisible(false) a text field, does it deactivate (ie. you can't write anything into it anymore) or does it just become hidden?

3) Is there a way to remove content from a window? Ie. the opposite of add(element).

So, for the second bit I'd have a field called isOpen, which, when you press the button, is tested. Then you can make the decision whether to open a new window or not. I am not sure what you mean by activated. If you look at the Java API then you will see what setVisible(true) does; basically it stops it being displayed but does not "destroy" it.
 
 
 
2012 Feb 24 at 00:15 UTC
Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
Down Rodeo said:
I am not sure what you mean by activated.

Activate as in restore, put on top, etc. Like if you had clicked on it.
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Feb 24 at 11:25 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
I was drunk when I wrote this, I'm sorry. Well, in that case you can have setVisible(false) and that sort of thing. Does that make sense to you?
 
 
 
2012 Feb 24 at 18:21 UTC
Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
Down Rodeo said:
I was drunk when I wrote this, I'm sorry. Well, in that case you can have setVisible(false) and that sort of thing. Does that make sense to you?

Not exactly sure what you mean :/
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Feb 25 at 17:35 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
Oh, I think I am misunderstanding you. Perhaps a more full description of what you're trying to do would help :) I have to confess, my knowledge of swing and all that nonsense is... Poor. I hate it actually, it is the single worst kind of programming, though I admit it feels nice when you have a sexy GUI. It's all kinds of pain though.
 
 
 
2012 Feb 26 at 19:46 UTC
Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
Well, the way it is now is, I open the main window and then click on one of the four buttons on it. That opens another window with a certain tool (e.g. calculator), depending on which of the four buttons was pressed. Now if I press that same button again, it'll open another window with that same tool. I don't want that.

What I want is that if I press that button again, it restores the window that was opened by that button (if it was minimized) and puts it on top as the currently active window.

In other words I want the same thing to happen when I press that button, as if I clicked with my mouse on that opened window.
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Feb 26 at 22:55 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
Ok, that should be easy: have if(isOpened()) { calc.setFocus() } else { calc.open() } or something similar. isOpened() should return a boolean indicating whether the calculator has, in fact, been opened before. EDIT: it's requestFocus(), I think.
 
 
 
2012 Feb 27 at 00:43 UTC — Ed. 2012 Feb 27 at 00:45 UTC
Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
Down Rodeo said:
Ok, that should be easy: have if(isOpened()) { calc.setFocus() } else { calc.open() } or something similar. isOpened() should return a boolean indicating whether the calculator has, in fact, been opened before. EDIT: it's requestFocus(), I think.

OK, once I get all these errors out of the way, I'll try it.
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Feb 28 at 10:08 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
OK, I realise I wasn't completely clear there; you probably got this but what I'm saying is that these are methods you should implement yourself, I do not know that they necessarily exist right now. Apologies.
 
 
 
2012 Feb 28 at 22:56 UTC
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
DR, when did your title change!
 
 
 
2012 Feb 29 at 17:30 UTC
Rockbomb
Dog fucker (but in a good way now)

2009 Nov 14 • 2045
sprinkles said:
DR, when did your title change!

He's had that title for as long as I can remember. Albeit, that's not very long, but still long enough for it to be significant.
 
 
 
2012 Feb 29 at 17:57 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
There was a thing ages back where AaronJer changed it from admin pupae to chrysalis to moth or something else. I said that I'd always wanted to be Firehouse Captain (awarded way back for 1024 posts) but I'd never been there. Before that I was Fuckhead, I think.
 
 
 
2012 Mar 1 at 00:00 UTC
Mate de Vita
Kelli

2008 Oct 4 • 2453
159 ₧
Down Rodeo said:
OK, I realise I wasn't completely clear there; you probably got this but what I'm saying is that these are methods you should implement yourself, I do not know that they necessarily exist right now. Apologies.

requestFocus() is an already existing method, according to Google results. I haven't really searched for an isOpened() method, but even if it doesn't exist, it shouldn't be too hard to implement.
...and that's the bottom line because Mate de Vita said so.
 
 
 
2012 Mar 1 at 00:22 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
Yeah, I'm being all over the place here. If you're lucky (unlucky) tomorrow I might draw a little diagram with what I am blethering about drawn on it. Sounds like you at least have an idea though.
 
 
 
2012 Mar 1 at 01:04 UTC
Page [1]