73 lines
1.8 KiB
Java
73 lines
1.8 KiB
Java
|
|
/*
|
|
* Author: CHEN Yongyuan (Walter) from OOP(1007)
|
|
* Date: 2022-05-01
|
|
* Description: This is the Main Frame class.
|
|
*/
|
|
import java.awt.BorderLayout;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JRadioButton;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JPanel;
|
|
import java.awt.Color;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.GridLayout;
|
|
|
|
public class MyFrame extends JFrame {
|
|
|
|
public MyFrame() {
|
|
setTitle("MyFrame");
|
|
setSize(400, 300);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
// center the frame
|
|
setLocationRelativeTo(null);
|
|
|
|
setLayout(new BorderLayout());
|
|
|
|
// first panel
|
|
JPanel p1 = new JPanel();
|
|
p1.setLayout(new BorderLayout(10, 10));
|
|
p1.setBackground(Color.BLUE);
|
|
// second panel
|
|
JPanel p2 = new JPanel();
|
|
p2.setLayout(new FlowLayout());
|
|
p2.setBackground(Color.GREEN);
|
|
// third panel
|
|
JPanel p3 = new JPanel();
|
|
p3.setLayout(new GridLayout(2, 2, 2, 2));
|
|
// add panel to frame
|
|
add(p1, BorderLayout.PAGE_START);
|
|
add(p2, BorderLayout.CENTER);
|
|
add(p3, BorderLayout.PAGE_END);
|
|
|
|
// tow button in the first panel
|
|
JButton b1 = new JButton("Button1");
|
|
p1.add(BorderLayout.LINE_START, b1);
|
|
JButton b2 = new JButton("Button2");
|
|
p1.add(BorderLayout.LINE_END, b2);
|
|
|
|
// two label in the second panel
|
|
JLabel l = new JLabel("Enter your name: ");
|
|
p2.add(l);
|
|
JTextField tx = new JTextField("Type Text Here");
|
|
p2.add(tx);
|
|
|
|
// checkboxs in the third panel
|
|
JCheckBox cb = new JCheckBox("I agree");
|
|
p3.add(cb);
|
|
JRadioButton rb = new JRadioButton("Yes");
|
|
p3.add(rb);
|
|
JComboBox<String> cb1 = new JComboBox<String>(new String[] { "Red", "Green", "Blue" });
|
|
p3.add(cb1);
|
|
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[] { 2, 7, -3, 24 });
|
|
p3.add(cb2);
|
|
|
|
setVisible(true);
|
|
}
|
|
}
|