Notepad Part One

1.4K 2 1
                                        

Well, I finally took the time to write out the code for this, and now I'm ready to teach you all how I did it. I'm not going to use NetBeans, because the GUI is really easy to make.

Start off with this little bit right here

import javax.swing.*;

public class Main extends JFrame {

public JTextArea field = new JTextArea();
public JMenuBar bar = new JMenuBar();
public JMenu file = new JMenu("File");
public JMenu options = new JMenu("Options");
public JMenuItem save = new JMenuItem("Save");
public JMenuItem saveAs = new JMenuItem("Save as");
public JMenuItem open = new JMenuItem("Open");
public JMenuItem newF = new JMenuItem("New"); 
public JMenuItem exit = new JMenuItem("Exit");
public JMenuItem about = new JMenuItem("About");
public JMenuItem help = new JMenuItem("Help");
public JMenu colors = new JMenu("Change colors");
public JMenuItem text = new JMenuItem("Change text color");
public JMenuItem background = new JMenuItem("Change background color");
public JScrollPane pane = new JScrollPane();

public static void main(String[] args) { 

new Main();
}

public Main() { 
super("Notepad");
setSize(500, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE); 

pane.add(field);
setContentPane(pane);
colors.add(text);
colors.add(background);
options.add(colors);
options.add(help);
options.add(about);
file.add(save);
file.add(saveAs); 
file.addSeperator();
file.add(open); 
file.addSeperator();
file.add(newF);
file.addSeperator();
file.add(exit); 

bar.add(file);
bar.add(options);
setJMenuBar(bar);

setVisible(true); 

Phew! That sure was a lot, wasn't it!? In the next chaper, I will explain it, because I didn't cover many of the concepts I put into this.

-Steve 

Java Swing GUI DevelopmentWhere stories live. Discover now