Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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