in java plz and not using bufferedreader or bufferedwriter!!
Write an application that implements a simple text editor. Use a text field and a button to get the file. Read the entire file as characters and display it in a TextArea. The user will then be able to make changes in the text area. Use a Save button to get the contents of the text area and write that over the text in the original file.
Hint: Read each line from the file and then display the line in the text area using a method, maybe called appendText(aString). A method, maybe called getText, will return all of the text area in a string that then can be written to the file.
Please find the code below:
SimpleTextEditor.java
package graphichal;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class SimpleTextEditor{
SimpleTextEditor(){
//main class
final JFrame f=new JFrame(); //we
are using jframe
f.setPreferredSize(new
Dimension(600,900));
f.setLayout(null);
final JTextField filename=new
JTextField();
filename.setBounds(0, 0,
270,30);
f.add(filename);
JButton openfile=new
JButton("open file");
openfile.setBounds(300, 0,
270,30);
f.add(openfile);
final JTextArea display=new
JTextArea();
display.setBounds(50, 50,
400,700);
f.add(display);
openfile.addActionListener(new
ActionListener() {
@Override
public void
actionPerformed(ActionEvent arg0) {
Scanner sc = new Scanner(System.in);
File file = new File(filename.getText());
//reading data from this file
Scanner reader;
String line="";
try {
reader = new
Scanner(file);
while(reader.hasNextLine()){
line +=
reader.nextLine()+"\n";
}
JOptionPane.showMessageDialog(null, "File loaded
successfully");
display.setText(line);
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "file not found");
}
sc.close();
}
});
JButton save=new
JButton("save");
save.setBounds(100, 750,
270,30);
f.add(save);
save.addActionListener(new
ActionListener() {
@Override
public void
actionPerformed(ActionEvent arg0) {
try {
PrintWriter outputFile = new
PrintWriter(filename.getText());
outputFile.write(display.getText());
outputFile.close();
JOptionPane.showMessageDialog(null, "File saved
successfully");
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "file not found");
}
}
});
f.pack();
f.setVisible(true);
}
public static void main(String[] args){
SimpleTextEditor f = new
SimpleTextEditor();
}
}
output:
test.txt
at
ordeals
abcdefghijklmnopqrstuvwxyz
abcdefghijklmabcdefghijklm
abcdABCDabcd
sadf
dsafdsa
fds
fsd
asdf
asdf
asdf
asdfsadfadsfsadfasdfasd
f
sadf
sad
asdffffffffffffffffffffffffffffffffffffffffffferfdsaafedf
in java plz and not using bufferedreader or bufferedwriter!! Write an application that implements a simple...
USING JAVA and NOTTT using BufferedReader or BufferedWriter Write an application that implements a simple text editor. Use a text field and a button to get the file. Read the entire file as characters and display it in a TextArea. The user will then be able to make changes in the text area. Use a Save button to get the contents of the text area and write that over the text in the original file. Hint: Read each line from...
JAVA Write an application to test the HuffmanTree class. Your application will need to read a text file and build a frequency table for the characters occurring in that file. Once that table is built create a Huffman code tree and then a string consisting of 0 and 1 characters that represents the code string for that file. Read that string back in and re-create the contents of the original file. Prompt the user for file name. Read the file,...
Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use...
Using java Create a simple queue class and a simple stack class. The queue and stack should be implemented as a linked list. Create three functions that utilize these data structures Write a function that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse...
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...
I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...
In Java code Write a complete method name convertFile that accepts a File object representing an input text file and a PrintWriter objects as arguments. The method should read the contents of the input file and change all characters to uppercase and store the results in the output file.
A. Create a java program that generates 1000 random integers. Write the 1000 random integers to a file using the Formatter class. B. Create a second java program that opens the file with the 1000 integers using the Scanner class. Read in the integers and find and print out the largest, smallest and the average of all 1000 numbers. C. Repeat A from above but use the BufferedWriter class B. Repeat B from above but use the BufferedReader class.
Write a Java application that implements the recursive Binary Search alogrithm below: Write a Java application that implements the recursive Binary Search alogrithm below:/** * Performs the standard binary search using two comparisons * per level. This is a driver that calls the recursive method * @return index where item is found or NOT FOUND if not found */public static <AnyType extends Comparable<? super AnyType>> int binarySearch(AnyType [] a, AnyType x) {return binarySearch(a, x, 0, a.length -1);}/** * Hidden recursive...
i need this done in java plz, add comments for every single method. also, make as simple as possible. 3. Write a GUI for computing the statistics of numbers input from the user. The GUI should have a text field and a button for adding floating point numbers. Each time a number is entered have a label show the current max, min and average. Have your GUI accept numbers whether the button is pressed or the enter key is pressed...