Files
oop/lab/lab10/Question3/MyFrame.java
2022-05-01 23:24:00 +08:00

48 lines
1.2 KiB
Java

/*
* Author: CHEN Yongyuan (Walter) from OOP(1007)
* Date: 2022-05-01
* Description: This is the Main Frame class.
*/
import java.awt.FlowLayout;
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 FlowLayout(FlowLayout.LEFT, 20, 40));
// 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);
add(tx);
add(cb);
add(rb);
add(cb1);
add(cb2);
setVisible(true);
}
}