My troller made in Java [Source code] 04-27-2013, 08:39 PM
#1
I was playing a little around, and ended up with this "Troller".
What it is doing:
Let's says I writes "Pie" in a textarea, and after that opens a .txt file on the computer, and maybe changes something in it. I presses "save", and thinks "great
", but when I opens it next time, it just says "Pie". That's what it's doing.
Code:
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import javax.swing.event.*;
public class fine extends JFrame implements ActionListener{
private JMenuBar mu = new JMenuBar();
private JMenu me = new JMenu("File");
private JMenuItem muit = new JMenuItem("new");
private JMenuItem muit2 = new JMenuItem("open");
private JMenuItem muit3 = new JMenuItem("save");
private JTextArea tf = new JTextArea(20 , 20);
String s;
public fine(){
super("the title");
setLayout(new FlowLayout());
getContentPane().setBackground(Color.GREEN);
me.add(muit);
me.add(muit2);
me.add(muit3);
mu.add(me);
add(mu);
JScrollPane scroller = new JScrollPane(tf);
JScrollBar bar = new JScrollBar();
scroller.add(bar);
add(tf);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(150,100);
muit2.addActionListener(this);
muit3.addActionListener(this);
}
public void actionPerformed(ActionEvent ev){
s = ev.getActionCommand();
if(s == "new"){
String k = null;
tf.append(k);
}
if(s == "save"){
JFileChooser chooser = new JFileChooser();
chooser.showSaveDialog(this);
loadFile2(chooser.getSelectedFile());
}
if(s =="open"){
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(this);
loadFile(chooser.getSelectedFile());
}
}
private void loadFile(File file) {
try {
FileInputStream fi2 = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
while ((line = reader.readLine()) != null) {
tf.append(line);
}
reader.close();
} catch(Exception ex) {
System.out.println("couldn't read the card file");
ex.printStackTrace();
}
}
public void loadFile2(File file){
try {
FileOutputStream fo = new FileOutputStream(file);
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(tf.getText());
writer.close();
}
catch(Exception e){
}
}
public static void main(String args[]){
fine fi = new fine();
}
}What it is doing:
Let's says I writes "Pie" in a textarea, and after that opens a .txt file on the computer, and maybe changes something in it. I presses "save", and thinks "great
", but when I opens it next time, it just says "Pie". That's what it's doing.



![[Image: crypto-gambling.net-logo-205x40.png]](https://crypto-gambling.net/wp-content/uploads/2020/10/crypto-gambling.net-logo-205x40.png)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
