- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiExample.java
More file actions
Latest commit
49 lines (38 loc) · 1.27 KB
/
Copy pathGuiExample.java
File metadata and controls
49 lines (38 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
/* Computer Programming 1
*/
importjava.io.*;
importjava.util.*;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassGuiExampleextendsJFrame
{
//class constructor
publicGuiExample (){
setSize(1600,600);
setTitle("Sample");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Toolkittoolkit = getToolkit();
Dimensionsize = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);
}
publicstaticvoidmain(String[] args) {
GuiExamplesimple = newGuiExample();
//simple.setLayout(null); // caused the panel to be hidden
JPanelpanel = newJPanel();
simple.getContentPane().add(panel);
//panel.setLayout(null);
JButtonbtn = newJButton("beep");
btn.setBounds(150,60,80,80);
panel.add(btn);
panel.add(newJButton("hi there"));
btn.addActionListener(newActionListener() {
publicvoidactionPerformed(ActionEventevent) {
//JButton btn1 = new JButton("hello");
//btn1.setBounds(200,120,80,80);
//panel.add(new JButton("hi there"));
}
});
simple.setVisible(true);
}
}