Re: Buttons, listeners etc
Quote:
Originally Posted by
LaughingSeraph
The interface raises the whole ActionEvent() method.
I am unaware of such a method.
Quote:
How do I position buttons?
This is a specific version of the general question of how to layout components in a container. And the key is in learning about and using layout managers. Please Google and check out the tutorial with that name -- Laying out Components in a Container.
Quote:
Is there another way to to determine which button was pressed without performing logic on the caption? Something similar in nature to Button1.Click(), Button2.Click() from VC,VB etc ?
I think that most of us who use Swing a lot would use either anonymous ActionListeners -- small classes created on the spot for each button, or AbstractActions -- reusable classes that also implement the ActionListener interface. You can read about using Actions in the same Swing tutorials referred to above.
Quote:
lastly, this one is hard to explain.
Is there a way to drawString(), drawImage() etc from outside of paint? As in, can I declare a Graphics g in another function to pass it down to a method, and have THAT method paint to the main context define(apparently) by AWT in paint?
so like this...
Code:
public void function1()
{
Graphics g = new Graphics();
g.drawString("Etc.",50,200,this.getImage());//or whatever would return that image context to a function
}
You can draw directly to a BufferedImage in such a way, but you'll still want to display that image in a JPanel's paintComponent(...) override method, in other words in a "passive" way. It is a mind set that will take some getting used to, but the more you do it, the more you'll appreciate it.
Quote:
I ask this because it seems odd to call repaint() , when I am using a function to explore the raised events from getActionCommand(). This would allow me to check stuff without jamming everything into paint() so that I could see stuff when a button is clicked. Does that make sense? Am I just completely off my rocker with the methodology or logic in Java? For me this is confusing as it is the simplest thing in certain languages, and is apparently a miracle to perform in java... :(
You may need to tell us more specifics. I am not sure what problems you might be having here.
Quote:
I don't even know where to start looking to produce the equivalent to This->Form1.text1.Text = getActionCommand();
Does java have a way to print to the little applet window like cout in c++ or print in Basic?
You're better off not trying to shoehorn C++ or Basic techniques into your Java code. They approach things differently, and you will want to learn how to do thing the Java way to be able to use it best.
Re: Buttons, listeners etc
Thanks!
I will explore that stuff and come back to it.
I am not trying to shoehorn methodologies in for the record, I just don't know how else to explain what it was I was trying to accomplish.
I am basically just looking for a way to easily print out the returns from these 'interfaces' such as getCommandAction() without having to go back into the paint method. I am new enough, that I don't quit understand what is happening there.
For instance, todays lesson I used that button and teh getCommandAction() returned was the buttons label String from its declaration. There is ALOT of stuff in the api documentation about listeners.So I was just trying to find out what each list, button, radiobutton etc was returned with that call.
Anyway, thanks. It looks like that googel search and the resulting tutorial has a great deal of information to digest.
Re: Buttons, listeners etc
System.println and System.out appear to be what I was looking for. I will check them out tomorrow and mark this as solved if they work.
Yeah, that set of tutorials in pretty solid.
<Solved>Re: Buttons, listeners etc
The tutorials and methods mentioned did what I needed.