Skip to main content

Problem with protected methods

4 replies [Last post]
rvsjoen
Offline
Joined: 2006-02-14

I'm having some compile problems and I cant figure out why... Any ideas ?

The compiler returns
repaint() has protected access in jcurses.Widgets.Window

import jcurses.widgets.*;
import jcurses.event.*;
import java.lang.Thread;

class jcursesTest {
public static void main(String[] args) {
MainArea main = new MainArea();
main.create();
while(true){
try{
Thread.sleep(2000);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
main.update();
}
}
}
class MainArea {
// Instantiate the main window
Window w = new Window(40,20,true,"< Mouse in Maze >");
DefaultLayoutManager mgr = new DefaultLayoutManager();
void create(){
mgr.bindToContainer(w.getRootPanel());
Maze maze = new Maze();
TextArea txt_area = new TextArea(38,14,maze.print());
mgr.addWidget(txt_area,0,0,38,14,0,0);

// Display the window
w.show();
}
void update(){
// Update the window content
w.repaint();
}

}
class Maze {

// Set up the maze ( 0=Empty, 1=Wall )
public int[][] coords = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1},
{1,1,1,0,1,0,1,1,1,1,0,0,0,1,0,0,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1,0,1,0,1},
{1,0,0,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,1,1,1,0,1,0,1,0,0,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,1},
{1,1,1,0,1,0,0,0,0,0,0,1,0,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1},
{1,0,0,0,1,0,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,1,0,1,0,1,1,0,1,1,1,1,0,1},
{1,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1},
{1,1,1,1,0,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1},
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};

// Declare the string to hold the printed maze
public String content = new String();

// Create a new instance of Mouse
Mouse minnie = new Mouse();

// Reads the coords[][] array and prints
String print(){
for(int rows=0;rows<=11;rows++){
for(int cols=0;cols<=35;cols++){
if(rows == minnie.mousey && cols == minnie.mousex){
content += "M";
} else if(coords[rows][cols] == 1){
content += "#";
} else {
content += " ";
}
}
content += "\n";
}
return content;
}
}
class Mouse {

// Initial position of the mouse is (x,y) = (0,1)
public int mousex = 0;
public int mousey = 1;

// The current direction the mouse is facing (0=up,1=right,2=down,3=left)
// Initial direction is up
public int direction = 0;

// Moves the mouse a step in the current direction
void move_forward(){
switch (direction)
{
case 0:mousey--;break;
case 1:mousex++;break;
case 2:mousey++;break;
case 3:mousex--;break;
}
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rvsjoen
Offline
Joined: 2006-02-14

This is a simplified version of the same problem

import jcurses.widgets.*;
class testRepaint {
public static void main(String[] args) {
Window w = new Window(40,20,true,"< Test >");
w.show();
w.repaint();
}
}

daaf
Offline
Joined: 2006-02-14

sorry dont have a solution to your problem, but actually a question. i am getting null pointer exceptions calling the window constructor. i got ncurses 5.4 installed and java "1.4.2_09"

Exception in thread "main" java.lang.ExceptionInInitializerError
at jcurses.system.InputChar.(InputChar.java:13)
at jcurses.widgets.Window.(Window.java:209)
at WindowTest.main(WindowTest.java:8)
Caused by: java.lang.NullPointerException
at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)
at jcurses.system.Toolkit.(Toolkit.java:37)
... 3 more

source:
import jcurses.system.CharColor;
import jcurses.widgets.*;

public class WindowTest
{
public static void main(String[] args) throws Exception
{
Window w = new Window(40, 20, true, "Hello World Window");

DefaultLayoutManager mgr = new DefaultLayoutManager();
mgr.bindToContainer(w.getRootPanel());
mgr.addWidget(
new Label("Hello World!", new CharColor(CharColor.WHITE, CharColor.G
REEN)),
0, 0, 40, 20,
WidgetsConstants.ALIGNMENT_CENTER,
WidgetsConstants.ALIGNMENT_CENTER);

w.show();
Thread.currentThread().sleep(5000);
w.close(); // reset the native console
}
}

daaf
Offline
Joined: 2006-02-14

by the way: i have the same problem as you compiling your little test program.

daaf
Offline
Joined: 2006-02-14