-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextAreal.java
More file actions
51 lines (39 loc) · 1.27 KB
/
Copy pathTextAreal.java
File metadata and controls
51 lines (39 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TextAreal implements ActionListener, ItemListener {
JTextArea text;
JCheckBox check;
public static void main(String[] args){
TextAreal gui = new TextAreal();
gui.go();
}
public void go(){
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton("Just click it");
check = new JCheckBox("Gogogo");
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
button.addActionListener(this);
text = new JTextArea(10,20);
text.setLineWrap(true);
JScrollPane scroller = new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
panel.add(check);
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.setSize(350,300);
frame.setVisible(true);
check.addItemListener(this);
}
public void actionPerformed(ActionEvent ev){
text.append("Button clicked\n");
}
public void itemStateChanged(ItemEvent ev){
String onOrOff = "off";
if(check.isSelected()) onOrOff = "on";
text.append("check box is "+onOrOff + "\n");
}
}