0

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

Edited by Slyvr: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Slyvr
0

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

0

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

Ah, thank you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.