?
Solved

More on the TextField Question

Posted on 1997-03-30
3
Medium Priority
?
185 Views
Last Modified: 2010-04-16
Here is more detail on my textfield question.

The program is given below:

In it the method Constraint(), just provide a position on
the panel.

What happends is the textfiled will show on the panel,
and when I click on it, it does recognize as an event.
event.targer = textfield1; but I can not enter any thing
in the textfield.  I wonder what happens.

P.S. The points on the other one will also be given
if you can help me.  Thank you.:
import java.io.*;
import java.awt.*;
import java.util.*;

public class EditLogin extends Frame {
      String temp,temp1,temp2,temp3,temp4;
      TextField textfield1;
      
      Panel panel1;
      GridBagLayout gridbag = new GridBagLayout();

      public EditLogin(String title)
      {
        super(title);

        panel1 = new Panel();
        panel1.setLayout(gridbag);

        textfield1 = new TextField(10);

        constrain(panel1,textfield1,0,5,1,1);

        this.setLayout(gridbag);
        constrain(this,panel1,0,0,1,1,GridBagConstraints.VERTICAL,
              GridBagConstraints.NORTHWEST,0.0,1.0,10,10,5,5);


      }

      public boolean handleEvent(Event event)
      {
      
            if (event.target == textfield1)
            { textarea.setText("Entering Text\n");
              temp1 = textfield1.getText();
              textarea.appendText(astring+"\n");
            }

            return true;
      }  
 

      public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int fill, int anchor, double weight_x, double weight_y,
                  int top, int left, int bottom, int right)
    {
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = grid_x; c.gridy = grid_y;
        c.gridwidth = grid_width; c.gridheight = grid_height;
        c.fill = fill; c.anchor = anchor;
        c.weightx = weight_x; c.weighty = weight_y;
        if (top+bottom+left+right > 0)
            c.insets = new Insets(top, left, bottom, right);
       
        ((GridBagLayout)container.getLayout()).setConstraints(component, c);
        container.add(component);
    }
   
    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.CENTER, 0.0, 0.0, 0, 0, 0, 0);
    }
   
    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int top, int left, int bottom, int right) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.CENTER,
              0.0, 0.0, top, left, bottom, right);
    }

      public static void main(String[] args) {
            Frame editlog = new EditLogin("Edit Login");
            editlog.pack();
            editlog.show();
      }
}

0
Comment
Question by:jiayan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:cyberwolf
ID: 1219319
Perhaps you need to request focus for the textfield?
0
 

Author Comment

by:jiayan
ID: 1219320
solved already by using action() instead of eventhandler()
0
 
LVL 1

Accepted Solution

by:
Arkadiy earned 20 total points
ID: 1219321
The reason you cannopt edit is that your hgandleEvent returns true! TextField.handleEvent gets the event before the native code in TextFieldPeer.handleEvent, and when you return true from EditLogin.handleEvent, TextFieldPeer.handleEvent is not called. true in this case means "I processed it, do not call anything else". Return  true only if you do not want the event to be seen by anything else.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question