MyFrame.java import javax.swing.JFrame; public class MyFrame { public static void main(String[] args) { JFrame frame = new JFrame("MyFrame"); // Create a frame frame.setSize(400, 300); // Set the frame size // Center a frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // Display the frame } } MyFrame1.java import javax.swing.*; public class MyFrameWithComponents { public static void main(String[] args) { JFrame frame = new JFrame("MyFrameWithComponents"); // Add a button to the frame JButton jbtOK = new JButton("OK"); frame.add(jbtOK); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); // Center the frame frame.setVisible(true); } } Showlayout.java import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JFrame; import java.awt.FlowLayout; public class ShowFlowLayout { public ShowFlowLayout() { // Set FlowLayout, aligned left with horizontal gap 10 // and vertical gap 20 between components setLayout( ); // Add labels and text fields to the frame add(new JLabel("First Name")); add(new JTextField(8)); add(new JLabel("MI")); add(new JTextField(1)); add(new JLabel("Last Name")); add(new JTextField(8)); } public static void main(String[] args) { ShowFlowLayout frame = new ShowFlowLayout(); frame.setTitle("ShowFlowLayout"); frame.setSize(200, 200); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ShowGridLayout.java import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JFrame; import java.awt.GridLayout; public class ShowGridLayout extends JFrame { public ShowGridLayout() { // Set GridLayout, 3 rows, 2 columns, and gaps 5 between // components horizontally and vertically setLayout(new GridLayout(3, 2, 5, 5)); // Add labels and text fields to the frame add(new JLabel("First Name")); add(new JTextField(8)); add(new JLabel("MI")); add(new JTextField(1)); add(new JLabel("Last Name")); add(new JTextField(8)); } public static void main(String[] args) { ShowGridLayout frame = new ShowGridLayout(); frame.setTitle("ShowGridLayout"); frame.setSize(200, 125); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } TestPanels.java import java.awt.*; import javax.swing.*; public class TestPanels extends JFrame { public TestPanels() { // Create panel p1 for the buttons and set GridLayout JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(4, 3)); // Add buttons to the panel for (int i = 1; i <= 9; i++) { p1.add(new JButton("" + i)); } p1.add(new JButton("" + 0)); p1.add(new JButton("Start")); p1.add(new JButton("Stop")); // Create panel p2 to hold a text field and p1 JPanel p2 = new JPanel(new BorderLayout()); p2.add (new JTextField("Time to be displayed here"), BorderLayout.NORTH); p2.add(p1, BorderLayout.CENTER); // Add contents to the frame add(p2, BorderLayout.EAST); add(new JButton("Food to be placed here"), BorderLayout.CENTER); } /** Main method */ public static void main(String[] args) { TestPanels frame = new TestPanels(); frame.setTitle("The Front View of a Microwave Oven"); frame.setSize(400, 250); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }