A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Look for idea.
Hui Zhao
Ranch Hand
Joined: Jul 09, 2007
Posts: 116
posted
Jul 19, 2007 10:15:00
0
Hi, I am going to read a data file to plot a graph.I follow the steps as:
1) choose file, then return file name.
import java.awt.event.*; import javax.swing.*; import java.io.*; import java.io.File; public class FileSelection extends JPanel { public File getFile() { // display file dialog, so user can choose file to open final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int result = fileChooser.showOpenDialog(this); // if user clicked Cancel button on dialog, return if( result == JFileChooser.CANCEL_OPTION) System.exit(1); File fileName = fileChooser.getSelectedFile(); // get selected file // display error if invalid if ((fileName == null) || (fileName.getName().equals(""))) { JOptionPane.showMessageDialog(this,"Invalid File Name", "Invalid File Name",JOptionPane.ERROR_MESSAGE); System.exit(1); } return fileName; } }
2)to process data by calling the file created in step 1 in another class
public class TestCell { private double ...; String e[]; RandomAccessFile file; BinaryFile bin; public void cellNumber() { try { FileSelection fs = new FileSelection(); File fileName = fs.getFile(); file = new RandomAccessFile(fileName, "r"); DataInputStream in = new DataInputStream(new FileInputStream(fileName));
3)drawing in an
applet
.
public class Combox extends JApplet { private Drawing drawing; public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } }
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
I like...
posted
Jul 19, 2007 10:56:00
0
Is there a question here?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award."
~Joe Strummer
sscce.org
Bert Bates
author
Sheriff
Joined: Oct 14, 2002
Posts: 8717
posted
Jul 19, 2007 11:18:00
0
closing down this duplicate thread
Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
subject: Look for idea.
Similar Threads
Look for idea.
Having Problems with Opening a file...
How do I declare an arrayList and initilise it in a constructor Method
using same actionlistener exit button not working
Background Color for JFileChooser
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter