Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIComponents.java
More file actions
Latest commit
81 lines (64 loc) · 2.12 KB
/
Copy pathGUIComponents.java
File metadata and controls
81 lines (64 loc) · 2.12 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassGUIComponents
{
publicstaticvoidmain(String[] args)
{
// JButton jbtOK = new JButton("OK");
// JButton jbtCancel = new JButton("Cancel");
JLabellabelAdj = newJLabel("ADJECTIVE");
JTextFieldtextAdj = newJTextField("smelly");
JLabellabelNoun = newJLabel("NOUN");
JTextFieldtextNoun = newJTextField("poop");
JLabellabelAnimal = newJLabel("ANIMAL");
JTextFieldtextAnimal = newJTextField("kitty-cat");
JLabellabelNoise = newJLabel("NOISE");
JTextFieldtextNoise = newJTextField("screeeeech");
JButtonbtn = newJButton("HERE WE GO!!!");
JTextArearesult = newJTextArea("Wait for it...");
// Create Panel
JPanelpanel = newJPanel();
// Set that magical thing to make it all one line
panel.setLayout(newBoxLayout(panel, BoxLayout.PAGE_AXIS));
// Add items to panel
panel.add(labelAdj);
panel.add(textAdj);
panel.add(labelNoun);
panel.add(textNoun);
panel.add(labelAnimal);
panel.add(textAnimal);
panel.add(labelNoise);
panel.add(textNoise);
panel.add(btn);
panel.add(result);
//Add JFrame
JFrameframe = newJFrame();
frame.add(panel);
frame.setTitle("Show GUI components");
frame.setSize(450, 1000);
frame.setLocation(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// Add action listener
btn.addActionListener(newActionListener()
{
@Override
publicvoidactionPerformed(ActionEvente)
{
Stringadj = textAdj.getText();
Stringnou = textNoun.getText();
Stringani = textAnimal.getText();
Stringnoi = textNoise.getText();
result.setText(
adj + " Macdonald had a " + nou + ", E-I-E-I-O\n" +
"and in that " + nou + " he had a " + ani + ", E-I-E-I-O\n" +
"with a "+ noi + " " + noi +" here\n" +
"and a " + noi + " " + noi + " there,\n" +
"here a " + noi + ", there a " + noi + ",\n" +
"everywhere a " + noi + " " + noi + ",\n" +
adj + "Macdonald had a " + nou + ", E-I-E-I-O.");
}
});
}
}