Hi all,
I know it's simple enough, although I can't see where I'm going wrong for some reason. Basically I've got a class which extends JPanel but when I try to call one of its methods from my main class I get an error. The relevant code (I hope) is:
Main.java
import java.awt.BorderLayout;
// ...
import javax.swing.UIManager;
public class Main extends JFrame implements ActionListener {
JFrame frame;
public static JPanel statusBar;
public Main() {
// ...
// Add a status bar
statusBar = new StatusBar();
mainPanel.add( statusBar, BorderLayout.SOUTH );
setContentPane( mainPanel );
// ...
}
// ...
public static void setStatusBarText( String s ) {
statusBar.setStatusText("Test");
}
// ...
}
StatusBar.java
import java.awt.Color;
// ...
import javax.swing.SwingConstants;
public class StatusBar extends JPanel {
private int barWidth;
private static JLabel status;
public StatusBar() {
super();
//barWidth = Main.getProgramWidth();
//setPreferredSize( new Dimension(barWidth,22) );
setLayout( new FlowLayout( FlowLayout.LEADING ) );
setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(160,160,160) ) );
status = new JLabel("Test", SwingConstants.LEFT);
//status.setVerticalAlignment( SwingConstants.CENTER );
add( status );
}
protected void setStatusText( String s ) {
status.setText( s );
revalidate();
}
}
The "statusBar.setStatusText("Test");" call in the main class file doesn't work and I get the error:
>
cannot find symbol
symbol : method setStatusText(java.lang.String)
location: class javax.swing.JPanel
statusBar.setStatusText("Test");
>
Any ideas what I'm doing wrong? I created an instance of the StatusBar class called statusBar, then I use this to call the setStatusText() method (via statusBar.setStatusText()) which I thought was all correct, then it doesn't work? Even if there's an easier way to do what I want to achieve (i.e. update a JLabel from the 'central' main class file instead of setting the JLabel to static and having every class call it directly), I'd appreciate knowing where I'm going wrong here nonetheless.
Many thanks,
Tristan