Solved

More on the TextField Question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

746 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

10 Experts available now in Live!

Get 1:1 Help Now