title: Change fonts in notepad application
body: <p>A friend and myself are making a NotePad. We are trying to get fonts to change when you click the appropriate button. For example if I press the Italic Button the text I write after that will be Italic until I press the Normal button which will turn it back to the normal font. As far as I can tell the code looks pretty good but when I press the font buttons nothing happens. Here is ALL the code.</p>
  
  <pre><code>package com.note.pad;
  
  import javax.swing.*; // for the main JFrame design
  import java.awt.*; // for the GUI stuff
  import java.awt.event.*; // for the event handling
  import java.util.Scanner; // for reading from a file
  import java.io.*; // for writing to a file
  
  public class Notepad  extends JFrame implements ActionListener{
  
      private TextArea textArea = new TextArea("", 0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
      private MenuBar menuBar = new MenuBar(); //First, create a menu bar.
      private Menu file = new Menu(); //File menu.
      private Menu fonts = new Menu(); //Font menu.
      private MenuItem italicFont = new MenuItem();
      private MenuItem normalFont = new MenuItem();
      private MenuItem openFile = new MenuItem(); //Open option
      private MenuItem saveFile = new MenuItem(); //Save option
      private MenuItem close = new MenuItem(); //Close option
  
      public Notepad(){
          this.setSize(500, 300); //Size of Notepad
          this.setTitle("BenPad"); //Name of Notepad
          setDefaultCloseOperation(EXIT_ON_CLOSE); //Closes when you hit X button
          this.textArea.setFont(new Font("Century Gothic", Font.BOLD, 12)); //Font
          this.getContentPane().setLayout(new BorderLayout());
          this.getContentPane().add(textArea);
          this.setMenuBar(this.menuBar);
          this.menuBar.add(this.file);
          this.menuBar.add(this.fonts);
          this.file.setLabel("File");
          this.fonts.setLabel("Fonts");
          this.italicFont.setLabel("Italic");
          this.normalFont.setLabel("Normal");
          this.fonts.add(this.italicFont);
          this.openFile.setLabel("Open");
          this.fonts.add(this.normalFont);
          this.openFile.addActionListener(this);
          this.openFile.setShortcut(new MenuShortcut(KeyEvent.VK_0, false));
          this.file.add(this.openFile);
          this.saveFile.setLabel("Save");
          this.saveFile.addActionListener(this);
          this.saveFile.setShortcut(new MenuShortcut(KeyEvent.VK_S, false));
          this.file.add(this.saveFile);
          this.close.setLabel("Close");
          this.close.setShortcut(new MenuShortcut(KeyEvent.VK_F4, false));
          this.close.addActionListener(this);
          this.file.add(this.close);
  
  
      }
  
      public void actionPerformed (ActionEvent e) {
  
              if (e.getSource() == this.close)
                  this.dispose(); 
  
  
              else if (e.getSource() == this.openFile) {
                  JFileChooser open = new JFileChooser(); 
                  int option = open.showOpenDialog(this); 
  
                  if (option == JFileChooser.APPROVE_OPTION) {
                      this.textArea.setText(""); 
                      try {
  
                          Scanner scan = new Scanner(new FileReader(open.getSelectedFile().getPath()));
                          while (scan.hasNext()) 
                              this.textArea.append(scan.nextLine() + "\n"); 
                                  } catch (Exception ex) { 
  
                                  System.out.println(ex.getMessage());
                                  }   
                              }
                          }
  
  
              else if (e.getSource() == this.italicFont) {
                      this.textArea.setFont(new Font("Italic", Font.ITALIC, 12));
              }
  
  
              else if (e.getSource() == this.normalFont) {
                  this.textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
              }
  
  
                          else if (e.getSource() == this.saveFile) {
                              JFileChooser save = new JFileChooser(); 
                              int option = save.showSaveDialog(this); 
  
                              if (option == JFileChooser.APPROVE_OPTION) {
                                  try {
  
                                      BufferedWriter out = new BufferedWriter(new FileWriter(save.getSelectedFile().getPath()));
                                      out.write(this.textArea.getText()); 
                                      out.close(); 
                                  } catch (Exception ex) { 
                                      System.out.println(ex.getMessage());
                                  }
                              }
                          }
      }
      public static void main(String args[]) {
          Notepad app = new Notepad();
          app.setVisible(true);
      }
  
  }
  </code></pre>