下面列出了java.awt.TextArea#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
TextAreaScrolling() {
try {
robot = new Robot();
} catch (Exception ex) {
throw new RuntimeException("Robot Creation Failed");
}
mainFrame = new Frame();
mainFrame.setSize(200, 200);
mainFrame.setLocation(200, 200);
textArea = new TextArea();
textArea.setText("1234 5678");
textArea.setSelectionStart(3);
textArea.setSelectionEnd(4);
mainFrame.add(textArea);
mainFrame.setVisible(true);
textArea.requestFocusInWindow();
}
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());
textArea = new TextArea(2, 10);
textArea.setSize(300, 100);
textArea.setText("123456 789123");
mainFrame.add(textArea);
mainFrame.setVisible(true);
textArea.requestFocusInWindow();
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);
final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
@Override
public void init() {
tf = new TextArea(3, 20);
tf.setText("0123456789");
tf.select(0, 6);
final TextArea ta = new TextArea("INSTRUCTIONS:\n"
+ "The text 012345 should be selected in the TextArea.\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);
}
@Override
public void init() {
tf = new TextArea(3, 20);
tf.setText("0123456789");
tf.select(0, 6);
final TextArea ta = new TextArea("INSTRUCTIONS:\n"
+ "The text 012345 should be selected in the TextArea.\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);
}
public void createAndShowInstructionFrame() {
Button passButton = new Button("Pass");
passButton.setEnabled(true);
Button failButton = new Button("Fail");
failButton.setEnabled(true);
TextArea instructions = new TextArea(12, 70);
instructions.setText(TEST_INSTRUCTIONS);
instructionFrame = new Frame("Test Instructions");
instructionFrame.add(passButton);
instructionFrame.add(failButton);
instructionFrame.add(instructions);
instructionFrame.setSize(200,200);
instructionFrame.setLayout(new FlowLayout());
instructionFrame.pack();
instructionFrame.setVisible(true);
passButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
});
failButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
throw new RuntimeException(FAIL_MESSAGE);
});
}
public void createAndShowInstructionFrame() {
Button passButton = new Button("Pass");
passButton.setEnabled(true);
Button failButton = new Button("Fail");
failButton.setEnabled(true);
TextArea instructions = new TextArea(12, 70);
instructions.setText(TEST_INSTRUCTIONS);
instructionFrame = new Frame("Test Instructions");
instructionFrame.add(passButton);
instructionFrame.add(failButton);
instructionFrame.add(instructions);
instructionFrame.setSize(200,200);
instructionFrame.setLayout(new FlowLayout());
instructionFrame.pack();
instructionFrame.setVisible(true);
passButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
});
failButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
throw new RuntimeException(FAIL_MESSAGE);
});
}
public EmailConfirmationDialog(Frame parent, String[] messages, String textArea) {
super(parent, true);
setTitle("Confirmation Dialog");
Font font = new Font("Courier", Font.PLAIN, 12);
setFont(font);
int rows = messages.length;
Panel textPanel = new Panel();
textPanel.setLayout(new GridLayout(rows,1));
for(int i = 0; i < rows; i++){
textPanel.add(new Label(messages[i]));
}
add("North", textPanel);
Panel textAreaPanel = new Panel();
TextArea ta = new TextArea(12,60);
ta.setText(textArea);
textAreaPanel.add(ta);
add("Center", textAreaPanel);
Panel p = new Panel();
p.setLayout(new FlowLayout());
Button yes = new Button("Yes");
yes.addActionListener(this);
p.add(yes);
Button no = new Button("No");
no.addActionListener(this);
p.add(no);
add("South", p);
setLocation(100, 200);
pack();
}
public void createAndShowInstructionFrame() {
Button passButton = new Button("Pass");
passButton.setEnabled(true);
Button failButton = new Button("Fail");
failButton.setEnabled(true);
TextArea instructions = new TextArea(12, 70);
instructions.setText(TEST_INSTRUCTIONS);
instructionFrame = new Frame("Test Instructions");
instructionFrame.add(passButton);
instructionFrame.add(failButton);
instructionFrame.add(instructions);
instructionFrame.setSize(200,200);
instructionFrame.setLayout(new FlowLayout());
instructionFrame.pack();
instructionFrame.setVisible(true);
passButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
});
failButton.addActionListener(ae -> {
dispose();
testContinueFlag = false;
throw new RuntimeException(FAIL_MESSAGE);
});
}
private void createInstructionUI() {
mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
layout = new GridBagLayout();
mainControlPanel = new Panel(layout);
resultButtonPanel = new Panel(layout);
GridBagConstraints gbc = new GridBagConstraints();
String instructions
= "INSTRUCTIONS:"
+ "\n 1. Click on the System Tray Icon"
+ "\n 2. Click on any of the displayed Menu items"
+ "\n 3. Repeat step 1 and count the number of items in the "
+ "Menu"
+ "\n 4. The number of items in the Menu should increase by 1"
+ "\n 5. Repeating steps 1, 2 and 3 should not break 4th step"
+ "\n 6. Click Fail if the 4th step is broken, Otherwise "
+ "click Pass ";
instructionTextArea = new TextArea();
instructionTextArea.setText(instructions);
instructionTextArea.setEnabled(false);
instructionTextArea.setBackground(Color.white);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainControlPanel.add(instructionTextArea, gbc);
passButton = new Button("Pass");
passButton.setName("Pass");
passButton.addActionListener(this);
failButton = new Button("Fail");
failButton.setName("Fail");
failButton.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
resultButtonPanel.add(passButton, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
resultButtonPanel.add(failButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
mainControlPanel.add(resultButtonPanel, gbc);
mainFrame.add(mainControlPanel);
mainFrame.pack();
mainFrame.setVisible(true);
}
public ActionEventTest() {
try {
robot = new Robot();
} catch(AWTException e) {
throw new RuntimeException(e.getMessage());
}
button = new Button("ClickMe");
button.setEnabled(true);
instructions = new TextArea(10, 50);
instructions.setText(
" This is a manual test\n" +
" Keep the Alt, Shift & Ctrl Keys pressed &\n" +
" Click 'ClickMe' button with left mouse button\n" +
" Test exits automatically after mouse click.");
add(button);
add(instructions);
setSize(400,400);
setLayout(new FlowLayout());
pack();
setVisible(true);
robot.waitForIdle();
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
int md = ae.getModifiers();
int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
| ActionEvent.SHIFT_MASK;
isProgInterruption = true;
mainThread.interrupt();
if ((md & expectedMask) != expectedMask) {
throw new RuntimeException("Action Event modifiers"
+ " are not set correctly.");
}
}
});
}