Hey,
I am making a test for my first GUI program.
Here is the code so far:
package Tests; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class GUITest { private static class Display extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("This is my first GUI Test.", 20, 30); g.drawString("Hello World!", 20, 40); } } private static class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public static void main(String[] arg) { JButton button = new JButton("Click to close"); Display displayPanel = new Display(); ButtonHandler listener = new ButtonHandler(); button.addActionListener(listener); JFrame window = new JFrame("GUI Test"); window.setContentPane(content); window.setSize(300, 300); window.setLocation(100, 100); window.setVisible(true); JPanel content = new JPanel(); content.add(displayPanel, BorderLayout.CENTER); content.add(button, BorderLayout.SOUTH); content.setLayout(new BorderLayout()); } }
In the main() routine, the content in window.setContentPane(content); is underlined and it says it can't find the variable content, but it is clearly there under the JPanel definition (JPanel content = new JPanel().
Help?
-Silent