simple static/non-static problem...need help!

Hello!

I have a problem thats is very simple but just can't fix it..

When i call visaSida() in the main Webbscrape-class i can't do that because it is calling a non static method in the innerclass, Webblasare. If I make the visaSida static it can't perform the setPage() inside of it because its not static. I have never really understood the static-thing either... whats its use?

tnx

import java.io.*;

import java.awt.*;

import java.awt.event.*;

import java.net.*;

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.text.html.*;

import javax.swing.text.*;

public class Webbscrape extends JFrame implements ActionListener{

Webblasare Jep = new Webblasare();

JTable Jt = new JTable(50,2);

JScrollPane Jsp_links;

JScrollPane Jsp_webb;

JTextField url = new JTextField();

public Webbscrape(){

Container c = getContentPane();

url.addActionListener(this);

Jsp_links = new JScrollPane(Jt);

Jsp_webb = new JScrollPane(Jep);

add(url, BorderLayout.PAGE_START);

add(Jsp_links, BorderLayout.LINE_END);

add(Jsp_webb, BorderLayout.CENTER);

setSize(850,500);

setLocation(100,100);

setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

setVisible(true);

}

public void actionPerformed(ActionEvent e) {

Webblasare.visaSida(url.getText());

}

public static void main(String[] args) {

Webbscrape wb = new Webbscrape();

}

////////////////////////////////////////////////////////////////////////////////////////////////////

public class Webblasare extends JEditorPane {

public Webblasare(){

super();

}

public void visaSida(String url) {

String newUrl = url;

try {

setPage(newUrl);

}

catch(Exception e){}

}

}

}

[1911 byte] By [Siggefa] at [2007-11-27 3:59:39]
# 1

You only can write

Webblasare.visaSida(url.getText());

if visaSida method is declared as static:

public static void visaSida(String url) {

String newUrl = url;

try {

setPage(newUrl);

}

catch(Exception e){}

}

If it's not (as in your code), you should use Webblasare objects to get access to class methods, for instance:

public void actionPerformed(ActionEvent e) {

Jep.visaSida(url.getText());

}

Message was edited by:

Qwintik

Qwintika at 2007-7-12 9:04:11 > top of Java-index,Desktop,Core GUI APIs...
# 2
http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
PhHeina at 2007-7-12 9:04:11 > top of Java-index,Desktop,Core GUI APIs...
# 3
oo ofcourse!!! im really a beginner.. :) Thanks!!
Siggefa at 2007-7-12 9:04:11 > top of Java-index,Desktop,Core GUI APIs...