Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to call a method because it's not static

807597Apr 21 2005 — edited Apr 21 2005
Hello,

When I try to run my code I get this error.

Error

java.lang.Error: Unresolved compilation problem:
The method BorderLayoutEg cannot be declared static; static methods can only be declared in a static or top level type

at Layouts$Blg.BorderLayoutEg(Layouts.java:29)
at Layouts.main(Layouts.java:22)
Exception in thread "main"

I am not sure what the problem is. I attempt to display several layouts. How do I make my code none static or how can I reference a dynamic content from static?
import javax.swing.*;

import java.awt.*;

import javax.swing.border.*;

public class Layouts {
static JFrame aWindow=new JFrame("This is a Border Layout");

	public static void main (String[] args){
		Blg.BorderLayoutEg();
	}

	class Blg {
	 static void BorderLayoutEg(){
		Toolkit theKit =aWindow.getToolkit();
		Dimension wndSize=theKit.getScreenSize();
		aWindow.setBounds(wndSize.width/4, wndSize.height/4, wndSize.width/2,wndSize.height/2);
		aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		BorderLayout border= new BorderLayout();
		Container  content=aWindow.getContentPane();
		content.setLayout(border);
		EtchedBorder edge=new EtchedBorder(EtchedBorder.RAISED);
		JButton button;
		content.add(button=new JButton("EAST"),BorderLayout.EAST);
		button.setBorder(edge);
		content.add(button=new JButton("WEST"),BorderLayout.WEST);
		button.setBorder(edge);
		content.add(button=new JButton("NORTH"),BorderLayout.NORTH);
		button.setBorder(edge);
		content.add(button=new JButton("SOUTH"),BorderLayout.SOUTH);
		button.setBorder(edge);
		content.add(button=new JButton("CENTER"),BorderLayout.CENTER);
		button.setBorder(edge);
		aWindow.setVisible(true);
	}
  }
	
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 19 2005
Added on Apr 21 2005
3 comments
162 views