This commit is contained in:
2022-05-01 23:24:00 +08:00
parent 0b354c7561
commit 053113577f
16 changed files with 493 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,34 @@
/**
* Answer to question.
*
* - Q: What happens when you run the program?
*
* - A: The layout change to 2 columns. Direction is LTR. The program change the
* layout to my desired, the layout use the number of columns that I specified.
*
* - Q: Use the mouse to resize the frame. Does the layout change?
*
* - A: No, the layout doesn't change.
*
* - Q: Set the number of rows to zero in the grid layout manager and try again.
* What happens?
*
* - A: BOOM SHAKARAKA!
*
* - Q: What happens when you add more than one component to one of the five
* areas of the frame? What happens when one of the five areas does not contain
* any component?
*
* - A: The component will overlapping.
*/
public class Start {
public static void main(String[] args) {
// Dispather
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MyFrame();
}
});
}
}