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