954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Misplace constructs?

I'm working on a really basic text editor to save and open txt files. On my text area setLineWrap, it's giving me a "misplaced constructs" and "delete token" for the period and (true)
For why?

/**Matthew Schrum
 *11/18/2010
 */

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class TxtEdit extends JFrame{
	
  boolean isStandalone = false;
  JPanel jPanel1 = new JPanel();
  JTextArea jta = new JTextArea();
  JScrollPane jScrollPane = new JScrollPane(jta);
  jta.setLineWrap(true);
  TitledBorder titledBorder1 = new TitledBorder("");
  JButton btnSave = new JButton("Save");
  JButton btnOpen = new JButton("Open");
  // Create a button group
  ButtonGroup btg = new ButtonGroup();
  

  //Component initialization
  public TxtEdit() {
	this.setSize(new Dimension(400, 300));
    jPanel1.setBorder(titledBorder1);


    this.getContentPane().add(jScrollPane, BorderLayout.CENTER);

    this.getContentPane().add(jPanel1, BorderLayout.NORTH);
    jPanel1.add(btnSave, null);
    jPanel1.add(btnOpen, null);

    // Group buttons
    btg.add(btnSave);
    btg.add(btnOpen);
    
    //Save Button
    btnSave.addActionListener(
    		new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				Boolean tryit=false;
    				try{
    					final Writer fw = new FileWriter(new File("Save.txt"));
    					fw.write(jta.getText());
    					tryit=true;
    					fw.close();
    				}
    				catch(IOException exception){tryit=false;}
    				if (tryit==true){
    					System.out.println("Saved file to Save.txt");
    				}
    			}
    		}
    );
    	
  }//end TxtEdit

  //Main method
  public static void main(String[] args) {
    TxtEdit frame = new TxtEdit();
    frame.setTitle("TxtEdit");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 320);
    frame.setLocationRelativeTo(null); // Center the frame
    frame.setVisible(true);  
  }//end main
}//end class


Much Thanks,
Slyvr

Slyvr
Junior Poster in Training
74 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

You are trying to set the line wrap too early. Try to move the jta.setLineWrap(true) inside your TxtEdit constructor.

Slimmy
Junior Poster in Training
71 posts since Oct 2010
Reputation Points: 11
Solved Threads: 11
 
You are trying to set the line wrap too early. Try to move the jta.setLineWrap(true) inside your TxtEdit constructor.

Ah, thank you.

Slyvr
Junior Poster in Training
74 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: