Results 1 to 6 of 6
- 04-23-2010, 09:13 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Traffic Organizing In JAVA2D Problems
hi everybody,
please try to understand me becuase my english is not so good..
i study in Damasucs university,IT..
i have a project : Traffic Organizing
i used java2D to draw Map
i made very good work until now
but I have some problems:
1-how can i save the new map (that the user draw it)..
2-when the user load an image from PC some parts of it disapear and after seconds it apears or after click on some part on screen >>> how can make it apear always ...
this the code :
Java Code:try{ Graphics2D g2=(Graphics2D)jPanel6.getGraphics(); File file = new File( "src/Maps/Capture.jpg" ); FileInputStream inputStream = new FileInputStream( file ); JPEGImageDecoder decoder =JPEGCodec.createJPEGDecoder( inputStream ); BufferedImage image = decoder.decodeAsBufferedImage(); g2.drawImage(image, 0,0,image.getWidth(), image.getHeight(),this); }
and this the code of dialog to load the image :
Java Code:try { JFileChooser jFileChooser1=new JFileChooser(); int response = jFileChooser1.showOpenDialog( this ); if (response==JFileChooser.APPROVE_OPTION) { File FileName =jFileChooser1.getSelectedFile(); Image_Loaded_Name=FileName.getAbsolutePath(); jLabel1.setText(FileName.getName()); FileInputStream inputStream = new FileInputStream(Image_Loaded_Name); JPEGImageDecoder decoder =JPEGCodec.createJPEGDecoder( inputStream ); Back_Image=decoder.decodeAsBufferedImage(); } } catch(Exception e) { }
and this the code of drawing streets and map :
3- when i resize the window the graphics also disapear >>Java Code:g4=(Graphics2D)jPanel4.getGraphics(); g4.drawImage(Back_Image,0,0,Back_Image.getWidth(),Back_Image.getHeight(),null); double dx,dy; stroke1 = new BasicStroke(6,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0,dashPattern1, 0); stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0,dashPattern, 0); for(int i=0;i<counter-1 ;i++) { if (points[i][0]!=-10000000&&points[i+1][0]!=-10000000) { dx=Math.abs(points[i][0]-points[i+1][0]); dy=Math.abs(points[i][1]-points[i+1][1]); g4.setColor(Color.DARK_GRAY); g4.setFont(new Font("",2,16)); g4.setStroke(stroke1); g4.draw(new Line2D.Double(points[i][0],points[i][1],points[i+1][0],points[i+1][1])); g4.setStroke(stroke2); g4.setColor(Color.white); g4.draw(new Line2D.Double(points[i][0],points[i][1],points[i+1][0],points[i+1][1])); } } for (int i=0;i<node_counter ;i++) { g4.setColor(Color.blue); Ellipse2D e1=new Ellipse2D.Float(points_circle[i][0], points_circle[i][1], radius_node, radius_node); Ellipse2D e2=new Ellipse2D.Float(points_circle[i][0]+2, points_circle[i][1]+2, radius_node-4, radius_node-4); g4.draw(e1); g4.draw(e2); }
:confused::confused:
please try to help me:oLast edited by tamer; 04-23-2010 at 09:18 AM.
-
Read the Sun tutorials on using graphics in Swing and Java2D as this is not how you're supposed to paint. You'll want to instead use the paintComponent method, and the tutorials will show you how. Much luck.
- 04-25-2010, 07:14 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
I tried the paint component before and i tried again >>>
it didn't work >>>
ok..... look the problem that when i open dailog (load,save) some part of the map(i.e the graphics in the panel) disapear ...
is there any other solution...
thanks for helping me...
-
- 04-25-2010, 11:16 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
ohhhh it's done .....
thanx the problem solved by this code
:):)Java Code:@Override public void paint( Graphics g) { super.paintComponents(g); Draw(); }
thanx very much ...Last edited by tamer; 04-25-2010 at 11:18 PM.
-
This looks like dangerous code that I suggest you fix quickly. You should not be calling the super.paintComponent method from within a paint override. Instead I suggest that you override paintComponent and call the super paintComponent method from within it. Ignore this advice at your own risk. Best of luck.
Similar Threads
-
Help with my traffic light program
By topps in forum New To JavaReplies: 4Last Post: 04-09-2010, 02:56 PM -
organizing elements in the jpanel/jbox
By okabeer in forum AWT / SwingReplies: 7Last Post: 04-15-2009, 12:42 PM -
Generate IP/Ethernet traffic
By vincent2001@gmail.com in forum New To JavaReplies: 0Last Post: 08-22-2008, 10:08 PM -
organizing larger application code / modules
By zenner in forum Advanced JavaReplies: 5Last Post: 07-28-2008, 09:18 AM -
Traffic simulator
By dirtycash in forum New To JavaReplies: 1Last Post: 03-12-2008, 03:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks