Playing Compiler
Find and correct the syntax and logic errors in the following program, which is supposed to display an image in the center of a frame, the words “huh?” and “what?” in the EAST and WEST sections of the frame, respectively, the digits 0 through 9 from left to right in the NORTH section, and the digits 9 through 0 from left to right in the SOUTH section.
import javax.swing.*; import java.awt.*; public class BorderLayoutExample extends JFrame { public BorderLayoutExample() { super("Border Layout Example"); setBounds(0, 0, 300, 300); // for the frame JPanel bottomPanel = new JPanel (new (GridLayout()) ); JPanel topPanel = new JPanel (new (GridLayout()) ); for (int i = 0; i<10; i++) { bottomPanel.add (new JLabel(i)); bottomPanel.add (new JLabel(10 − i)); } add(bottomPanel, BorderLayout.SOUTH); add(topPanel, BorderLayout.NORTH); add(new String ("huh?"), BorderLayout.EAST); add(new String ("what?"), BorderLayout.WEST); JLabel picture = new JLabel(new ImageIcon("test.jpg")); add(picture, BorderLayout.CENTER); } public static void main(String[] args) { JFrame frame = new BorderLayoutExample(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.