opening a shape file

We are developing a map viewing software. We are not able to implement

Page 1 of 1

4 Replies - 3147 Views - Last Post: 28 February 2007 - 10:08 AM Rate Topic: -----

#1 varkan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-February 07

opening a shape file

Posted 27 February 2007 - 03:57 AM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.*;
import java.io.*;

class MenuFrame extends Frame
{
	  MenuItem   item1, item2, item3, item4, item5, item6,  
					   item7, item8; 
	  

	   public MenuFrame(String title)
	   {
		  super (title);
		  CheckboxMenuItem debug;
		  MenuBar mbar=new MenuBar();
		  setMenuBar (mbar);
		  Menu file=new Menu("File");
		  debug=new CheckboxMenuItem("Debug");
		  file.add(item1= new MenuItem("New"));
		  file.add(item2= new MenuItem("Open.."));
		  file.add(item3= new MenuItem("Save"));
		  file.add(item4= new MenuItem("Save As.."));
		  file.add(item5= new MenuItem("Print"));
		  file.add(item6= new MenuItem("Import"));
		  file.add(item7= new MenuItem("Export"));
		  file.add(item8= new MenuItem("Exit"));
		  mbar.add(file);


		  //coding for edit
		  
		 Menu analyse=new Menu("Analysis");
		  /* MenuItem item9,item10,item11,item12,item13; 
		  edit.add(item9= new MenuItem("Cut"));
		  edit.add(item10= new MenuItem("Copy.."));
		  edit.add(item11= new MenuItem("Paste"));
		  edit.add(item12= new MenuItem("Delete"));
		  edit.add(item13= new MenuItem("Select All"));*/
		  mbar.add(analyse);
	 
	  Menu navigate=new Menu("Navigation");
		  Menu sub=new Menu("Zoom");
	  MenuItem item14,item15,item16;
	  sub.add(item14= new MenuItem("Zoom In"));
		  sub.add(item15= new MenuItem("Zoom Out"));
		  navigate.add(sub);
		  navigate.add(item16= new MenuItem("Pan"));
		  mbar.add(navigate);
					
		  MyMenuHandler handler=new MyMenuHandler(this);
		  item1.addActionListener(handler);
		  item2.addActionListener(handler);
		  item3.addActionListener(handler);
		  item4.addActionListener(handler);
		  item5.addActionListener(handler);
		  item6.addActionListener(handler);
		  item7.addActionListener(handler);
	  item8.addActionListener(handler);
		  
	  debug.addItemListener(handler);
	  MyWindowAdapter adapter=new	
							  MyWindowAdapter(this);
	  addWindowListener(adapter);
	 }  
}		  
 
			  

class MyWindowAdapter extends WindowAdapter
{
	MenuFrame menuFrame;
	public MyWindowAdapter(MenuFrame menuFrame)
	{
		this.menuFrame= menuFrame;
	}
	public void windowClosing(WindowEvent we)
	{
		menuFrame.dispose();
	}
}

class MyMenuHandler implements ActionListener,ItemListener
{
	
	MenuFrame menuFrame;
	String filename = null;
	
	public void FileDialog (Frame f)
	{
	}
	public MyMenuHandler(MenuFrame menuFrame)
	{
		this.menuFrame= menuFrame;
	}
} 
public class MapView1 extends Applet
 {
	
	/* Initialization method that will be called after the applet 
		 is loaded into the browser.
	 */
	 
	 Frame fs;
	 
	 String msg="";
	 public void init()
	 {
		fs=new MenuFrame("Map Viewing");
	int width=Integer.parseInt(getParameter("Width"));
	int height=Integer.parseInt(getParameter("height"));
	setSize(new Dimension(width,height));
	fs.setSize(width,height);
	fs.setVisible(true);
		// TODO start asynchronous download of heavy 
		//resources
	}
	
	public void start()
   {
		  fs.setVisible (true);
	}

	public void stop()
	{
		  fs.setVisible (false);
	  }
 }


Is This A Good Question/Topic? 0
  • +

Replies To: opening a shape file

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: opening a shape file

Posted 27 February 2007 - 07:45 AM

Can you please specify the problem you are encountering? A short description along with any error messages being generated would be much appreciated. thanks.
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: opening a shape file

Posted 27 February 2007 - 08:10 AM

I must agree, there is a lot of code for us to be able to guess the problem.

*Please remember to use [code ][ /code] tags around your code segments, especially large ones like this.
Was This Post Helpful? 0
  • +
  • -

#4 varkan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-February 07

