![]() String classString = o.getClass().getName() Returns just the class name - no package info. If(answer.equalsIgnoreCase("y") || answer.equalsIgnoreCase("yes")) if the user wants to save, call the save file method "You have not saved changes to this file, would you like to save your changes?") If(command.equals("New.")) //the New file option was selectedĮlse if(command.equals("Open."))//the Open file option was selectedĮlse if(command.equals("Save."))//the Save file option was selectedĮlse if(command.equals("Save As."))//the Save file option was selectedĮlse if(command.equals("Exit."))//the Exit program option was selectedĪnswer = JOptionPane.showInputDialog(null, tCaretPosition(output.getDocument().getLength()) Public void actionPerformed(ActionEvent ae) tFont(new Font("Monospaced", Font.PLAIN, 12)) ĬontentPane.add(scrollPane, BorderLayout.CENTER) JPanel contentPane = new JPanel(new BorderLayout()) JOptionPane.showMessageDialog(null, "You must create or open a document before saving.") JOptionPane.showMessageDialog(null, "Save command cancelled by user.") JOptionPane.showMessageDialog(null, "Saving " + file.getName() + ".") If(returnVal = JFileChooser.APPROVE_OPTION) JOptionPane.showMessageDialog(null, "Writing " + file.getName() + " to " + directory) Writer = new BufferedWriter(new FileWriter(file)) Reader = new BufferedReader(new InputStreamReader(new FileInputStream(currentFile))) Public void writeFileData(File directory, File file) JOptionPane.showMessageDialog(null, "Open command cancelled by user.") JOptionPane.showMessageDialog(null, "Opening " + file.getName() + ".") If(returnVal = JFileChooser.APPROVE_OPTION) //user selected and file and hit 'open'ĬurrentFile = file = fc.getSelectedFile() prompt the user with the open file dialog MenuItem.getAccessibleContext().setAccessibleDescription(description) JMenuItem menuItem = new JMenuItem(name) Public JMenuItem createMenuItem(String name, String description, boolean actionListener) * actionListener Whether or not this JMenuItem will need to register an * description The description of the JMenuItem "and save documents, as well as exit the program") įileMenu.add(createMenuItem("New.", "Lets users create a new document", true)) įileMenu.add(createMenuItem("Open.", "Lets users open a document", true)) įileMenu.add(createMenuItem("Save.", "Lets users save a document", true)) įileMenu.add(createMenuItem("Save As.", "Lets users save a document", true)) įileMenu.add(createMenuItem("Exit.", "Lets users exit the program", true)) "This is the File menu, users can create, open, " + JMenuItem newMenuItem, openMenuItem, saveMenuItem, exitMenuItem įileMenu.getAccessibleContext().setAccessibleDescription( Public class JTextEditor implements ActionListener java that looks like this with comments organized the way I want them: Is there anyway to keep the formatting the same? While((line = reader.readLine()) != null) reads an input file and displays it in the text areaīufferedReader reader = new BufferedReader(new InputStreamReader(file)) JAVA CREATE NEW FILE MENU CODEThe actual code is ok but the comments always get messed up. java file into a JTextArea and no matter what method I use to read in the file the formatting is never preserved. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |