The Artima Developer Community
Sponsored Link

Java Answers Forum
Cursors in Java

3 replies on 1 page. Most recent reply: Sep 5, 2002 5:38 AM by Neva Mohammad

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Neva Mohammad

Posts: 28
Nickname: neva
Registered: Apr, 2002

Cursors in Java Posted: Aug 29, 2002 7:44 AM
Reply to this message Reply
Advertisement
I have four textfields on a page. All take some input and use the input for calculation. When I press the enter key in one textfield I'd like to move to the next textfield.
does anyone know how?
an example of what my program looks like:

textfield a, b, c

if (e.getSource() == a){
//and then some stuff here which refers to other methods.......
}
pls help!
thanks
Neva


Swaraj

Posts: 24
Nickname: swaraj
Registered: Mar, 2002

Re: Cursors in Java Posted: Aug 30, 2002 10:58 PM
Reply to this message Reply
Hi

for this you need to write a custom event handler for your keyboard actions, or use actionMap, when the enter key is press pass the focus to the next text field available.

Swaraj

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Cursors in Java Posted: Aug 31, 2002 8:07 AM
Reply to this message Reply
The applet code that follows can be downloaded from:
http://www.quantumhyperspace.com/applets/TextFieldAdvanceTest/TextFieldAdvanceTest.java

and is live at:
http://www.quantumhyperspace.com/applets/TextFieldAdvanceTest/TextFieldAdvanceTest.html



/* TextFieldAdvanceTest.java
* @author: Charles Bell
* @version: August 31, 2002

* Problem statement:
* I have four textfields on a page. All take some input and use the input
* for calculation. When I press the enter key in one textfield I'd like to
* move to the next textfield.
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class TextFieldAdvanceTest extends Applet implements ActionListener{

private TextField textFieldA, textFieldB, textFieldC, textFieldD;
private Button submit;
private TextArea messageArea;

public void init(){
textFieldA = new TextField(20);
textFieldB = new TextField(20);
textFieldC = new TextField(20);
textFieldD = new TextField(20);
textFieldA.addActionListener(this);
textFieldB.addActionListener(this);
textFieldC.addActionListener(this);
textFieldD.addActionListener(this);
add(new Label("A"));
add(textFieldA);
add(new Label("B"));
add(textFieldB);
add(new Label("C"));
add(textFieldC);
add(new Label("D"));
add(textFieldD);
submit = new Button("Submit");
submit.addActionListener(this);
add(submit);
messageArea = new TextArea(5,50);
add(messageArea);
}

public void actionPerformed(ActionEvent actionEvent){
Object source = actionEvent.getSource();
if (source.equals(textFieldA)){
messageArea.setText("Processing action from TextFieldA \nby requesting Focus for TextFieldB");
textFieldB.requestFocus();
}else if (source.equals(textFieldB)){
messageArea.setText("Processing action from TextFieldB \nby requesting Focus for TextFieldC");
textFieldC.requestFocus();
}else if (source.equals(textFieldC)){
messageArea.setText("Processing action from TextFieldC \nby requesting Focus for TextFieldD");
textFieldD.requestFocus();
}else if (source.equals(textFieldD)){
messageArea.setText("Processing action from TextFieldD \nby requesting Focus for TextFieldA");
textFieldA.requestFocus();
}else if (source.equals(submit)){
messageArea.setText("Processing action from Submit Button to submit form data.\n");
String aString = textFieldA.getText();
String bString = textFieldB.getText();
String cString = textFieldC.getText();
String dString = textFieldD.getText();
submitData(aString, bString, cString, dString);
}
}

public void submitData(String a, String b, String c, String d){
messageArea.append("Processed " + a + "\n" + b + "\n" + c + "\n" + d + "\n");
}
}

Neva Mohammad

Posts: 28
Nickname: neva
Registered: Apr, 2002

Re: Cursors in Java Posted: Sep 5, 2002 5:38 AM
Reply to this message Reply
Thanks Charles..I'm gonna try it out...

Flat View: This topic has 3 replies on 1 page
Topic: Java 2D: how to move drawn shape when image is rotated Previous Topic   Next Topic Topic: New to Java:  How Do You Average Numbers?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use