Results 1 to 2 of 2
- 01-12-2012, 09:52 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 1
- Rep Power
- 0
java.lang.Thread has been deprecated
Hi I am trying to get this program to be compiled on Netbeans 7.1 /Dr Java with JDK 7 installed on my machine. I am currently bumping with around 13 errors after compilation, all related to <java.lang.Thread has been deprecated> type. What's wrong ? Is is because this code was written on older version of Java ?
Would appreciate any light on this. This could probably be very simple to correct, but I am somehow stuck in this.
[/CODE]Java Code:[CODE] // Base Model (a) v0.1 // The Version v0.1 Contains : Grid & Nodes, Vehicle Motion, Lights (Red-Green) & Stop Sign // Related files in 'relatedfiles_1-11-2011.zip' archive // Jan 11th 2012, 1:30 PM /** Issues and Problems : Segmentations faults need correction Fixing needed for 'java.lang.Thread has been deprecated' errors Working on these errors and fixing them one step at a time */ import java.util.*; import java.awt.*; import java.applet.Applet; import java.io.InputStream; import java.net.URL; class Node { int lane; int road; double dx; double dy; double x; double y; String lbl; int carW; int carL; double carWaiting; } // Displaying The Change In Lights, (Either Red Or Green Here) class ChangeLight implements Runnable { int signal; int pass, redpass, greenpass; Thread lighter; ChangeLight(){ signal=1; redpass=6000; greenpass=6000; } public void run() { signal=1; while (true) { if (signal==1){ signal=0; pass=greenpass; } else { signal=1; pass=redpass; } try { Thread.sleep(pass); } catch (InterruptedException e) { break; } } } public void start() { lighter = new Thread(this); lighter.start(); } public void stop() { lighter.stop(); } } // Displaying the Congestion & Flow of Cars in the Lanes // Cars Wait In A Queue If The Car In Front Of It Comes To A Stop, On Account Of Lights class CarFlow implements Runnable { int carnumbers, count; double carwait; int pass; double time0, time1, timeforlap; double carflow[] = new double[40]; Thread flow; CarFlow(){ carnumbers=0; carwait=0; pass=2000; time0=0; time1=0; for (int k=0; k<40; k++) carflow[k]=0; count=0; } public void run() { while (true) { time1= System.currentTimeMillis(); timeforlap=time1-time0; if (timeforlap >50) carflow[count]= ((double)(carnumbers)/timeforlap)*1000; count=(count+1)%40; try { Thread.sleep(pass); } catch (InterruptedException e) { break; } } } public void start() { flow = new Thread(this); flow.start(); } public void stop() { flow.stop(); } } class GraphPanel extends Applet implements Runnable { Graph graph; int nnodes; int LightOrStop; Node nodes[] = new Node[100]; ChangeLight light[] = new ChangeLight[5]; CarFlow carperminute[] = new CarFlow[5]; Thread relaxer, flow; int bringtoflag[] = new int[5]; double speed=10; int carwidth=6, carlength=9; int xpos[]= new int[5]; int ypos=200; int bringtoright[] = new int[5]; int bringtoleft[] = new int[5]; int bringtotop =ypos+ carlength; int bringtobottom=ypos- carlength; int roadleft[]=new int[5]; int roadright[] = new int[5]; int roadtop= ypos+ carwidth, roadbottom= ypos- carwidth; GraphPanel(Graph graph) { LightOrStop=1; //When Stop :0, When Light: 1 this.graph = graph; for (int i=0; i<5; i++) { light[i]= new ChangeLight(); carperminute[i]= new CarFlow(); xpos[i]=150*(i+1); bringtoright[i]=xpos[i]- carlength; bringtoleft[i]=xpos[i]+ carlength; bringtoflag[i]=0; } for(int k=1; k<4; k++){ roadleft[k]= xpos[k-1]- carwidth; roadright[k]= xpos[k-1]+ carwidth; } roadleft[0]=0; roadright[0]=0; } int findNode(String lbl) { for (int i = 0 ; i < nnodes ; i++) { if (nodes[i].lbl.equals(lbl)) { return i; } } return addNode(lbl); } int addNode(String lbl) { int temp; Node n = new Node(); temp = (int)(5*Math.random()); if (temp==0||temp==4){ n.x = 480 + 210*Math.random(); n.y= ypos; n.carW=carlength; n.carL=carwidth; } else{ n.x= xpos[temp-1]; n.y= 10+100*Math.random(); n.carW=carwidth; n.carL=carlength; } if (temp==4) temp=0; n.road=temp; n.lbl = lbl; n.carWaiting=-1; nodes[nnodes] = n; return nnodes++; } // Displaying The Running Of Cars With Reference To Lights public void run() { for (int j=0; j<5; j++) light[j].signal=1; flow = new Thread(carperminute[0]); carperminute[0].time0 = System.currentTimeMillis(); carperminute[0].carnumbers=0; flow.start(); while (true) { relax(); try { Thread.sleep(50); } catch (InterruptedException e) { break; } } } synchronized void relax() { for (int i = 0 ; i < nnodes; i++) { if (nodes[i].road==0){ nodes[i].dx = -speed*Math.random(); nodes[i].dy = 2*Math.random()-1; } else{ nodes[i].dy = speed*Math.random(); nodes[i].dx = 2*Math.random()-1; } } for (int i = 0 ; i < nnodes ; i++) { Node n1 = nodes[i]; double dx = 0; double dy = 0; for (int j = 0 ; j < nnodes ; j++) { Node n2 = nodes[j]; if (i == j||n1.road!=n2.road) { continue; } double vx; if(n1.road==0) vx = n1.x - n2.x; else vx= n2.y-n1.y; if (vx<0) continue; double len=vx; if( len<(n2.carW+n2.carL)){ if (n1.carWaiting<0) n1.carWaiting= System.currentTimeMillis(); if(n1.road==0) n1.dx=0; else n1.dy=0; } } } // Displaying The 'Motion' Of A Car Dimension d = size(); double temp; for (int i = 0 ; i < nnodes ; i++) { Node n = nodes[i]; if(n.road==0){ temp=n.x; n.x += Math.max(-10, Math.min(10, n.dx)); for (int k=0; k<3; k++){ if ((n.x<bringtoleft[k]&&n.x>bringtoright[k])&&bringtoflag[k]==1){ if(temp> bringtoleft[k] ||temp<bringtoright[k]) n.x=temp; } else if ((n.x< bringtoleft[k] &&n.x>bringtoright[k])&&bringtoflag[k]==0) if (LightOrStop==0) bringtoflag[k]=1; else{ if (light[k].signal==0) bringtoflag[k]=1; else n.x=temp; } else if(temp< bringtoleft[k] &&temp>bringtoright[k]) bringtoflag[k]=0; if (n.x < 0) { n.x = d.width-10*Math.random(); carperminute[0].carnumbers=carperminute[0].carnumbers+1; } else if (n.x > d.width) { n.x = d.width-10*Math.random(); } if (n.x!=temp&&n.carWaiting==-1){ carperminute[0].carwait+= System.currentTimeMillis()- n.carWaiting; n.carWaiting=-1; } } } else{ temp=n.y; n.y += Math.max(-10, Math.min(10, n.dy)); if ((n.y<bringtotop&&n.y>bringtobottom)&&bringtoflag[n.road-1]==1){ if(temp> bringtotop ||temp<bringtobottom) n.y=temp; } else if ((n.y< bringtotop &&n.y>bringtobottom)&&bringtoflag[n.road-1]==0) if (LightOrStop==0) bringtoflag[n.road-1]=1; else{ if (light[n.road-1].signal==1) bringtoflag[n.road-1]=1; else n.y=temp; } else if(temp< bringtotop &&temp>bringtobottom) bringtoflag[n.road-1]=0; if (n.y > d.height||n.y<0) { n.y = 10*Math.random(); carperminute[0].carnumbers=carperminute[0].carnumbers+1; } } } repaint(); } Node pick; double pickoldx, pickoldy; Image offscreen; Dimension offscreensize; Graphics offgraphics; final Color selectColor = Color.pink; final Color edgeColor = Color.black; final Color nodeColor = new Color(250, 220, 100); // Displaying Node Onto The Applet public void paintNode(Graphics g, Node n) { int x = (int)n.x; int y = (int)n.y; g.setColor((n==pick) ? selectColor : nodeColor); int w= n.carW; int h=n.carL; g.fillRect(x - w/2, y - h / 2, w, h); g.setColor(Color.black); g.drawRect(x - w/2, y - h / 2, w-1, h-1); g.drawString(".", x-w/2+2, y+h/2-2); } // Displaying Road Onto The Applet public void paintRoad(Graphics g){ Dimension d = size(); g.setColor(Color.gray); for(int k=1; k<4; k++){ g.drawLine(roadleft[k], 0, roadleft[k], roadbottom); g.drawLine(roadleft[k], roadtop, roadleft[k], d.height); g.drawLine(roadright[k], 0, roadright[k], roadbottom); g.drawLine(roadright[k], roadtop, roadright[k], d.height); g.drawLine(roadright[k-1], roadtop, roadleft[k], roadtop); g.drawLine(roadright[k-1], roadbottom, roadleft[k], roadbottom); } g.drawLine(roadright[3], roadbottom, d.width, roadbottom); g.drawLine(roadright[3], roadtop, d.width, roadtop); } public void paintLghtPeriod(Graphics g){ Font warnFont, dispFont, stopFont; warnFont=new Font("Arial", Font.BOLD, 20); dispFont=new Font("Arial", 0, 12); stopFont=new Font("Arial", Font.BOLD, 14); Dimension d = size(); offgraphics.setColor(Color.black); if(LightOrStop==1){ offgraphics.drawString("Traffic Light Period (1: red, 0: green)", 600,50); offgraphics.setColor(Color.red); offgraphics.drawString("red", 714, 50); offgraphics.setColor(Color.green); offgraphics.drawString("green", 747, 50); offgraphics.setColor(Color.black); for(int k=0; k<3; k++){ int tempred= light[k].redpass/200, tempgreen= light[k].greenpass/200; int temp1=roadright[3]+170; int temp2, temp3, temp4, temp5; if (light[k].signal==0){ temp2=temp1+tempred; temp3=30*(k+1)+40; temp4= temp2+tempgreen; temp5=temp3+12; } else{ temp2=temp1+tempgreen; temp3=30*(k+1)+40+12; temp4= temp2+tempred; temp5=temp3-12; } offgraphics.drawString("Light " +Integer.toString(k+1), temp1-40, (temp5+temp3)/2+5); while (temp1<d.width){ offgraphics.drawLine(temp1, temp3, temp2, temp3); offgraphics.drawLine(temp2, temp5, temp4, temp5); offgraphics.drawLine(temp1, temp3, temp1, temp5); offgraphics.drawLine(temp2, temp3, temp2, temp5); temp1=temp4; temp2=temp1+tempred; temp4=temp2+tempgreen; } } offgraphics.setColor(Color.lightGray); offgraphics.fillRect(roadright[3]+328, 30, 15, 130); offgraphics.setColor(Color.gray); offgraphics.drawRect(roadright[3]+120, 20, 223, 145); offgraphics.setColor(Color.black); } else{ offgraphics.setFont(warnFont); offgraphics.setColor(Color.white); offgraphics.fillOval(roadleft[3]+175, roadtop-160, 70, 70); offgraphics.setColor(Color.red); offgraphics.fillOval(roadleft[3]+180, roadtop-155, 60, 60); offgraphics.setColor(Color.white); offgraphics.drawString("STOP", roadleft[3]+183, roadtop-116); offgraphics.setColor(Color.black); offgraphics.setFont(dispFont); offgraphics.drawString("(City)", roadleft[3]+185, roadtop-50); } } public void paintLights(Graphics g){ Font dispFont, stopFont; dispFont=new Font("Arial", 0, 12); stopFont=new Font("Arial", Font.BOLD, 14); g.setFont(dispFont); int lightwidth=15; for(int k=1; k<4; k++){ if(LightOrStop==0){ g.setColor(Color.red); g.fillOval(roadleft[k]-18, roadtop+4, lightwidth, lightwidth); g.setColor(Color.white); g.setFont(stopFont); g.drawString("S", roadleft[k]-14, roadtop+16); g.setFont(dispFont); } else{ g.setColor(Color.black); g.fillRect(roadleft[k]-18, roadtop+4, lightwidth-2, lightwidth-2); g.setColor(light[k-1].signal==1 ? Color.red : Color.green); g.fillOval(roadleft[k]-7, roadtop+6, 6, 9); g.setColor(light[k-1].signal==1 ? Color.green : Color.red); g.fillOval(roadleft[k]-16, roadtop+2, 9, 6); g.setColor(Color.black); g.drawString("Light "+k, roadleft[k]-58, roadtop+17); } } } public void paintAxies(Graphics g){ int temp1=610; int temp2=350; int temp3=temp1+160; int temp4= temp2-80; offgraphics.setColor(Color.gray); offgraphics.drawRect(roadright[3]+120, temp4-35, 220, 130); offgraphics.setColor(Color.black); offgraphics.drawLine(temp1, temp2, temp3, temp2); offgraphics.drawLine(temp3, temp2, temp3-10, temp2-2); offgraphics.drawLine(temp3, temp2, temp3-10, temp2+2); offgraphics.drawLine(temp1, temp2, temp1, temp4); offgraphics.drawLine(temp1, temp4, temp1-2, temp4+10); offgraphics.drawLine(temp1, temp4, temp1+2, temp4+10); for (int k=1; k<4; k++){ int grid=20*k; offgraphics.drawLine(temp1, temp2- grid, temp1+5, temp2- grid); offgraphics.drawString(k+".0", temp1- 20, temp2- grid+5); } offgraphics.drawString("Time", temp3-10, temp2-10); offgraphics.drawString("Traffic Flow ", temp1-20, temp2-95); offgraphics.drawString(" (Cars/Sec.)", temp1-20, temp2-82); for (int k=0; k<40; k++){ if (k>=carperminute[0].count){ temp3=1; offgraphics.setColor(Color.gray); } else{ temp3=2; offgraphics.setColor(Color.black); } offgraphics.drawRect(k*3+temp1, temp2 - (int)(carperminute[0].carflow[k]*20+1), temp3, temp3); } } public synchronized void update(Graphics g) { Dimension d = size(); if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offgraphics = offscreen.getGraphics(); } offgraphics.setColor(getBackground()); offgraphics.fillRect(0, 0, d.width, d.height); paintRoad(offgraphics); //Draws Lights paintLights(offgraphics); //Draws Light Period paintLghtPeriod(offgraphics); //Draws Axis paintAxies(offgraphics); //Draws Cars for (int i = 0 ; i < nnodes ; i++) { paintNode(offgraphics, nodes[i]); } g.drawImage(offscreen, 0, 0, null); } public synchronized boolean mouseDown(Event evt, int x, int y) { double bestdistance = Double.MAX_VALUE; for (int i = 0 ; i < nnodes ; i++) { Node n = nodes[i]; double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y); if (dist < bestdistance) { pick = n; pickoldx=n.x; pickoldy=n.y; bestdistance = dist; } } pick.x = x; pick.y = y; repaint(); return true; } public synchronized boolean mouseDrag(Event evt, int x, int y) { pick.x = x; pick.y = y; repaint(); return true; } public synchronized boolean mouseUp(Event evt, int x, int y) { boolean insidelane; pick.x = x; pick.y = y; insidelane=false; for (int k=1; k<4; k++) if (x>roadleft[k]&&x<roadright[k]) { pick.road=k; pick.x=xpos[k-1]; pick.carW= carwidth; pick.carL= carlength; insidelane=true; } if (!insidelane&&(y<roadtop&&y>roadbottom)) { pick.road=0; pick.y=ypos; pick.carW= carlength; pick.carL= carwidth; } else if(!insidelane) { pick.x=pickoldx; pick.y=pickoldy; } pick = null; repaint(); return true; } public void start() { relaxer = new Thread(this); relaxer.start(); } public void stop() { relaxer.stop(); } } public class Graph extends Applet { GraphPanel panel; int carnumbers; Thread LightThrd[] = new Thread[3]; public void init() { setLayout(new BorderLayout()); panel = new GraphPanel(this); add("Center", panel); carnumbers = Integer.parseInt(getParameter("carnumbers")); carnumbers=Math.min(carnumbers, 70); for (int k=0; k<carnumbers; k++) panel.findNode(Integer.toString(k)); panel.LightOrStop=1; for (int k=0; k<3; k++){ LightThrd[k] = new Thread(panel.light[k]); panel.light[k].redpass=(k+1)*1000+3000; panel.light[k].greenpass=panel.light[k].redpass; LightThrd[k].start(); } panel.carperminute[0].time0 = System.currentTimeMillis(); panel.carperminute[0].carnumbers=0; Panel btpnl=new Panel(); add("South", btpnl); btpnl.add(new Button("Start")); btpnl.add(new Button("End")); btpnl.add(new Button("Stop")); btpnl.add(new Button("Traffic Light")); btpnl.add(new Button("New Schedule: Lights")); } public boolean action(Event evt, Object arg){ if (((Button)evt.target).getLabel().equals("Traffic Light")) { if (panel.LightOrStop==0){ panel.LightOrStop=1; for (int k=0; k<3; k++){ LightThrd[k] = new Thread(panel.light[k]); panel.light[k].redpass=(k+1)*1000+3000; panel.light[k].greenpass=panel.light[k].redpass; LightThrd[k].start(); panel.carperminute[0].time0 = System.currentTimeMillis(); panel.carperminute[0].carnumbers=0; } } } else if (((Button)evt.target).getLabel().equals("Stop")) { panel.LightOrStop=0; for(int k=0; k<3; k++){ if (LightThrd[k].isAlive()) LightThrd[k].stop(); } panel.carperminute[0].time0 = System.currentTimeMillis(); panel.carperminute[0].carnumbers=0; } else if (((Button)evt.target).getLabel().equals("End")) { for(int k=0; k<3; k++){ if (LightThrd[k].isAlive()) LightThrd[k].stop(); } panel.stop(); } else if (((Button)evt.target).getLabel().equals("Start")) { if(panel.LightOrStop==1) for(int k=0; k<3; k++){ if (!LightThrd[k].isAlive()){ LightThrd[k] = new Thread(panel.light[k]); LightThrd[k].start(); } } if (!panel.relaxer.isAlive()) panel.start(); } else if (((Button)evt.target).getLabel().equals("New Schedule: Lights")) { if (panel.LightOrStop==1){ for(int k=0; k<3; k++){ if (LightThrd[k].isAlive()){ panel.light[k].redpass=(int)(Math.random()*6000)+3000; panel.light[k].greenpass=(int)(Math.random()*6000)+3000; } } panel.carperminute[0].time0 = System.currentTimeMillis(); panel.carperminute[0].carnumbers=0; panel.carperminute[0].carwait=0; } } return true; } public void start() { panel.start(); } public void stop() { panel.stop(); } }
- 01-12-2012, 10:12 PM #2
Re: java.lang.Thread has been deprecated
The Thread class has not been deprecated, but several methods are deprecated in Java 7.
Deprecated methods:
countStackFrames()
destroy()
resume()
stop()
stop( Throwable obj )
suspend()
These are also the same deprecated methods in Java 6 Thread class.If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
Similar Threads
-
exception in thread main java.lang.arrayindexoutofboundsexception
By dwill19686 in forum New To JavaReplies: 3Last Post: 02-03-2011, 04:49 PM -
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/star/lang/XEventLi
By baktha.thalapathy in forum New To JavaReplies: 5Last Post: 06-02-2010, 01:05 PM -
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/star/lang/XEventLi
By baktha.thalapathy in forum Advanced JavaReplies: 3Last Post: 06-01-2010, 03:01 PM -
Exception in thread "Thread-22" java.lang.NoClassDefFoundEthen screen just sits there
By bnh14 in forum Java AppletsReplies: 3Last Post: 11-06-2008, 04:24 PM -
java.lang.OutOfMemoryError: unable to create new native thread
By jai135 in forum Java ServletReplies: 11Last Post: 09-01-2008, 10:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks