The code below is returning the following error :
"non-static variable this cannot be referenced from a static context" on line 25 (i have added notation to the code below to show where the error is...
all help will be greatly appreciated, i am new to GUI development, and this has me stumped.
Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class BinarySearchTreeApp { public static void main (String[]args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI();}});} private static void createAndShowGUI() { JFrame Frame1 = new JFrame("My Application"); Frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame1.setSize(500,500); Frame1.setVisible(true); Frame1.add(new MyPanel()); <----ERROR IS ON THIS LINE! } class MyPanel extends JPanel { public MyPanel() { setBorder(BorderFactory.createLineBorder(Color.black)); } public void paintComponent(Graphics g) { super.paintComponent(g); } } }




Reply With Quote