当前位置: 首页>>代码示例>>Java>>正文


Java TextField类代码示例

本文整理汇总了Java中java.awt.TextField的典型用法代码示例。如果您正苦于以下问题:Java TextField类的具体用法?Java TextField怎么用?Java TextField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextField类属于java.awt包,在下文中一共展示了TextField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TFFrame

import java.awt.TextField; //导入依赖的package包/类
public TFFrame() {
	TextField tf = new TextField();
	add(tf);
	tf.addActionListener(new TFActionListener());
	tf.setEchoChar('*');
	pack();
	setVisible(true);
}
 
开发者ID:limengbo,项目名称:youyoulearning,代码行数:9,代码来源:TFActionEvent.java

示例2: init

import java.awt.TextField; //导入依赖的package包/类
@Override
public void init() {
this.setVisible(true);
this.setSize(500, 500);
this.setBackground(Color.green);
this.setLayout(new FlowLayout());

l1 = new Label("User Name");
l2 = new Label("Password");
tf1 = new TextField(20);
tf2 = new TextField(20);
tf2.setEchoChar('*');
b = new Button("Login");
b.addActionListener(this);

Font font = new Font("arial", Font.BOLD, 25);
l1.setFont(font);
l2.setFont(font);
tf1.setFont(font);
tf2.setFont(font);
b.setFont(font);

this.add(l1);
this.add(tf1);
this.add(l2);
this.add(tf2);
this.add(b);

}
 
开发者ID:pratikdimble,项目名称:Servlet_Applet_Communication,代码行数:30,代码来源:LoginApplet.java

示例3: init

import java.awt.TextField; //导入依赖的package包/类
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SelectionVisible.java

示例4: OverScrollTest

import java.awt.TextField; //导入依赖的package包/类
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textField = new TextField(10);
    textField.setSize(300, 100);
    textField.setText("123456 789123");
    mainFrame.add(textField);
    mainFrame.setVisible(true);
    textField.requestFocusInWindow();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:OverScrollTest.java

示例5: actionPerformed

import java.awt.TextField; //导入依赖的package包/类
public void actionPerformed(ActionEvent ev) {

        String s = ev.getActionCommand();

        if (s.equals("ConnectOk") || (ev.getSource() instanceof TextField)) {
            try {
                if (mURL.getText().indexOf('\u00AB') >= 0) {
                    throw new Exception("please specify db path");
                }

                mConnection = createConnection(mDriver.getText(),
                                               mURL.getText(),
                                               mUser.getText(),
                                               mPassword.getText());

                if (mName.getText() != null
                        && mName.getText().trim().length() != 0) {
                    ConnectionSetting newSetting =
                        new ConnectionSetting(mName.getText(),
                                              mDriver.getText(),
                                              mURL.getText(), mUser.getText(),
                                              mPassword.getText());

                    ConnectionDialogCommon.addToRecentConnectionSettings(
                        settings, newSetting);
                }

                dispose();
            } catch (java.io.IOException ioe) {
                dispose();
            } catch (Exception e) {
                e.printStackTrace();
                mError.setText(e.toString());
            }
        } else if (s.equals("ConnectCancel")) {
            dispose();
        }
    }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:39,代码来源:ConnectionDialog.java

示例6: main

import java.awt.TextField; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:DeadKeySystemAssertionDialog.java

示例7: initTestWindow

import java.awt.TextField; //导入依赖的package包/类
public static void initTestWindow() {
    mainFrame = new Frame();
    p1 = new Panel();
    mainFrame.setTitle("TestWindow");
    mainFrame.setBounds(700, 10, 400, 100);

    tf = new TextField(20);
    tf.select(0, 10);
    bt = new Button("Disable textfield");
    p1.add(tf);
    p1.add(bt);
    mainFrame.add(p1);
    bt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            tf.setEditable(false);
        }
    });
    mainFrame.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:DisabledUndoTest.java

示例8: testFocus

import java.awt.TextField; //导入依赖的package包/类
static void testFocus() throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:MultiResolutionSplashTest.java

示例9: testFocus

import java.awt.TextField; //导入依赖的package包/类
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();
        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:UnixMultiResolutionSplashTest.java

示例10: main

import java.awt.TextField; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        frame.setVisible(true);
        robot.waitForIdle();

        textField.requestFocus();
        robot.waitForIdle();

        // Check that the system assertion dialog does not block Java
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        frame.setVisible(false);
        frame.dispose();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:DeadKeySystemAssertionDialog.java

示例11: fixtext

