COMP2396
Loading...
Searching...
No Matches
TextAreaEx.java
Go to the documentation of this file.
1import javax.swing.*;
2import java.awt.*;
3import java.awt.event.*;
4
5public class TextAreaEx implements ActionListener {
6 JTextArea text;
7
8 public static void main(String[] args) {
9 TextAreaEx gui = new TextAreaEx();
10 gui.go();
11 }
12
13 public void go() {
14 JFrame frame = new JFrame();
15 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16 JPanel panel = new JPanel();
17 JButton button = new JButton("Just Click It");
18 button.addActionListener(this);
19 text = new JTextArea(10, 20);
20 text.setLineWrap(true);
21 JScrollPane scroller = new JScrollPane(text);
22 scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
23 scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
24 panel.add(scroller);
25 frame.add(panel, BorderLayout.CENTER);
26 frame.add(button, BorderLayout.SOUTH);
27 frame.setSize(350, 300);
28 frame.setVisible(true);
29 }
30
31 public void actionPerformed(ActionEvent event) {
32 text.append("button clicked\n");
33 }
34}
void actionPerformed(ActionEvent event)
static void main(String[] args)