import javax.swing.*; import java.awt.*; import java.awt.event.*; public class BorderLayoutRegionsExample implements ActionListener { JFrame frame; Container cp; JButton submitB; JLabel titleL, commentsL; JTextArea commentsTA; public void actionPerformed(ActionEvent a) { System.out.println("Code to submit these comments to the database would go inside this method..."); } public static void main(String[] args) { BorderLayoutRegionsExample t = new BorderLayoutRegionsExample(); t.go(); } //end method main() public void go() { frame = new JFrame(); frame.setSize(300, 150); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cp = frame.getContentPane(); JButton submitB = new JButton("Submit Comments"); cp.add(BorderLayout.SOUTH, submitB); submitB.addActionListener(this); titleL = new JLabel("User Feedback Form"); titleL.setHorizontalAlignment(SwingConstants.CENTER); //by default, labels are left -justified cp.add(BorderLayout.NORTH, titleL); JLabel commentsL = new JLabel("Tell us what you think!"); cp.add(BorderLayout.WEST, commentsL); JTextArea commentsTA = new JTextArea(); commentsTA.setLineWrap(true); //by default, line wrapping is turned OFF in a text area cp.add(BorderLayout.CENTER, commentsTA); //Notice that I do not have anything in the EAST regions. This is fine. //There is nothing that says you have to have content in all of the regions. /* Obviously, this isn't exactly a beautiful GUI. Learning to make really nice GUIs is an art and a Java skill in its own right. We will not spend time focusing on it in this course, but I do strongly encourage you to play around with it on your own. There are entire books devoted to Swing which will teach you all about GUI layout. Many Java textbooks will allocate at least a few pages to it. */ frame.setVisible(true); } //end method go() } //end class