48 lines
1.3 KiB
Java
48 lines
1.3 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;
|
|
|
|
public class MyFrame extends JFrame {
|
|
|
|
public MyFrame() {
|
|
setSize(400, 300);
|
|
setTitle("MyFrame");
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setLocationRelativeTo(null);
|
|
|
|
// set the layout of the frame
|
|
setLayout(new BorderLayout());
|
|
|
|
// add the buttons to the frame
|
|
add(new JButton("Button 1"));
|
|
add(new JButton("Button 2"));
|
|
|
|
JLabel l = new JLabel("Enter your name: ");
|
|
JTextField tx = new JTextField("Type Text Here");
|
|
JCheckBox cb = new JCheckBox("I agree");
|
|
JRadioButton rb = new JRadioButton("Yes");
|
|
JComboBox<String> cb1 = new JComboBox<String>(new String[] { "Red", "Green", "Blue" });
|
|
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[] { 2, 7, -3, 24 });
|
|
// add the components to the frame
|
|
add(l, BorderLayout.PAGE_START);
|
|
add(tx, BorderLayout.LINE_START);
|
|
add(cb, BorderLayout.CENTER);
|
|
add(rb, BorderLayout.LINE_END);
|
|
add(cb1, BorderLayout.PAGE_END);
|
|
add(cb2);
|
|
|
|
setVisible(true);
|
|
}
|
|
}
|