本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
示例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);
}
示例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!");
}
}
示例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!");
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 ());
}
示例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);
}