Solved

More on the TextField Question

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services spring boot application error 3 199
HashTable highest marks enumeration alternative 9 39
throw exception 21 44
Chrome and Firefox Java 5 34
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 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