Event/Listeners help
I have a frame titled personal profile where the user enters name(text field), address (text area), degree(radio button), and skills(check boxes). Then they click 'create profile' button. Once they do that a 2nd frame opens up and is suppose to display the information they just entered.
I can get the 2nd frame to open up, but I don't know how to get the user input on to this frame. I don't know if I need listeners on the radio buttons and check boxes and text fields? Any help is appreciated.
Any examples? Here is my code so far..
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Profile extends JFrame
private JRadioButton jrbBS, jrbMS, jrbPHD;
private JCheckBox jchkVisual = new JCheckBox("Visual Basic");
private JCheckBox jchkJava = new JCheckBox("Java");
private JCheckBox jchkServlets = new JCheckBox("Servlets and JSP");
private JCheckBox jchkDatabase = new JCheckBox("Database Programming");
public Profile()
//create a panel for radio buttons and group
JPanel jpRadioButtons = new JPanel();
jpRadioButtons.setLayout(new GridLayout(3,1));
jpRadioButtons.add(jrbBS = new JRadioButton("B.S"));
jpRadioButtons.add(jrbMS = new JRadioButton("M.S"));
jpRadioButtons.add(jrbPHD = new JRadioButton("Ph.D"));
ButtonGroup group = new ButtonGroup();
group.add(jrbBS);
group.add(jrbMS);
group.add(jrbPHD);
//create a panel for check boxes
JPanel jpCheckBoxes = new JPanel();
jpCheckBoxes.setLayout(new GridLayout(4, 1));
jpCheckBoxes.add(jchkVisual);
jpCheckBoxes.add(jchkJava);
jpCheckBoxes.add(jchkServlets);
jpCheckBoxes.add(jchkDatabase);
//Create a text area
JTextArea jtaAddress = new JTextArea(3,1);
jtaAddress.setLineWrap(true);
jtaAddress.setBackground(Color.red);
jtaAddress.setFont(new Font("Courier", Font.BOLD,12));
///Create a textfield
JTextField jtfName = new JTextField("", 10);
jtfName.setFont(new Font("Courier", Font.BOLD,12));
//create panel 1 for heading label
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1, 1));
//add label to the panel
p1.add(new JLabel("Personal Profile", SwingConstants.CENTER));
//create panel 2 for labels
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(4, 1));
p2.add(new JLabel("Name:"));
p2.add(new JLabel("Address:"));
p2.add(new JLabel("Degree:"));
p2.add(new JLabel("Skills:"));
//create panel 3 for textfields and check boxes
JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(4, 1));
p3.add(jtfName);
p3.add(jtaAddress);
p3.add(jpRadioButtons);
p3.add(jpCheckBoxes);
//create button
JButton jbtCreate = new JButton("Create Profile");
ActionListener listener = new CreateListener();
jbtCreate.addActionListener(listener);
//create panel for button
JPanel p4 = new JPanel();
p4.add(jbtCreate);
//Add contents into frame
add(p1, BorderLayout.NORTH);
add(p2, BorderLayout.WEST);
add(p3, BorderLayout.CENTER);
add(p4, BorderLayout.SOUTH);
private class CreateListener implements ActionListener
public void actionPerformed(ActionEvent e)
JFrame frame = new JFrame(" PROFILE CREATED ");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
frame.setLayout(new BorderLayout());
JPanel p5 = new JPanel();
p5.setLayout(new GridLayout(4, 1));
p5.add(new JLabel("Name:"));
p5.add(new JLabel("Address:"));
p5.add(new JLabel("Degree:"));
p5.add(new JLabel("Skills:"));
Message Panel messagePanel1 = new MessagePanel();
frame.add(p5, BorderLayout.WEST);
frame.add(p6, BorderLayout.CENTER);
public static void main(String[] args)
Profile frame = new Profile();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
Similar Messages
-
Help me I'm trying to create event listeners
I am trying to create event listeners
Whenever any keyboard event occurs the string s gets appended by a,c
or p.At the end of the program its supposed to print value of s
But s always happens to null.Please tell me how to correct it....so
that detection is possible for any case
import java.io.*;
import java.awt.event.*;
public class trial {
int x;
public static String s;
//OutputStream f1=new FileOutputStream("file2.txt");
public static void keyReleased(KeyEvent e)
s=s+"a";
public static void keyPressed(KeyEvent e)
s=s+"c";
public static void keyTyped(KeyEvent e)
s=s+"p";
public static void main(String args[])
throws IOException
char c;
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Entercharactes,'q' to quit.");
do
c=(char)br.read();
System.out.println(c);
while(c!='q');
// for(int i=0;i<s.length();++i)
System.out.println(s);I suggest looking at the java tutorial. Your code completely misses the mark and you need to see examples.
-
[JS] Basic question about event listeners and event handlers
I am very new to the whole topic of event listeners and event handlers. I'd run the test for the following problem myself, but I don't know where to start, and I just want to know if it's impossible -- that is, if I'm misunderstanding what event listeners and event handlers do.
Say I have an InDesign document with a text frame that is linked to an InCopy story. Can I use an "afterImport" event listener on the text frame to perform some action any time the link to the InCopy story gets updated? And will the event handler have access to both the story that is imported, and the pathname of the InCopy file?
Thanks.Thank you, Kasyan.
Both of those are good solutions.
We are currently using InDesign CS4 and InCopy CS5. I'm hoping to get them to purchase the whole CS5 suite soon, since I'd like to start writing scripts for InDesign CS5 as soon as possible, as long as I'm going to have to be doing it in the not too distant future anyway. The greater variety of event handlers sounds like it might be something that is crucial to the project I'm working on, so that adds to the argument for getting CS5.
Thanks again. You have no idea how helpful this is. I made some promises to my boss yesterday that I later realized were based on assumptions of mine about the InDesign/InCopy system that didn't make any sense, and I was going to have to retract my promises. But after reading your response I think I can still deliver, in a slightly different way that I had been thinking before.
Richard -
Documentation for custom event listeners
Hi,
I am searching in portal 8.1 documents for using custom events, coding and registering event listeners, and using them in jsp pages. So far my search has been unsuccessful.
Can some one let me know where i find this info?
-thanksHi J,
Thanks for your reply.
I didn’t find the custom work item Web Access control Official documents, but you can refer to the information in these articles(it’s same in TFS 2013):
http://blogs.msdn.com/b/serkani/archive/2012/06/22/work-item-custom-control-development-in-tf-web-access-2012-development.aspx
http://blogs.msdn.com/b/serkani/archive/2012/06/22/work-item-custom-control-development-in-tf-web-access-2012-deployment.aspx
For how to debug TFS Web Access Extensions, please refer to:
http://www.alexandervanwynsberghe.be/debugging-tfs-web-access-customizations/.
For the custom work item Web Access control Official documents, you can
submit it to User Voice site at: http://visualstudio.uservoice.com/forums/121579-visual-studio. Microsoft engineers will evaluate them seriously.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
JSP have event listeners???
Hi Would like to check if JSP have event listeners?? Eg.Like onblur that is used to activate javascript. Instead of calling a javascript function, can it call a JSP code or function.
Do JSP has functions like javascript?
Also does anyone know how if javabean is able to return a value and place it in a textfield on a JSP page??
Please help me I am going more and more headache
as mine deadline draws near....sign :(No.
JSP can have Java code as scriptlets, but tag libraries are preferred. I don't put any scriptlet code in my JSPs.
You can add a JavaBean to page, request, session, or application scope in a JSP page and access the properties that have getters. Then you can assign the values to a text field.
I don't know how tight your deadline is, but the best approach in my view is to use Java Standard Tag Library (JSTL). Jakarta has a free implementation. I'd also recommend reading Shawn Bayern's "JSTL In Action" book. You'll be up to speed with JSTL very quickly. It will provide a solution to what you're asking, if your deadline will allow you time to learn it. The book is very well-written and technically excellent, IMO. - MOD -
Managing various event listeners in multi-frame movie
I'm working on a gunslinger game. I have numerous frames
which correspond to different stages of the game. The frame that
corresponds to the actual gameplay has a really involved
ENTER_FRAME function attached to particular item on the stage. When
the game is over (or an error occurs, or the network connection
fails) I want to leave the gameplay frame and move to some other
frame. When this happens, I would like the ENTER_FRAME function on
the gunslinger to be removed because the player may finish a game
and then re-enter the gameplay frame later after selecting a new
opponent.
QUESTION: Can anyone recommend a good way to manage the
keyboard event listeners, all the button event listeners, etc? As
you might imagine, I have no reliable way to determine which frame
might be entered after the gameplay frame because the frame change
could be triggered by a variety of different reasons.I have tried using hasEventListener to check for an existing
ENTER_FRAME function before adding the event listener again but it
never seems to notice that there is an existing enterframe function
running. Furthermore, when I leave the frame, the enterframe
function (which is attached to a particular movie clip on frame 2)
continues to run even though that movie clip doesn't exist on any
other frame in the flash movie.
The first frame in my movie just has a button that takes the
movie to frame 2. frame 2 has a movie clip (myMovie) and a button
(btnFrame1) which goes back to frame 1. It also has the attached
actionscript.
I start the movie.
I click 'goto frame 2'
the enterframe listener is added and starts to output trace
statements of the current frame of myMovie (e.g., 1-2-3).
i click 'goto frame 1' on the main movie
although i am looking at frame 1 of my main movie which has
no instance of myMovie, the enterframe function keeps tracing the
current frame--interestingly, the frame of myMovie does not
advance...it stays on 1, 2, or 3 and announces that frame over and
over again.
Repeating the visit to frame 1 and frame2 over and over again
results in more listeners being added over and over again.
I have uploaded a sample FLA here:
http://jaith.net/questions/listenerExample.zip
I hope that you might help me determine how to remove the
listener upon exiting this frame. I don't want that enterframe
function running (and referring to movieclips that don't exist)
when I exit the frame where it is relevant. I'm wondering if I
should try adding the event listener to the root movie
instead. -
Is it possible to have event listeners apply to multiple objects, instead of creating multiple functions?
I'm just wondering if there is an easier way than making a new function for the same event listeners for each object I want to apply it to. Here's my code thus far, just to clarify what I'm talking about:
import gs.*;
var mc_homeX:Number = mc_home.x;
var mc_productsX:Number = mc_products.x;
var mc_msdsX:Number = mc_msds.x;
var mc_environmentX:Number = mc_environment.x;
mc_home.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
mc_home.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
function onOver(e:MouseEvent):void
TweenLite.to(e.target, .2, {x:mc_homeX-10});
function onOut(e:MouseEvent):void
TweenLite.to(e.target, .2, {x:mc_homeX});
I've only starting adding the listeners to mc_home, but I'd like to apply them to all. Any help would be appreciated. Thanks.import gs.*;
var mc_homeX:Number = mc_home.x;
var mc_productsX:Number = mc_products.x;
var mc_msdsX:Number = mc_msds.x;
var mc_environmentX:Number = mc_environment.x;
var mcA:Array=[mc_homeX,mc_productsX,etc];
for(var i:uint=0;i<mcA.length;i++){
mcA[i].addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
mcA[i].addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
function onOver(e:MouseEvent):void
TweenLite.to(e.target, .2, {x:mc_homeX-10});
function onOut(e:MouseEvent):void
TweenLite.to(e.target, .2, {x:mc_homeX});
I've only starting adding the listeners to mc_home, but I'd like to apply them to all. Any help would be appreciated. Thanks. -
I have a problem with the firing of event listeners. I have 4 functions (see below). Function f1 is triggered when button1 is clicked and function f3 is triggered when button3 is clicked. Then f1 calls getFileOperation (a webservice operation) and should call function f2 whereas function f3 should call function f4.
function f1 (event:MouseEvent):void
trace("f1 triggered");
getFileOperation.addEventListener(ResultEvent.RESULT, f2);
function f2 (ev:ResultEvent):void {
trace("f2 triggered");
function f3 (event:MouseEvent):void
trace("f3 triggered");
getFileOperation.addEventListener(ResultEvent.RESULT, f4);
function f4(e:ResultEvent):void {
trace("f4 triggered");
However the output being given when I press button1 followed by button2 is:
f1 triggered
f2 triggered
f3 triggered
f2 triggered ///repeated!!!
f4 triggered
Similarly the output being given when I press button2 followed by button1 is:
f3 triggered
f4 triggered
f1 triggered
f4 triggered ///repeated!!!
f2 triggered
Why is f2 fired again in the first case and f4 in the second case? How can I go about it to avoid this repetition. Any help would be appreciated...thanks!!I tried to change getFileOperation to getFileOperation2 in one of the functions as follows but same problem appeared.
function f3 (event:MouseEvent):void
trace("f3 triggered");
getFileOperation2.addEventListener(ResultEvent.RESULT, f4);
Do you have an idea how I can avoid the same function from triggering twice?? thanks a lot -
Does removeChild remove the object's event listeners?
Hi
If you dynamically create a parent movieclip, and dynamically add a color picker to each clip, and add an event listener for each color picker, does a removeChild on the parent movieClip remove event listeners belonging to any of it's children?
Thanks
ShaunAhh - thanks Ned
Is there any software you could recommend that monitors and shows you what or how many event listeners are open, memory consumption etc, to help you to trim the fat from your coding?
Thanks
Shaun -
How to block execution of event listeners
Hi all,
JDev version : 11.1.1.6
My requirement is that I want to block all event listeners like ActionListeners, SelectionListeners, DisclosureListeners, RowDisclosure listeners when the screen is opened in readonly mode.
I could block ActionListeners by disabling command links and command buttons etc.
But there's no way to block SelectionListeners, DisclosureListeners, RowDisclosure listeners.
So Is there any common code which can block all listeners?
Or is there any EventController or something like that which will allow me to control event execution?I would have if it was just one screen.
There are hundreds of screens.
Anyways, can't I use any javascript to do this? There are some interfaces like EventListeners , classes like EventConsumer etc. Do none of them provide feature to block event listeners? -
I can no longer create an event on iCal by double clicking on a time or date, nor can I double click on an existing event! HELP!
The only way I have to create an event is by using the "+" button, which is very limiting!
I am running the latest version of Mac OS X and all the updates.
Anyone know how I could get a proper use of my iCal ?
ThanksHi,
If you list the steps you have taken to fix this it will help.
Have you tried using the File > New Event menu item?
Have you logged the user account out/ restarted the computer?
Have you tried un-syncing any accounts synced to Calendar?
Is there some change made to the computer that may have triggered this?
Best wishes
John M -
Event Log Help Links No Longer Working?
Have the help links in the Windows XP event log entries been discontinued?
They used to open up the Help and Support Center with further information about the Event Log error if it was available.
For some time now they have all just given a "page not found" error, which then re-directs to Bing with offered results that are no use at all!
This happens now on every XP system I've tried it on.
As a user of Windows 8.1 as well as XP, I'm well aware that the Windows 8 Event Log help links have never worked so far, but the XP ones always did, and despite the looming "End of Support" I can see no reason for all that information to have been
removed.
Any explanation for this?
Thanks, Dave Hawley.Hi - thank you DaveHawley for the report. Just wanted to confirm that I've passed this on to the team that looks after the redirect service behind the "More Info" link.
There have been some major changes in how this redirection works over the years as well as in the last months. The most recent efforts added the option to enable use of the TechNet Wiki [sample]
to allow the community to comment & contribute for a given component. I'm only guessing here, but this might have accidentally impacted XP.
Thanks
Bruno -
Using Multiple Event Listeners
Hi,
I have a movielcip (A) class in which I have used a Tween class effect on a child movieclip (B) scrollRect. The (B) Movieclip in turn has several movieclips whose have tween class effect being executed on thier child movieclips.
the tweens are all unique to each movieclip
and the event listeners are taken off once completed.
This works all well and good in FLASH IDE...
My problem arises when I try to view this in a browser on a Windows XP
it doesnt work in
Opera Version 9.63
Firefox 2.0
and Google Chrome 2.0
The only browser it works fluently in is
Internet Explorer 7.0.5
What is happening in most cases it that the animation appears to "stick" but i think what may be happening is the listening or removal of the event listeners. The animations are left incompleted.
Is there any rule of thumb when using multiple event listeners?
here is a snippet of some of my code
on click event from movieclip (A)
private function scrollToSlidePrev(e:MouseEvent) {
if (((slideIndex - 1) >= 0)) {
nextButton.mouseEnabled = nextButton.enabled = previousButton.enabled = previousButton.mouseEnabled = false;
var position:Number = 0-SLIDEAREA.width;
var slide1:TileListSlide = slides[slideIndex] as TileListSlide;
var slide2:TileListSlide = slides[--slideIndex] as TileListSlide;
scrollSlide(position,slide1,slide2);
tween animation in movieclip (A) on (B)
private function scrollSlide(pos:int,slide1:TileListSlide,slide2:TileListSlide) {
slide1.resizeSlideTo(0.6); // execute tween on child movie clips in B
slide2.resizeSlideTo(1); // same as above;
var rect:Rectangle = sliderMc.scrollRect;
var tween1:Tween = new Tween(rect,"x",Regular.easeOut,rect.x,rect.x + pos,3,true);
tween1.addEventListener(TweenEvent.MOTION_CHANGE,setSliderScroll,false,4);
tween1.addEventListener(TweenEvent.MOTION_FINISH,toggleButtonEnabled,false,3);
tween animation in movieclip (B) children
public function resizeSlideTo(sc) {
var m:Matrix = tileList.transform.matrix as Matrix;
var p:Point = new Point (m.a, 0);
var tween2:Tween = new Tween(p,"x",Regular.easeOut,p.x,sc,3,true);
if (numericStepper != null) {
if (sc != 1) {
numericStepper.visible = false;
tween2.removeEventListener(TweenEvent.MOTION_FINISH,showStepper);
if (sc === 1) {
tween2.addEventListener(TweenEvent.MOTION_FINISH,showStepper,false,2);
tween2.addEventListener(TweenEvent.MOTION_CHANGE,setScaleOnScroll,false,3);
here is the link
http://visual_admin.web.aplus.net/ticker/ticker_widget.html
the effect disables and re-enables the buttons when its done.... then the listeners are removed.
each one with the exception cretes its own unique tween (obviously this is a custom class built as each clip)
i really don't know what to make of it guysapparantly making the tween a property of the class rather than a random variable in a function worked.....go figure
-
I have an external hard drive which has my i-photo on it & some movies from i-movie that I have on disk now. But for some reason my ehd has a caution symbol on it & I can't move my event to free up space on my hd so that I can export i-movie events. Help!
Usually the caution symbol means that it's formatted as a PC compatible format like NTFS or most likely FAT32. For iMovie to use it the ehd must be formatted Mac OS Extended. Then iMovie will show it without the caution symbol and you can drag/drop open any Event/Project from that hard drive.
To find out if it's formatted as PC:
Go to the desktop, holding down the Control key click on that ehd and in the pop-menu choose 'Get Info'
Under Format: It will say whether or not it's Mac OS Extended (Journaled). The only way to undo a PC formatted ehd would be to copy everything off of it first, Erase/Format the drive using Disk Utility in the Applications>Utilities folder on your Mac, choosing the Mac OS Extended (Journaled) format in the pull-down menu there. -
I just got a new iPhone 5. The sales person helped me transfer some photos from my MacBook Pro to the iPhone. Now, I can't get iPhoto to move photos from Photostream to events. Help!
Make sure you have iPhoto's Photo Stream preferences set as follows:
What happens when you drag photos from the Photo Stream window in iPhoto onto the Events icon in the left hand pane? That should import the photos into the library.
If it doesn't thenTry the following:
1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
User/Home/Library/ Preferences folder.
2 - delete iPhoto's cache file, Cache.db, that is located in your
User/Home/Library/Caches/com.apple.iPhoto folder (Snow Leopard and Earlier).
or with Lion and Mt. Lion from the User/Library/Containers/com.apple.iPhoto/
Data/Library/Caches/com.apple.iPhoto folder
3 - launch iPhoto, reset its various preferences and try again.
NOTE 1: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto. You'll also have to reset the iPhoto's various preferences.
NOTE 2: In Lion and Mountain Lion the Library folder is now invisible. To make it permanently visible enter the following in the Terminal application window: chflags nohidden ~/Library and hit the Enter button - 10.7: Un-hide the User Library folder.
OT
Maybe you are looking for
-
App hangs when I try to upload pix from my camera
I have iPhoto 11 on a MacBook Pro, vintage 2006, running OS 10.6.8. Launch is OK but the dreaded rotating rainbow appears when I try to upload photos from my camera. I can see them all with Preview so I know they are on the camera. I have reinsta
-
HR Programming : Problem with IDOC HRMD_A
Hello , We use Idoc HRMD_A for transferring PA records from one R3 system (ECC5) to another R3 system (46d). We have a problem - The Idoc doesn't check the data inserted against the database check tables and inserts wrong values into the target syste
-
NTFS Partition Doesn't Allow Programs To Access It [SOLVED]
Hello all, First of all, I have finally returned to Arch after several years of using Linux Mint. It feels good to be back in a bloatware-free environment, and I'm enjoying my 1 second boot times! Unfortunately, this hiatus has caused me to lose much
-
I just downloaded a new software update to my ipod touch and now the ipod and screen are frozen. I received a message that the download was not successful and now my screen is showing the blue round itunes symbol with an arrow pointing to the symbol
-
When I type a site into the address bar,and hit enter for it to go,it won't go,it used to. now i have to hit the lil green arrow and it's really annoying =/ this just suddenly happened. and ive uninstalled and reinstalled firefox. help?