本文整理汇总了Java中java.awt.TextField.setText方法的典型用法代码示例。如果您正苦于以下问题:Java TextField.setText方法的具体用法?Java TextField.setText怎么用?Java TextField.setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.TextField
的用法示例。
在下文中一共展示了TextField.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: mouseClicked
import java.awt.TextField; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1) // Double-click
{
TextField text;
String title;
if (e.getSource() == text1)
{
text = text1;
title = "Coordinate_file_1";
}
else
{
text = text2;
title = "Coordinate_file_2";
}
String[] path = decodePath(text.getText());
OpenDialog chooser = new OpenDialog(title, path[0], path[1]);
if (chooser.getFileName() != null)
{
text.setText(chooser.getDirectory() + chooser.getFileName());
}
}
}
示例7: mouseClicked
import java.awt.TextField; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1 && e.getSource() instanceof TextField) // Double-click
{
TextField tf = (TextField) e.getSource();
String path = tf.getText();
boolean recording = Recorder.record;
Recorder.record = false;
if (tf == textParamFile)
{
path = Utils.getFilename("Choose_a_parameter_file", path);
}
else
{
path = Utils.getDirectory("Choose_a_directory", path);
}
Recorder.record = recording;
if (path != null)
tf.setText(path);
}
}
示例8: initTestWindow
import java.awt.TextField; //导入方法依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame("ScrollSelectionTest frame");
mainFrame.setBounds(500, 0, 400, 200);
textField = new TextField(40);
textField.setText("abcdefghijklmnopqrstuvwxyz");
mainFrame.add(textField);
mainFrame.setLayout(new FlowLayout());
textField.select(0, 20);
mainFrame.setVisible(true);
}
示例9: testConstructor2
import java.awt.TextField; //导入方法依赖的package包/类
private void testConstructor2() {
textField = new TextField(30);
textField.setSize(200, 100);
mainFrame.add(textField);
textField.setText(testStrEOL);
checkTest();
mainFrame.remove(textField);
}
示例10: testSetText
import java.awt.TextField; //导入方法依赖的package包/类
private void testSetText() {
textField = new TextField();
textField.setSize(200, 100);
textField.setText(testStrEOL);
mainFrame.add(textField);
checkTest();
mainFrame.remove(textField);
}
示例11: dialogItemChanged
import java.awt.TextField; //导入方法依赖的package包/类
@Override
public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
if (!DialogModifier.allNumbersValid(gd.getNumericFields()))
return false;
final Vector<?> checkboxes = gd.getCheckboxes();
final Vector<?> nFields = gd.getNumericFields();
final Checkbox calibration = (Checkbox) checkboxes.get(10);
final boolean isHUCalibrated = calibration.getState();
final TextField minT = (TextField) nFields.get(0);
final TextField maxT = (TextField) nFields.get(1);
final double min = Double.parseDouble(minT.getText());
final double max = Double.parseDouble(maxT.getText());
if (isHUCalibrated && !fieldUpdated) {
minT.setText("" + cal.getCValue(min));
maxT.setText("" + cal.getCValue(max));
fieldUpdated = true;
}
if (!isHUCalibrated && fieldUpdated) {
minT.setText("" + cal.getRawValue(min));
maxT.setText("" + cal.getRawValue(max));
fieldUpdated = false;
}
if (isHUCalibrated)
DialogModifier.replaceUnitString(gd, "grey", "HU");
else
DialogModifier.replaceUnitString(gd, "HU", "grey");
final Checkbox oriented = (Checkbox) checkboxes.get(9);
if (orienteer == null) {
oriented.setState(false);
oriented.setEnabled(false);
} else
oriented.setEnabled(true);
DialogModifier.registerMacroValues(gd, gd.getComponents());
return true;
}
示例12: handleName
import java.awt.TextField; //导入方法依赖的package包/类
protected synchronized void handleName(NameCallback c)
{
Frame ownerFrame = new Frame();
Dialog dialog = new Dialog(ownerFrame);
dialog.setTitle(c.getPrompt());
dialog.setLayout(new GridLayout(3, 1));
Label label = new Label(c.getPrompt());
TextField input = new TextField();
if (c.getDefaultName() != null)
{
input.setText(c.getDefaultName());
}
Panel buttons = new Panel();
Button ok = new Button(messages.getString("callback.ok"));
ok.setActionCommand(ACTION_OK);
ok.addActionListener(this);
Button cancel = new Button(messages.getString("callback.cancel"));
cancel.setActionCommand(ACTION_CANCEL);
cancel.addActionListener(this);
dialog.add(label);
dialog.add(input);
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttons.add(ok);
buttons.add(cancel);
dialog.add(buttons);
dialog.pack();
dialog.show();
try { wait(); }
catch (InterruptedException ie) { }
if (actionCommand.equals(ACTION_OK))
{
c.setName(input.getText());
}
dialog.dispose();
ownerFrame.dispose();
}
示例13: validateFloatEdit
import java.awt.TextField; //导入方法依赖的package包/类
private static boolean validateFloatEdit(
TextField theField,
double minValue,
double maxValue) {
StringTokenizer fieldTokenizer
= new StringTokenizer(theField.getText());
if (!fieldTokenizer.hasMoreElements()) {
theField.setText("Error--No Data");
return false;
}
else {
String fieldString =
fieldTokenizer.nextToken();
try {
double fieldValue =
new Double(fieldString)
.doubleValue();
if (fieldValue < minValue ) {
theField.setText("Value Too Low");
return false;
}
else if (fieldValue < minValue ) {
theField.setText("Value Too High");
return false;
}
}
catch (Throwable e ) {
theField.setText("Data Error");
return false;
}
}
if (fieldTokenizer.hasMoreElements()) {
theField.setText("Data Error");
return false;
}
else {
return true;
}
}
示例14: validateIntegerEdit
import java.awt.TextField; //导入方法依赖的package包/类
private static boolean validateIntegerEdit(
TextField theField,
int minValue,
int maxValue) {
StringTokenizer fieldTokenizer
= new StringTokenizer(theField.getText());
if (!fieldTokenizer.hasMoreElements()) {
theField.setText("Error--No Data");
return false;
}
else {
String fieldString =
fieldTokenizer.nextToken();
try {
int fieldValue =
new Integer(fieldString)
.intValue();
if (fieldValue < minValue ) {
theField.setText("Value Too Low");
return false;
}
else if (fieldValue > maxValue ) {
theField.setText("Value Too High");
return false;
}
}
catch (Throwable e ) {
theField.setText("Data Error");
return false;
}
}
if (fieldTokenizer.hasMoreElements()) {
theField.setText("Data Error");
return false;
}
else {
return true;
}
}
示例15: createTextPanel
import java.awt.TextField; //导入方法依赖的package包/类
private Panel createTextPanel(TextField textField, String label, String value)
{
Panel panel = new Panel();
panel.setLayout(new BorderLayout());
Label listLabel = new Label(label, 0);
//listLabel.setFont(monoFont);
//textField.setSize(fontWidth * 3, fontWidth);
textField.setText(value);
panel.add(listLabel, BorderLayout.WEST);
panel.add(textField, BorderLayout.CENTER);
return panel;
}