-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFormatter.java
More file actions
47 lines (39 loc) · 1.22 KB
/
TextFormatter.java
File metadata and controls
47 lines (39 loc) · 1.22 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TextFormatter extends JFrame {
private JTextField textField;
private JTextArea textArea;
public TextFormatter(){
setTitle("Simple Text Formatter");
setSize(400, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
textField = new JTextField(15);
textField.setBounds(50, 30, 300, 30);
add(textField);
JButton b = new JButton("Format Button");
b.setBounds(130, 80, 130, 30);
add(b);
textArea = new JTextArea(5,20);
textArea.setEditable(false);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setBounds(50, 130, 300, 200);
add(scroll);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
formatText();
}
});
setVisible(true);
}
public void formatText(){
String text = textField.getText();
textArea.setText(text);
textArea.setFont(new Font("Arial",Font.PLAIN,16));
}
public static void main(String[] args) {
new TextFormatter();
}
}