Contoh Program berikut ini mendemokan penanganan inputan Textarea di java. Inputan textarea ini dapat dibuat dengan objek JTextArea. Program akan menampilkan dua text-area dimana sebagian atau seluruh tulisan yang dipilih pada text-area yang pertama akan dicopy / dipindahkan ke text-area yang kedua.
Berikut ini tampilan programnya:
Berikut ini contoh programnya
03 | import java.awt.event.*; |
07 | public class TextAreaDemo extends JFrame { |
09 | private JTextArea textArea1, textArea2; |
11 | private JButton btnCopy; |
13 | public TextAreaDemo() { |
15 | super ("Menampilkan Textarea"); |
17 | Box box = Box.createHorizontalBox(); |
19 | String string = "Ini hanya contoh aja yach"; |
21 | textArea1 = new JTextArea(string, 10, 15); |
23 | box.add(new JScrollPane(textArea1)); |
25 | btnCopy = new JButton("Copy >>"); |
29 | btnCopy.addActionListener( |
31 | new ActionListener() { |
33 | public void actionPerformed(ActionEvent e) { |
35 | textArea2.setText(textArea1.getSelectedText()); |
43 | textArea2 = new JTextArea(10,15); |
45 | textArea2.setEditable(false); |
47 | box.add(new JScrollPane(textArea2)); |
49 | Container container = getContentPane(); |
57 | setLocationRelativeTo (null); |
63 | public static void main (String args[]) { |
65 | JFrame.setDefaultLookAndFeelDecorated(true); |
67 | TextAreaDemo test = new TextAreaDemo(); |
69 | test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
Semoga bermanfaat
0 komentar:
Poskan Komentar