Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ONLY need display GUI THANKS! This program has the following requirements: 1. Th

ID: 3656135 • Letter: O

Question

ONLY need display GUI THANKS! This program has the following requirements: 1. The textfield should accommodate 3 characters. 2. The X and Y labels should be next to the corresponding textfields. Hint: Put each label and its adjacent text field into a panel, then put both panels into another panel! 3. The buttons should have 10 pixels horizontal spacing and 5 pixels vertical spacing. 4. For the layout of the JFrame, use FlowLayout( FlowLayout.CENTER, 10, 5). 5. Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed. 6. Do not use inheritance for this program. Use a JFrame member variable as the main window object for this program.

Explanation / Answer

import javax.swing.*; import java.awt.*; /** * @version 1.32 2007-06-12 * @author Cay Horstmann */ public class NotHelloWorld { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { NotHelloWorldFrame frame = new NotHelloWorldFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }}; } } /** * A frame that contains a message panel */ class NotHelloWorldFrame extends JFrame { public NotHelloWorldFrame() { setTitle("NotHelloWorld"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add panel to frame NotHelloWorldPanel panel = new NotHelloWorldPanel(); add(panel); } public static final int DEFAULT_WIDTH = 300; public static final int DEFAULT_HEIGHT = 200; } /** * A panel that displays a message. */ class NotHelloWorldPanel extends JPanel { public void paintComponent(Graphics g) { g.drawString("Not a Hello, World program", MESSAGE_X, MESSAGE_Y); } public static final int MESSAGE_X = 75; public static final int MESSAGE_Y = 100; }