• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

hNOTE [Java|NotePad]

Banned
Banned
Joined
Dec 23, 2013
Messages
134
Reaction score
10
Basically a simple notepad written in java for lols, I was bored. Either way, Here we go ; -

iIg3Jjv - hNOTE [Java|NotePad] - RaGEZONE Forums


Here, we create two classes, Grid.Java and hNote.java along with few simple methods, in grid java which is then called in hNote.java.
As you can see in the pic, It also has a small menu of New,Open Save and Exit, Which works , you know how.
It's very basic notepad, Just for the lols. Have fun here's the code , xo

PHP:
import javax.swing.JFrame;

public class hNote {
 
    public static void main(String args[])
    {
        JFrame frame = new grid();
        frame.setTitle("hNote");
        frame.setVisible(true);
        frame.setSize(1280,720);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(true);
        frame.setLocationRelativeTo(null);
     
    }
     

}

hNOTE.Java( Our main class)


PHP:
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class grid extends JFrame{
    int fileToOpen;
    int fileToSave;
    JFileChooser fileOpen;
    JFileChooser fileSave;
    grid(){
        MenuBar menuBar = new MenuBar();
        MenuItem menutem = new MenuItem();
        final JTextArea textArea = new JTextArea();
        setMenuBar(menuBar);
        Menu file = new Menu("File");
        menuBar.add(file);
        MenuItem newOption = new MenuItem("New");
        MenuItem open = new MenuItem("Open");
        MenuItem save = new MenuItem("Save");
        MenuItem close = new MenuItem("Exit");
        file.add(newOption);
        file.add(open);
        file.add(save);
        file.add(close);
        getContentPane().add(textArea);
        newOption.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                textArea.setText("");
            }
        });
        open.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                openFile();
                if (fileToOpen == JFileChooser.APPROVE_OPTION){
                    textArea.setText("");
                    try{
                        Scanner scan = new Scanner(new FileReader(fileOpen.getSelectedFile().getPath()));
                        while (scan.hasNext())
                            textArea.append(scan.nextLine());
                    } catch (Exception ex){
                        System.out.println(ex.getMessage());
                    }
                }
            }
        });
        save.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                saveFile();
                if (fileToSave == JFileChooser.APPROVE_OPTION){
                    try {
                        BufferedWriter out = new BufferedWriter(new FileWriter(fileSave.getSelectedFile().getPath()));
                        out.write(textArea.getText());
                        out.close();
                    } catch (Exception ex) {
                        System.out.println(ex.getMessage());
                    }
                }
            }
        });
        close.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                System.exit(0);
            }
        });
    }
    public void openFile(){
        JFileChooser open = new JFileChooser();
        int option = open.showOpenDialog(this);
        fileToOpen = option;
        fileOpen = open;
    }
    public void saveFile(){
        JFileChooser save = new JFileChooser();
        int option = save.showOpenDialog(this);
        fileToSave = option;
        fileSave = save;
    }
}

grid.java ( our class where all methods are declared )

Have fun faggits.
 

Attachments

You must be registered for see attachments list
Back
Top