It really interested me, I thought it was very cool to try to make my own text editor, no matter how simple it is. So I wrote the code, reading the notes and understanding most of it, but it wont compile. it says it cant find the main class texttest001.TextTest001, I've tried to copy the tutorials script and renaming the directories to NutPad, still no luck ): I would greatly appreciate any help!
Heres my script:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class TextTest001 extends JFrame {
private JTextArea _editArea;
private JFileChooser _fileChooser = new JFileChooser();
private Action _openAction = new OpenAction();
private Action _saveAction = new SaveAction();
private Action _exitAction = new ExitAction();
public static void main(String[] args) {
new TextTest001();
}
public TextTest001() {
_editArea = new JTextArea(15, 80);
_editArea.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
_editArea.setFont(new Font("monospaced", Font.PLAIN, 14));
JScrollPane scrollingText = new JScrollPane(_editArea);
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(scrollingText, BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = menuBar.add(new JMenu("File"));
fileMenu.setMnemonic('F');
fileMenu.add(_openAction);
fileMenu.add(_saveAction);
fileMenu.addSeparator();
fileMenu.add(_exitAction);
setContentPane(content);
setJMenuBar(menuBar);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("TextTest001");
pack();
setLocationRelativeTo(null);
setVisible(true);
}
class OpenAction extends AbstractAction {
public OpenAction() {
super("Open...");
putValue(MNEMONIC_KEY, new Integer('O'));
}
public void actionPerformed(ActionEvent e) {
int retval = _fileChooser.showOpenDialog(TextTest001.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File f = _fileChooser.getSelectedFile();
try {
FileReader reader = new FileReader(f);
_editArea.read(reader, "");
} catch (IOException ioex) {
System.out.println(e);
System.exit(1);
}
}
}
}
class SaveAction extends AbstractAction {
SaveAction() {
super("Save...");
putValue(MNEMONIC_KEY, new Integer('S'));
}
public void actionPerformed(ActionEvent e) {
int retval = _fileChooser.showSaveDialog(TextTest001.this);
if (retval == JFileChooser.APPROVE_OPTION) {
file f = _fileChooser.getSelectedFile();
try {
FileWriter writer = new FileWriter(f);
_editArea.write(writer);
} catch (IOException ioex) {
JOptionPane.showMessageDialog(TextTest001.this, ioex);
System.exit(1);
}
}
}
}
class ExitAction extends AbstractAction {
public ExitAction() {
super("Exit");
putValue(MNEMONIC_KEY, new Integer('X'));
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}

New Topic/Question
Reply




MultiQuote







|