本文整理汇总了Java中java.awt.TextField.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java TextField.getWidth方法的具体用法?Java TextField.getWidth怎么用?Java TextField.getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.TextField
的用法示例。
在下文中一共展示了TextField.getWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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(TEXT + LAST_WORD, 30);
Panel panel = new Panel(new FlowLayout());
panel.add(textField);
frame.add(panel);
frame.setVisible(true);
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
toolkit.realSync();
Robot robot = new Robot();
robot.setAutoDelay(50);
Point point = textField.getLocationOnScreen();
int x = point.x + textField.getWidth() / 2;
int y = point.y + textField.getHeight() / 2;
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
robot.mousePress(InputEvent.BUTTON1_MASK);
int N = 10;
int dx = textField.getWidth() / N;
for (int i = 0; i < N; i++) {
x += dx;
robot.mouseMove(x, y);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
if (!textField.getSelectedText().endsWith(LAST_WORD)) {
throw new RuntimeException("Last word is not selected!");
}
}
示例2: 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(TEXT + LAST_WORD, 30);
Panel panel = new Panel(new FlowLayout());
panel.add(textField);
frame.add(panel);
frame.setVisible(true);
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.waitForIdle();
Point point = textField.getLocationOnScreen();
int x = point.x + textField.getWidth() / 2;
int y = point.y + textField.getHeight() / 2;
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_MASK);
int N = 10;
int dx = textField.getWidth() / N;
for (int i = 0; i < N; i++) {
x += dx;
robot.mouseMove(x, y);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
if (!textField.getSelectedText().endsWith(LAST_WORD)) {
throw new RuntimeException("Last word is not selected!");
}
}