Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the error " Cannot find symbol " on getdocumentBase()
    text
    copied!<p>Despite I import the applet library, NetBeans cannot recognize and use getDocumentBase() in my code, I have my html file within my project and all other required files as well, here is a part of my code :</p> <pre><code>import java.awt.*; import java.applet.*; public class AirportCanvas extends Canvas { SingleLaneAirport controller; Image redPlane; Image bluePlane; Image airport; //AudioClip crashSound; int[] redX,redY,blueX,blueY; int maxCar = 2; final static int initredX = 5; final static int initredY = 55; final static int initblueX = 410; final static int initblueY = 130; final static int bridgeY = 90; boolean frozen = false; int cycleTime = 20; AirportCanvas(SingleLaneAirport controller) { super(); this.controller = controller; // crashSound=controller.getAudioClip(controller.getDocumentBase(),"crash.au"); MediaTracker mt; mt = new MediaTracker(this); redPlane = controller.getImage(controller.getDocumentBase(), "redplane.png"); mt.addImage(redPlane, 0); bluePlane = controller.getImage(controller.getDocumentBase(), "blueplane.png"); mt.addImage(bluePlane, 1); airport = controller.getImage(controller.getDocumentBase(), "airport.png"); mt.addImage(airport, 2); try { mt.waitForID(0); mt.waitForID(1); mt.waitForID(2); } catch (java.lang.InterruptedException e) { System.out.println("Couldn't load one of the images"); } setSize(airport.getWidth(null),airport.getHeight(null)); init(1); } public final void init(int ncars) { //set number of cars maxCar = ncars; frozen = false; redX = new int[maxCar]; redY = new int[maxCar]; blueX = new int[maxCar]; blueY = new int[maxCar]; for (int i = 0; i&lt;maxCar ; i++) { redX[i] = initredX - i*85; redY[i] = initredY; blueX[i] =initblueX + i*85; blueY[i] =initblueY; } repaint(); } Image offscreen; Dimension offscreensize; Graphics offgraphics; public void backdrop() { Dimension d = getSize(); if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offgraphics = offscreen.getGraphics(); offgraphics.setFont(new Font("Helvetica",Font.BOLD,36)); } offgraphics.setColor(Color.lightGray); offgraphics.drawImage(airport,0,0,this); } @Override public void paint(Graphics g) { update(g); } @Override public void update(Graphics g) { backdrop(); for (int i=0; i&lt;maxCar; i++) { offgraphics.drawImage(redPlane,redX[i],redY[i],this); offgraphics.drawImage(bluePlane,blueX[i],blueY[i],this); } if (blueY[0]==redY[0] &amp;&amp; Math.abs(redX[0]+80 - blueX[0])&lt;5) { offgraphics.setColor(Color.red); offgraphics.drawString("Crunch!",200,100); frozen=true; // crashSound.play(); } g.drawImage(offscreen, 0, 0, null); } //returns true for the period from just before until just after car on bridge public boolean moveRed(int i) throws InterruptedException { int X = redX[i]; int Y = redY[i]; synchronized (this) { while (frozen ) wait(); if (i==0 || Math.abs(redX[i-1] - X) &gt; 120) { X += 2; if (X &gt;=500) { X = -80; Y = initredY; } if (X &gt;=60 &amp;&amp; X &lt; 290 &amp;&amp; Y&lt;bridgeY) ++Y; if (X &gt;=290 &amp;&amp; Y&gt;initredY) --Y; } redX[i]=X; redY[i]=Y; repaint(); } Thread.sleep(cycleTime); return (X&gt;25 &amp;&amp; X&lt;400); } //returns true for the period from just before until just after car on bridge public boolean moveBlue(int i) throws InterruptedException { int X = blueX[i]; int Y = blueY[i]; synchronized (this) { while (frozen ) wait(); if (i==0 || Math.abs(blueX[i-1] - X) &gt; 120) { X -= 2; if (X &lt;=-80) { X = 500; Y = initblueY; } if (X &lt;=370 &amp;&amp; X &gt; 130 &amp;&amp; Y&gt;bridgeY) --Y; if (X &lt;=130 &amp;&amp; Y&lt;initblueY) ++Y; blueX[i]=X; } blueY[i]=Y; repaint(); } Thread.sleep(cycleTime); repaint(); return (X&gt;25 &amp;&amp; X&lt;400); } public synchronized void freeze() { frozen = true; } public synchronized void thaw() { frozen = false; notifyAll(); } } </code></pre> <p>Single Lane Airport Class :</p> <pre><code>import java.awt.*; import java.awt.event.*; import java.applet.*; public class SingleLaneAirport { AirportCanvas display; Button restart; Button freeze; Button onecar; Button twocar; Button threecar; Checkbox fair; Checkbox safe; boolean fixed = false; int maxCar = 1; Thread red[]; Thread blue[]; @Override public void init() { setLayout(new BorderLayout()); display = new AirportCanvas(this); add("Center",display); restart = new Button("Restart"); restart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { display.thaw(); } }); freeze = new Button("Freeze"); freeze.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { display.freeze(); } }); onecar = new Button("One Car"); onecar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { stop(); maxCar = 1; start(); } }); twocar = new Button("Two Cars"); twocar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { stop(); maxCar = 2; start(); } }); threecar = new Button("Three Cars"); threecar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { stop(); maxCar = 3; start(); } }); safe = new Checkbox("Safe",null,true); safe.setBackground(Color.lightGray); safe.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { stop(); start(); } }); fair = new Checkbox("Fair",null,false); fair.setBackground(Color.lightGray); fair.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { stop(); start(); } }); Panel p1 = new Panel(); p1.setLayout(new FlowLayout()); p1.add(freeze); p1.add(restart); p1.add(onecar); p1.add(twocar); p1.add(threecar); p1.add(safe); p1.add(fair); add("South",p1); setBackground(Color.lightGray); } @Override public void start() { red = new Thread[maxCar]; blue = new Thread[maxCar]; display.init(maxCar); Airport b; if (fair.getState() &amp;&amp; safe.getState()) b = new FairAirport(); else if ( safe.getState()) b = new SafeAirport(); else b = new Airport(); for (int i = 0; i&lt;maxCar; i++) { red[i] = new Thread(new RedPlane(b,display,i)); blue[i] = new Thread(new BluePlane(b,display,i)); } for (int i = 0; i&lt;maxCar; i++) { red[i].start(); blue[i].start(); } } @Override public void stop() { for (int i = 0; i&lt;maxCar; i++) { red[i].interrupt(); blue[i].interrupt(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload