Okay. This is the file that I used as an [bold]input:[/bold]
[bold]and the output that I get was:[/bold]Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class p1 extends JFrame { private int size=6; private ImageIcon icon; private JLabel lblImg; private Timer timer; public p1() { JPanel p1 = new JPanel(); lblImg = new JLabel(); icon = new ImageIcon(getClass().getResource("Sunset0.jpg")); lblImg.setIcon(icon); setLayout(new FlowLayout()); add(lblImg); } public static void main(String args[]) { p1 frame = new p1(); frame.setSize(600,600); frame.setVisible(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
However, the output that I [bold]want[/bold] is:Code:import java.awt.*; { private ImageIcon icon; private Timer timer; { lblImg = new JLabel(); lblImg.setIcon(icon); add(lblImg); { frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class p1 extends JFrame { private int size=6; private ImageIcon icon; private JLabel lblImg; private Timer timer; public p1() { JPanel p1 = new JPanel(); lblImg = new JLabel(); icon = new ImageIcon(getClass().getResource("Sunset0.jpg")); lblImg.setIcon(icon); setLayout(new FlowLayout()); add(lblImg); } public static void main(String args[]) { p1 frame = new p1(); frame.setSize(600,600); frame.setVisible(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }




Reply With Quote