Results 1 to 3 of 3
Thread: GUI's
- 12-22-2008, 06:47 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
GUI's
Hey guys. I've recently started learning about GUI's, action events, and that whole shindig... I've been doing exercises out of my textbook. I recently got an exercise where I have to make a GUI with a text field and two buttons, one called upper case and one called lower case. When I press the upper case one it's supposed to make whatever I type in the text field turn upper case, and vice versa for the lower version. What I'm confused about is how exactly to write these two action listeners.
Every example that I've seen in the book embeds the action listener in the client program. However I don't see how I'd have an actionPerformed method for both the upper and lower case buttons inside the client program so I'd probably have to make two separate classes.
Now what confuses me about that is that the actionPerformed method, as far as I understand, is supposed to have something like textField.setText(textField.getField().toUpperCase ()) or vice versa for the lower case one. How would I be able to edit the textField from the client program through the separate action listener though??
Also, another question: one of the answer solutions to one of the exercises uses an action listener that is a private class that is INSIDE the public class that creates the GUI. How do these private classes work and what are their strengths/limitations? I never even knew these existed and the book never spoke of them.
Thanks a lot - knowing how to do use multiple action listeners to edit the components' fields will make the rest of the exercises a lot easier.
- 12-22-2008, 07:25 PM #2
The private classes inside your public classes are called nested inner classes. These are very useful for listeners in particular(I have limited experience with them so google for more info)
As for your listeners. Attach them directly to the buttons.
Java Code:toLowerCaseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // // put your code in here to get the text and change the text // } });
Now what confuses me about that is that the actionPerformed method, as far as I understand, is supposed to have something like textField.setText(textField.getField().toUpperCase ()) or vice versa for the lower case one. How would I be able to edit the textField from the client program through the separate action listener though??Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
- 12-22-2008, 10:19 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
Similar Threads
-
Creating GUI's for simulators.
By Modifier in forum New To JavaReplies: 3Last Post: 11-20-2008, 01:35 AM
Bookmarks