Results 1 to 5 of 5
Thread: Buttons, listeners etc
- 01-16-2013, 01:26 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 24
- Rep Power
- 0
Buttons, listeners etc
Hello,
So at the moment my classes had me use my first button. Yay?
The interface raises the whole ActionEvent() method.
A couple of things. and I am just asking to be pointed to reading material or examples.
I determined that getActionCommand returns the label of a button.
//--short questions--//
How do I position buttons?
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 ?
//-Not even sure hwo to explain my troubles-//
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...
public void function1()
{
Graphics g = new Graphics();
g.drawString("Etc.",50,200,this.getImage());//or whatever would return that image context to a function
}
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... :(
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?
-
Re: Buttons, listeners etc
I am unaware of such a method.
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.How do I position buttons?
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.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 ?
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.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...
Java 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 may need to tell us more specifics. I am not sure what problems you might be having here.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'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.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?
- 01-16-2013, 05:39 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 24
- Rep Power
- 0
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.
- 01-16-2013, 05:50 AM #4
Member
- Join Date
- Jan 2013
- Posts
- 24
- Rep Power
- 0
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.
- 01-16-2013, 08:30 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Key Listeners
By wired-in=p in forum New To JavaReplies: 17Last Post: 09-17-2011, 08:27 PM -
two different Listeners
By Billaguana in forum New To JavaReplies: 8Last Post: 01-21-2011, 03:20 AM -
For some reason, my GUI is not recognizing multiple action listeners for buttons.
By JavaStudent1990 in forum New To JavaReplies: 8Last Post: 08-10-2010, 02:59 AM -
Help with Listeners
By Psyclone in forum AWT / SwingReplies: 8Last Post: 02-09-2010, 07:21 PM -
Seriously need help on my listeners!!
By themburu in forum Java AppletsReplies: 4Last Post: 05-26-2008, 10:41 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks