Solved

More on the TextField Question

Posted on 1997-03-30
3
180 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
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 10 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now