how to open .drw or .prt file using swing?

Hi Everyone,

I am new to java programming n I m facing a problem in swing.I want to open a perticular drawing file using Java program but the condition is,it should open in the same window.Now,I have managed to open normal txt files n .doc files in the same window using JFileChooser and IO programming.But I dont know what it takes to open a .prt or a .drw file using the same program.

Can you guys plz help me out in this?I think,it is not compatible to open such files...but how to make it compatible then?

I m posting the code here...plz check it n help me out as soon as possible...Thank you very much......

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

public class FileChooseApp1 extends JFrame

implements ActionListener

{

JMenuItem fMenuOpen = null;

JTextArea fTextArea;

File fFile = new File ("default.java");

FileChooseApp1 (String title) {

super (title);

Container cp = getContentPane ();

// Create a user interface.

cp.setLayout ( new BorderLayout () );

fTextArea = new JTextArea ("");

cp.add ( fTextArea, "Center");

JMenu m = new JMenu ("File");

m.add (fMenuOpen = makeMenuItem ("Open"));

JMenuBar mb = new JMenuBar ();

mb.add (m);

setJMenuBar (mb);

setSize (400,400);

}

public void actionPerformed ( ActionEvent e ){

boolean status = false;

String command = e.getActionCommand ();

if (command.equals ("Open")) {

// Open a file

status = openFile ();

}

}

private JMenuItem makeMenuItem (String name) {

JMenuItem m = new JMenuItem (name);

m.addActionListener (this);

return m;

}

boolean openFile () {

JFileChooser fc = new JFileChooser ();

fc.setDialogTitle ("Open File");

// Choose only files, not directories

fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);

// Start in current directory

fc.setCurrentDirectory (new File ("."));

// Set filter for Java source files.

// fc.setFileFilter (fJavaFilter);

// Now open chooser

int result = fc.showOpenDialog (this);

if (result == JFileChooser.CANCEL_OPTION) {

return true;

} else if (result == JFileChooser.APPROVE_OPTION) {

fFile = fc.getSelectedFile ();

// Invoke the readFile method in this class

String file_string = readFile (fFile);

if (file_string != null)

fTextArea.setText (file_string);

else

return false;

} else {

return false;

}

return true;

} // openFile

public String readFile (File file) {

StringBuffer fileBuffer;

String fileString=null;

String line;

try {

FileReader in = new FileReader (file);

BufferedReader dis = new BufferedReader (in);

fileBuffer = new StringBuffer () ;

while ((line = dis.readLine ()) != null) {

fileBuffer.append (line + "\n");

}

in.close ();

fileString = fileBuffer.toString ();

}

catch (IOException e ) {

return null;

}

return fileString;

} // readFile

public static void main (String [] args) {

// Can pass frame title in command line arguments

String title="Frame Test";

if (args.length != 0) title = args[0];

FileChooseApp1 f = new FileChooseApp1 (title);

f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

f.setVisible (true);

} // main

}

[3561 byte] By [Vishal_Borgaonkara] at [2007-11-27 4:40:16]
# 1
Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5173615When you post code, use [code][/code] tags, it makes the code readable. Are you having trouble getting the FileChooser to select the file, or figuring out how to read those file types?
hunter9000a at 2007-7-12 9:51:11 > top of Java-index,Java Essentials,Java Programming...
# 2

well....the issue is,by the above mentioned code,I m able to open all text files like .txt or .doc....but I want to open a file having an extension .eprt or .easm.....these are all drawing related files....how to do that?

what exactly happens when a text file is opened in java...do I need to register these drawing related files somewhere?if yes,wher should I register them?

Thanks a lot.....

Vishal_Borgaonkara at 2007-7-12 9:51:11 > top of Java-index,Java Essentials,Java Programming...