Re: opening a shape file

Posted 28 February 2007 - 01:40 AM

View Postvarkan, on 28 Feb, 2007 - 02:10 PM, said:

We actually want to open a shape file. First for this we are trying to open text file, which we are not able to implement. Can you please help by giving us code for opening a file (text or shape) in Java.


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.*;
import java.io.*;

class MenuFrame extends Frame
{
	  MenuItem   item1, item2, item3, item4, item5, item6,  
					   item7, item8;
	  

	   public MenuFrame(String title)
	   {
		  super (title);
		  CheckboxMenuItem debug;
		  MenuBar mbar=new MenuBar();
		  setMenuBar (mbar);
		  Menu file=new Menu("File");
		  debug=new CheckboxMenuItem("Debug");
		  file.add(item1= new MenuItem("New"));
		  file.add(item2= new MenuItem("Open.."));
		  file.add(item3= new MenuItem("Save"));
		  file.add(item4= new MenuItem("Save As.."));
		  file.add(item5= new MenuItem("Print"));
		  file.add(item6= new MenuItem("Import"));
		  file.add(item7= new MenuItem("Export"));
		  file.add(item8= new MenuItem("Exit"));
		  mbar.add(file);


		  //coding for edit
		  
		 Menu analyse=new Menu("Analysis");
		  /* MenuItem item9,item10,item11,item12,item13;
		  edit.add(item9= new MenuItem("Cut"));
		  edit.add(item10= new MenuItem("Copy.."));
		  edit.add(item11= new MenuItem("Paste"));
		  edit.add(item12= new MenuItem("Delete"));
		  edit.add(item13= new MenuItem("Select All"));*/
		  mbar.add(analyse);
	
	  Menu navigate=new Menu("Navigation");
		  Menu sub=new Menu("Zoom");
	  MenuItem item14,item15,item16;
	  sub.add(item14= new MenuItem("Zoom In"));
		  sub.add(item15= new MenuItem("Zoom Out"));
		  navigate.add(sub);
		  navigate.add(item16= new MenuItem("Pan"));
		  mbar.add(navigate);
					
		  MyMenuHandler handler=new MyMenuHandler(this);
		  item1.addActionListener(handler);
		  item2.addActionListener(handler);
		  item3.addActionListener(handler);
		  item4.addActionListener(handler);
		  item5.addActionListener(handler);
		  item6.addActionListener(handler);
		  item7.addActionListener(handler);
	  item8.addActionListener(handler);
		  
	  debug.addItemListener(handler);
	  MyWindowAdapter adapter=new	
							  MyWindowAdapter(this);
	  addWindowListener(adapter);
	 }  
}		  

			  

class MyWindowAdapter extends WindowAdapter
{
	MenuFrame menuFrame;
	public MyWindowAdapter(MenuFrame menuFrame)
	{
		this.menuFrame= menuFrame;
	}
	public void windowClosing(WindowEvent we)
	{
		menuFrame.dispose();
	}
}

class MyMenuHandler implements ActionListener,ItemListener
{
	
	MenuFrame menuFrame;
	String filename = null;
	
	public void FileDialog (Frame f)
	{
	}
	public MyMenuHandler(MenuFrame menuFrame)
	{
		this.menuFrame= menuFrame;
	}
}
public class MapView1 extends Applet
{
	
	/* Initialization method that will be called after the applet
		 is loaded into the browser.
	 */
	
	 Frame fs;
	
	 String msg="";
	 public void init()
	 {
		fs=new MenuFrame("Map Viewing");
	int width=Integer.parseInt(getParameter("Width"));
	int height=Integer.parseInt(getParameter("height"));
	setSize(new Dimension(width,height));
	fs.setSize(width,height);
	fs.setVisible(true);
		// TODO start asynchronous download of heavy
		//resources
	}
	
	public void start()
   {
		  fs.setVisible (true);
	}

	public void stop()
	{
		  fs.setVisible (false);
	  }
}

Was This Post Helpful? 0
  • +
  • -

#5 Ryan Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 14-February 07

Re: opening a shape file

Posted 28 February 2007 - 10:08 AM

HERE is a section on java.io.

Hopefully that helps.

Here is saving a text file:
try {
		BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
		out.write("aString");
		out.close();
	} catch (IOException e) {
	}



... and here is reading from it:
try {
		BufferedReader in = new BufferedReader(new FileReader("infilename"));
		String str;
		while ((str = in.readLine()) != null) {
			process(str);
		}
		in.close();
	} catch (IOException e) {
	}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1