import java.awt.TextField; //导入依赖的package包/类
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string330 = "\\";
    String string331 = "";
    int i = 0;
    int i332 = -1;
    rd.setFont(new Font("Arial", 1, 12));
    ftm = rd.getFontMetrics();
    for (/**/; i < string.length(); i++) {
        final String string333 = "" + string.charAt(i);
        if (string333.equals("|") || string333.equals(",") || string333.equals("(") || string333.equals(")") || string333.equals("#") || string333.equals(string330) || string333.equals("!") || string333.equals("?") || string333.equals("~") || string333.equals(".") || string333.equals("@") || string333.equals("$") || string333.equals("%") || string333.equals("^") || string333.equals("&") || string333.equals("*") || string333.equals("+") || string333.equals("=") || string333.equals(">") || string333.equals("<") || string333.equals("/") || string333.equals(";") || string333.equals(":") || ftm.stringWidth(string331) > 274) {
            i332 = i;
        } else {
            string331 = "" + string331 + string333;
        }
    }
    if (i332 != -1) {
        textfield.setText(string331);
        textfield.select(i332, i332);
    }
}
 
开发者ID:uwx,项目名称:OpenNFMM,代码行数:23,代码来源:StageMaker.java

示例12: fixtext

import java.awt.TextField; //导入依赖的package包/类
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string64 = "\\";
    String string65 = "";
    int i = 0;
    int i66 = -1;
    for (/**/ ; i < string.length(); i++) {
        final String string67 = "" + string.charAt(i);
        if (string67.equals("|") || string67.equals(",") || string67.equals("(") || string67.equals(")") || string67.equals("#") || string67.equals(string64) || string67.equals("!") || string67.equals("?") || string67.equals(" ") || string67.equals("~") || string67.equals("$") || string67.equals("%") || string67.equals("^") || string67.equals("&") || string67.equals("*") || string67.equals("+") || string67.equals("=") || string67.equals(">") || string67.equals("<") || string67.equals("/") || string67.equals("'") || string67.equals(";") || string67.equals(":") || string67.equals("\u00a0")) {
            i66 = i;
        } else {
            string65 = "" + string65 + string67;
        }
    }
    if (i66 != -1) {
        textfield.setText(string65);
        textfield.select(i66, i66);
    }
}
 
开发者ID:uwx,项目名称:OpenNFMM,代码行数:21,代码来源:Login.java

示例13: fixtext

import java.awt.TextField; //导入依赖的package包/类
private void fixtext(final TextField textfield) {
    String string = textfield.getText();
    string = string.replace('\"', '#');
    final String string360 = "\\";
    String string361 = "";
    int i = 0;
    int i362 = -1;
    for (/**/; i < string.length(); i++) {
        final String string363 = "" + string.charAt(i);
        if (string363.equals("|") || string363.equals(",") || string363.equals("(") || string363.equals(")") || string363.equals("#") || string363.equals(string360) || string363.equals("!") || string363.equals("?") || string363.equals("~") || string363.equals(".") || string363.equals("@") || string363.equals("$") || string363.equals("%") || string363.equals("^") || string363.equals("&") || string363.equals("*") || string363.equals("+") || string363.equals("=") || string363.equals(">") || string363.equals("<") || string363.equals("/") || string363.equals("'") || string363.equals(";") || string363.equals(":") || i > 15) {
            i362 = i;
        } else {
            string361 = "" + string361 + string363;
        }
    }
    if (i362 != -1) {
        textfield.setText(string361);
        textfield.select(i362, i362);
    }
}
 
开发者ID:uwx,项目名称:OpenNFMM,代码行数:21,代码来源:CarMaker.java

示例14: create

import java.awt.TextField; //导入依赖的package包/类
void create ()
{
  Font f = awtComponent.getFont ();

  // By default, Sun sets a TextField's font when its peer is
  // created.  If f != null then the peer's font is set by
  // GtkComponent.create.
  if (f == null)
    {
      f = new Font ("Dialog", Font.PLAIN, 12);
      awtComponent.setFont (f);
    }

  FontMetrics fm = getFontMetrics (f);

  TextField tf = ((TextField) awtComponent);
  int cols = tf.getColumns ();

  int text_width = cols * fm.getMaxAdvance ();

  create (text_width);

  setEditable (tf.isEditable ());
}
 
开发者ID:vilie,项目名称:javify,代码行数:25,代码来源:GtkTextFieldPeer.java

示例15: TiledImageComponent

import java.awt.TextField; //导入依赖的package包/类
/** Set things up nicely. */
public TiledImageComponent() {

    setLayout(new FlowLayout());
    add(new Label("Name:", Label.CENTER));
    add(nameTF=new TextField(10));

    add(new Label("Password:", Label.CENTER));
    add(passTF=new TextField(10));
    passTF.setEchoChar('*');

    add(new Label("Domain:", Label.CENTER));
    add(domainTF=new TextField(10));

    im = getToolkit().getImage(DEFAULT_IMAGE_NAME);
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:17,代码来源:TiledImageComponent.java


注:本文中的java.awt.TextField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。