Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008, 09:10 PM
Member
 
Join Date: Jun 2008
Posts: 1
Sticks_ll is on a distinguished road
save will work but load wont?!?!
hi i have a program which I thought i had working, I now find the load button wont function properly and don't know how i can go about fixing it. I need to hand this in tomorrow so any help would be much appreciated. ty
here is the code:

Code:
import java.awt.Event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.*; import java.io.*; import java.util.*; import javax.swing.*; import java.util.EventObject.*; public class save extends JFrame implements ActionListener,MouseListener { private JTextArea coord; private JButton Reflect,Link,Save,Load,Quit; private JPanel Drawing; private ArrayList Array; private BufferedReader inFile; PrintWriter outFile; private PrintWriter outfile; private String values = " "; public static void main(String[] args) { save mygoblet = new save(); } public save() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); setSize(650,600); Drawing = new JPanel(); Drawing.setPreferredSize(new Dimension(500,400)); c.add(Drawing); Drawing.setBackground(Color.RED); Drawing.addMouseListener(this); coord = new JTextArea(25,6); c.add(coord); Reflect = new JButton("Reflect"); c.add(Reflect); Reflect.addActionListener(this); Link = new JButton("Link"); c.add(Link); Link.addActionListener(this); Save = new JButton("Save"); c.add(Save); Save.addActionListener(this); Load = new JButton("Load"); c.add(Load); Load.addActionListener(this); Quit = new JButton("Quit"); c.add(Quit); Quit.addActionListener(this); show(); Array = new ArrayList(); } public void mouseClicked(MouseEvent arg0) { } public void mousePressed(MouseEvent arg0) { Graphics g = Drawing.getGraphics(); int x,y; x = arg0.getX(); y = arg0.getY(); Array.add("" + x); Array.add("" + y); values = values + arg0.getX()+","+arg0.getY()+'\n'; coord.setText(values); g.drawLine(x-2,y-2,x+2,y+2); g.drawLine(x+2,y-2,x-2,y+2); } public void mouseReleased(MouseEvent arg0) { } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { } public void actionPerformed(ActionEvent arg0) { if (arg0.getSource()==Reflect) { reflect(); } // { if(arg0.getSource()==Link) { Graphics g = Drawing.getGraphics(); int x,x1=0,y,y1=0; for(int loop =0;loop<Array.size();loop+=2){ x=Integer.parseInt((String)Array.get(loop)); y=Integer.parseInt((String)Array.get(loop+1)); if(loop+2<Array.size()) x1=Integer.parseInt((String)Array.get(loop+2)); if(loop+3<Array.size()) y1=Integer.parseInt((String)Array.get(loop+3)); g.drawLine(x,y,x1,y1); g.drawLine(Drawing.getWidth()- x,y,Drawing.getWidth()-x1,y1); g.setColor(Color.black); // { x=Integer.parseInt((String)Array.get(loop)); y=Integer.parseInt((String)Array.get(loop+1)); x1=Drawing.getWidth()-x; g.drawLine(x,y,x1,y); // } } } else if(arg0.getSource() == Save){ System.out.println("This is a Save page"); final JFileChooser fs = new JFileChooser(); int save = fs.showSaveDialog(save.this); if (save ==JFileChooser.APPROVE_OPTION){ File file = fs.getSelectedFile(); for(int loop =0;loop<Array.size();loop++)/////////////////////////// try { outFile = new PrintWriter (new FileWriter(file),true); outFile.print(Array); outFile.close(); } catch(IOException e) { JOptionPane.showMessageDialog(null,"File error"+e.toString()); } } } else if (arg0.getSource() == Load) { { rootPaneCheckingEnabled = true; FileDialog getNameBox; String fileName; getNameBox = new FileDialog(this, " open File",FileDialog.LOAD); getNameBox.show(); fileName = getNameBox.getDirectory()+ getNameBox.getFile(); //Attempt to open named file try { inFile = new BufferedReader(new FileReader(fileName)); String line; JTextArea coordinates = null; coord.setText(""); while ((line = inFile.readLine())!= null) coordinates.append(line+"\n"); inFile.close(); } catch(IOException e) { JOptionPane.showInputDialog(null,"File error" + e,toString()); } { } } } if(arg0.getSource()==Quit) { System.exit(0); } } // } // } private void reflect(){ int x,y,newx; Graphics g = Drawing.getGraphics(); for(int loop = 0; loop<Array.size();loop+=2) {x = Integer.parseInt((String) Array.get(loop)); y = Integer.parseInt((String) Array.get(loop+1)); newx = Drawing.getWidth()-x; g.drawLine(newx-2,y-2,newx+2,y+2); g.drawLine(newx+2,y-2,newx-2,y+2); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2008, 06:19 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Specify your question early. What you have done in load button. Reading a long code id not much easier.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Save/Load Vector to/from file Java Tip java.lang 0 04-14-2008 10:37 PM
[SOLVED] Last line in JTextArea wont display Chris.Brown.SPE Advanced Java 5 04-11-2008 03:52 PM
Load URL that contains spaces? barkster Java Applets 0 01-30-2008 11:40 PM
How can i save the data Internally(auto save) Rama Koti Reddy AWT / Swing 0 12-10-2007 03:46 PM
simple problem - code wont compile dirtycash New To Java 1 11-20-2007 07:49 PM


All times are GMT +3. The time now is 01:56 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org