The following program examples demonstrate the Textarea input handling in java. This textarea input can be made with a JTextArea object. The program will display two text-area where most or all of the selected text in text-area first to be copied / moved to a second text-area.
Here is the display program:
Here is an example program
01 import java.awt .*;
02
03 import java.awt.event .*;
04
05 import javax.swing .*;
06
07 public class extends JFrame {TextAreaDemo
08
09 private JTextArea textArea1, textArea2;
10
11 private JButton btnCopy;
12
13 public TextAreaDemo () {
14
15 super ("Displays textarea");
16
17 Box box = Box.createHorizontalBox ();
18
19 String string = "This is just an example aja ya";
20
21 textArea1 = new JTextArea (string, 10, 15);
22
23 box.add (new JScrollPane (textArea1));
24
25 btnCopy = new JButton ("Copy >>");
26
27 box.add (btnCopy);
28
29 btnCopy.addActionListener (
30
31 new ActionListener () {
32
33 public void actionPerformed (ActionEvent e) {
34
35 textArea2.setText (textArea1.getSelectedText ());
36
37}
38
39}
40
41); / / end of addActionListener
42
43 textArea2 = new JTextArea (10.15);
44
45 textArea2.setEditable (false);
46
47 box.add (new JScrollPane (textArea2));
48
49 Container container = getContentPane ();
50
51 container.add (box);
52
53 setSize (425, 200);
54
55 setResizable (false);
56
57 setLocationRelativeTo (null);
58
59 setVisible (true);
60
61}
62
63 public static void main (String args []) {
64
65 JFrame.setDefaultLookAndFeelDecorated (true);
66
67 TextAreaDemo TextAreaDemo test = new ();
68
69 test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
70
71}
72
73}
may be useful
Langganan:
Posting Komentar (Atom)
0 komentar: