-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path51_Panels
More file actions
51 lines (41 loc) · 1.64 KB
/
51_Panels
File metadata and controls
51 lines (41 loc) · 1.64 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
// JPanel = a GUI component that functions as a container to hold other components
// JFrame = a GUI window to add components to (Look like pop out window)
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.io.*;
import java.util.*;
import static javax.swing.text.StyleConstants.setBackground;
public class Main {
public static void main(String[] args){
ImageIcon icon = new ImageIcon("Ph.png");
JLabel label = new JLabel();
label.setText("Hi");
label.setIcon(icon);
/*label.setVerticalAlignment(label.TOP);
label.setHorizontalAlignment(label.RIGHT);*///don't need if use layout manager
label.setBounds(100,100,10,10);
JPanel redPanel = new JPanel();
redPanel.setBackground(Color.red);
redPanel.setBounds(0,0,250,250);//(x,y,width,height)
redPanel.setLayout(new BorderLayout());
JPanel bluePanel = new JPanel();
bluePanel.setBackground(Color.blue);
bluePanel.setBounds(250,0,250,250);//(x,y,width,height)
bluePanel.setLayout(null);
JPanel greenPanel = new JPanel();
greenPanel.setBackground(Color.green);
greenPanel.setBounds(0,250,500,250);//(x,y,width,height)
greenPanel.setLayout(new BorderLayout());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation((JFrame.EXIT_ON_CLOSE));
frame.setLayout(null);
frame.setSize(750,750);
frame.setVisible(true);
greenPanel.add(label);
frame.add(redPanel);
frame.add(bluePanel);
frame.add(greenPanel);
}
}
//if dw use layout manager, set null