![]() |
|
My troller made in Java [Source code] - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.ly/Forum-Java-JVM-JRE) +--- Thread: My troller made in Java [Source code] (/Thread-My-troller-made-in-Java-Source-code) |
My troller made in Java [Source code] - ProTech - 04-27-2013 I was playing a little around, and ended up with this "Troller". 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.
RE: My troller made in Java [Source code] - Sunlight - 04-27-2013 Nice little trolling program. RE: My troller made in Java [Source code] - ProTech - 04-27-2013 (04-27-2013, 08:43 PM)Sunlight Wrote: Nice little trolling program.Yeah, but if you uses this on a friend, you could ending up dying :angel: I sent it to a friend, and he saved a password for a site. He could remember it, but pretty funny xD! |