Notepad Sederhana

1. Menu Utama

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package notepad;

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
/**
 *
 * @author Opay
 */
public class Notepad extends javax.swing.JFrame {

    // Inisialisasi
    private File isi;
    int fileToOpen;
    int fileToSave;
    int fileToSaveas;
    JFileChooser filediOpen;
    JFileChooser filediSave;
    JFileChooser filediSaveas;
    private boolean disimpan;
    UndoManager undo = new UndoManager();

    /**
     * Creates new form Notepad
     */
    public Notepad() {
        //fulls screen
        /*GraphicsEnvironment env =
        GraphicsEnvironment.getLocalGraphicsEnvironment();
        this.setMaximizedBounds(env.getMaximumWindowBounds());
        this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
        */
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        TextArea = new javax.swing.JTextArea();
        MenuBar = new javax.swing.JMenuBar();
        mFile = new javax.swing.JMenu();
        fileNew = new javax.swing.JMenuItem();
        fileOpen = new javax.swing.JMenuItem();
        fileSave = new javax.swing.JMenuItem();
        fileSaveas = new javax.swing.JMenuItem();
        fileExit = new javax.swing.JMenuItem();
        mEdit = new javax.swing.JMenu();
        editUndo = new javax.swing.JMenuItem();
        editRedo = new javax.swing.JMenuItem();
        editCut = new javax.swing.JMenuItem();
        editCopy = new javax.swing.JMenuItem();
        editPaste = new javax.swing.JMenuItem();
        editDelete = new javax.swing.JMenuItem();
        mFormat = new javax.swing.JMenu();
        formatFont = new javax.swing.JMenuItem();
        formatLine = new javax.swing.JMenuItem();
        mView = new javax.swing.JMenu();
        viewFullscreen = new javax.swing.JMenuItem();
        mHelp = new javax.swing.JMenu();
        helpView = new javax.swing.JMenuItem();
        helpAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        TextArea.setBackground(new java.awt.Color(255, 153, 255));
        TextArea.setColumns(20);
        TextArea.setRows(5);
        jScrollPane2.setViewportView(TextArea);

        MenuBar.setBackground(new java.awt.Color(153, 204, 0));

        mFile.setText("File");

        fileNew.setText("New");
        fileNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileNewActionPerformed(evt);
            }
        });
        mFile.add(fileNew);

        fileOpen.setText("Open");
        fileOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileOpenActionPerformed(evt);
            }
        });
        mFile.add(fileOpen);

        fileSave.setText("Save");
        fileSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileSaveActionPerformed(evt);
            }
        });
        mFile.add(fileSave);

        fileSaveas.setText("Save As");
        fileSaveas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileSaveasActionPerformed(evt);
            }
        });
        mFile.add(fileSaveas);

        fileExit.setText("Exit");
        fileExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileExitActionPerformed(evt);
            }
        });
        mFile.add(fileExit);

        MenuBar.add(mFile);

        mEdit.setText("Edit");

        editUndo.setText("Undo");
        editUndo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editUndoActionPerformed(evt);
            }
        });
        mEdit.add(editUndo);

        editRedo.setText("Redo");
        editRedo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRedoActionPerformed(evt);
            }
        });
        mEdit.add(editRedo);

        editCut.setText("Cut");
        editCut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editCutActionPerformed(evt);
            }
        });
        mEdit.add(editCut);

        editCopy.setText("Copy");
        editCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editCopyActionPerformed(evt);
            }
        });
        mEdit.add(editCopy);

        editPaste.setText("Paste");
        editPaste.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editPasteActionPerformed(evt);
            }
        });
        mEdit.add(editPaste);

        editDelete.setText("Delete");
        editDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDeleteActionPerformed(evt);
            }
        });
        mEdit.add(editDelete);

        MenuBar.add(mEdit);

        mFormat.setText("Format");

        formatFont.setText("Font");
        formatFont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formatFontActionPerformed(evt);
            }
        });
        mFormat.add(formatFont);

        formatLine.setText("Line");
        formatLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formatLineActionPerformed(evt);
            }
        });
        mFormat.add(formatLine);

        MenuBar.add(mFormat);

        mView.setText("View");

        viewFullscreen.setText("Full Screen");
        viewFullscreen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewFullscreenActionPerformed(evt);
            }
        });
        mView.add(viewFullscreen);

        MenuBar.add(mView);

        mHelp.setText("Help");
        mHelp.setActionCommand("mHelp");

        helpView.setText("View Help");
        helpView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpViewActionPerformed(evt);
            }
        });
        mHelp.add(helpView);

        helpAbout.setText("Tentang Notepad");
        helpAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpAboutActionPerformed(evt);
            }
        });
        mHelp.add(helpAbout);

        MenuBar.add(mHelp);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
        );

        pack();
    }// //GEN-END:initComponents

    // MENU FILE
    private void fileNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileNewActionPerformed
        // TODO add your handling code here:
        TextArea.setText("");
    }//GEN-LAST:event_fileNewActionPerformed

    private void fileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileOpenActionPerformed
        // TODO add your handling code here:
        openFile();
         /* Content
        if (fileToOpen == JFileChooser.APPROVE_OPTION){
			TextArea.setText("");
			try{
				Scanner scan = new Scanner(new FileReader(filediOpen.getSelectedFile().getPath()));
				while (scan.hasNext())
				TextArea.append(scan.nextLine());
			} catch (Exception ex){
				System.out.println(ex.getMessage());
				}
			}
        */
    }//GEN-LAST:event_fileOpenActionPerformed

    private void fileSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileSaveActionPerformed
        // TODO add your handling code here:
        saveFile();
                /* Content
                if (fileToSave == JFileChooser.APPROVE_OPTION){
			try {
				BufferedWriter out = new BufferedWriter(new FileWriter(filediSave.getSelectedFile().getPath()));
				out.write(TextArea.getText());
				out.close();
			} catch (IOException ex) {
				System.out.println(ex.getMessage());
				}
			}
                */
    }//GEN-LAST:event_fileSaveActionPerformed

    private void fileSaveasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileSaveasActionPerformed
        // TODO add your handling code here:
        if (isi== null)
        {
            saveFile();
        }
        else
        {
            saveasFile();
        }
    }//GEN-LAST:event_fileSaveasActionPerformed

    private void fileExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileExitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_fileExitActionPerformed

        // MENU EDIT
    private void editUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editUndoActionPerformed
        // TODO add your handling code here:
        edit_undo();
    }//GEN-LAST:event_editUndoActionPerformed

    private void editRedoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRedoActionPerformed
        // TODO add your handling code here:
        edit_undo();
    }//GEN-LAST:event_editRedoActionPerformed

    private void editCutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editCutActionPerformed
        // TODO add your handling code here:
        cut();
    }//GEN-LAST:event_editCutActionPerformed

    private void editCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editCopyActionPerformed
        // TODO add your handling code here:
        copy();
    }//GEN-LAST:event_editCopyActionPerformed

    private void editPasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPasteActionPerformed
        // TODO add your handling code here:
        paste();
    }//GEN-LAST:event_editPasteActionPerformed

    private void editDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editDeleteActionPerformed
        // TODO add your handling code here:
        delete();
    }//GEN-LAST:event_editDeleteActionPerformed

    private void formatFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formatFontActionPerformed
        // TODO add your handling code here:
        pilihfont();
    }//GEN-LAST:event_formatFontActionPerformed

    private void formatLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formatLineActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_formatLineActionPerformed

    private void viewFullscreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewFullscreenActionPerformed
        // TODO add your handling code here:
        //Belum Tahu Script
        fullscreen();

    }//GEN-LAST:event_viewFullscreenActionPerformed

    private void helpViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpViewActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_helpViewActionPerformed

    private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed
        // TODO add your handling code here:
        About abo = new About();
       abo.setVisible(true);
    }//GEN-LAST:event_helpAboutActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Notepad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Notepad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Notepad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Notepad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Notepad().setVisible(true);
            }
        });
    }

    // Pengaturan Menu
    //1. Menu File
    public void openFile(){
        //checkSaveRequirement();
        /*
        JFileChooser open = new JFileChooser();
	int option = open.showOpenDialog(this);
	fileToOpen = option;
	filediOpen = open;
        */

        JFileChooser pilihfile = new JFileChooser(".");
        int pilihan1 = pilihfile.showOpenDialog(this);
        if(pilihan1 == JFileChooser.APPROVE_OPTION)
        {
            FileReader baca_file = null;
            try {
                isi = pilihfile.getSelectedFile();
                setTitle(isi.getPath());
                baca_file = new FileReader(isi);
                BufferedReader br = new BufferedReader(baca_file);
             TextArea.setText(" ");
                while (br.ready()) {
                    TextArea.append(br.readLine() + "\n");
                }

            }catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(this,"Cannot find the file");
            }catch (IOException ex) {
                JOptionPane.showMessageDialog(this,"Cannot read the file data");

            }
        }

    }

    public void saveFile(){
	if(isi!=null)
        {
            FileWriter simpan = null;
            try {
                simpan = new FileWriter(isi);
                simpan.write(TextArea.getText());
                simpan.flush();
                disimpan=true;
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,"Maaf terjadi error");
            } finally {
                try {
                    simpan.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
        else
        {
            saveasFile();
        }
    }

    public void saveasFile(){
        JFileChooser fileChooser=new JFileChooser(".");
        int option=fileChooser.showSaveDialog(this);
        if(option==JFileChooser.APPROVE_OPTION)
        {
            File fileku = fileChooser.getSelectedFile();
            isi=new File(fileChooser.getSelectedFile().getPath()+".txt");
            setTitle(isi.getPath());
            saveFile();
        }
    }

    public void checkSaveRequirement()
    {
        if(!disimpan)
        {
                int pilihan2 = JOptionPane.showConfirmDialog(this,"Text in "+isi.getName()+" has changed.\nDo you want to save the changes?","Confirmation",JOptionPane.YES_NO_OPTION);
                if(pilihan2 == JOptionPane.YES_OPTION)
                {
                    saveFile();
                }
        }
    }

    //1. Menu EDIT
    public void edit_undo() {
        if( undo.canUndo())
        {
            try
            {
                undo.undo();
            }
            catch(CannotUndoException e)
            {
            }
        }
    }

    private void cut() {
        TextArea.cut();
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private void copy() {
        TextArea.copy();
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private void paste() {
        TextArea.paste();
    }

    public void delete(){
        String temp = TextArea.getText();
        TextArea.setText(temp.substring(0, TextArea.getSelectionStart())+temp.substring(TextArea.getSelectionEnd()));
    }

    public void pilihfont(){
        Menu_format fontChooser=new Menu_format(this,true,TextArea.getFont());
        int choice=fontChooser.showFontDialog();
        Font font=fontChooser.getSelectedFont();
        if(font!=null)
        TextArea.setFont(font);
    }
    public void fullscreen() {
        setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        //JFrame.setDefaultLookAndFeelDecorated(true);
        //Notepad t = new Notepad();
        //t.setVisible(true);
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuBar;
    public static javax.swing.JTextArea TextArea;
    private javax.swing.JMenuItem editCopy;
    private javax.swing.JMenuItem editCut;
    private javax.swing.JMenuItem editDelete;
    private javax.swing.JMenuItem editPaste;
    private javax.swing.JMenuItem editRedo;
    private javax.swing.JMenuItem editUndo;
    private javax.swing.JMenuItem fileExit;
    private javax.swing.JMenuItem fileNew;
    private javax.swing.JMenuItem fileOpen;
    private javax.swing.JMenuItem fileSave;
    private javax.swing.JMenuItem fileSaveas;
    private javax.swing.JMenuItem formatFont;
    private javax.swing.JMenuItem formatLine;
    private javax.swing.JMenuItem helpAbout;
    private javax.swing.JMenuItem helpView;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JMenu mEdit;
    private javax.swing.JMenu mFile;
    private javax.swing.JMenu mFormat;
    private javax.swing.JMenu mHelp;
    private javax.swing.JMenu mView;
    private javax.swing.JMenuItem viewFullscreen;
    // End of variables declaration//GEN-END:variables

}

2. Fomat Font

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package notepad;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *
 * @author Opay
 */
public class Menu_format extends javax.swing.JDialog {

    /** Creates new form JFontChooser */

    public Menu_format(java.awt.Frame parent, boolean modal,Font font)
    {
        this(parent,modal);
        daftar.setSelectedValue(font.getName(),true);
        ukuran.setSelectedValue(String.valueOf(font.getSize()),true);
        switch(font.getStyle())
        {
            case Font.PLAIN:Style_font.setSelectedValue("Regular",true);break;
            case Font.BOLD:Style_font.setSelectedValue("Bold",true);break;
            case Font.ITALIC:Style_font.setSelectedValue("Italic",true);break;
            case Font.BOLD|Font.ITALIC:Style_font.setSelectedValue("Bold Italic",true);break;
        }

    }
    public Menu_format(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we)
        {
            selectedFont=null;
            choice=CANCEL_OPTION;
            dispose();
        }
        });
        setSize(413,375);
        setLocation(parent.getX()+(parent.getWidth()-getWidth())/2,parent.getY()+(parent.getHeight()-getHeight())/2);
        GraphicsEnvironment graphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment();
        availableFonts=graphicsEnvironment.getAvailableFontFamilyNames();
        daftar.setListData(availableFonts);
        daftar.setSelectedIndex(0);
        preview();

    }

    public int showFontDialog()
    {

        setVisible(true);
        return choice;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        sclPreview = new javax.swing.JScrollPane();
        test = new javax.swing.JTextArea();
        sclFontList = new javax.swing.JScrollPane();
        daftar = new javax.swing.JList();
        sclFontSize = new javax.swing.JScrollPane();
        ukuran = new javax.swing.JList();
        sclFontStyle = new javax.swing.JScrollPane();
        Style_font = new javax.swing.JList();
        btnOK = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Format Huruf");
        setBackground(new java.awt.Color(204, 204, 255));
        setBounds(new java.awt.Rectangle(0, 0, 413, 351));
        setResizable(false);

        test.setColumns(20);
        test.setRows(5);
        sclPreview.setViewportView(test);

        daftar.setSelectedIndex(0);
        daftar.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                daftarValueChanged(evt);
            }
        });
        sclFontList.setViewportView(daftar);

        ukuran.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        ukuran.setSelectedIndex(5);
        ukuran.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                ukuranValueChanged(evt);
            }
        });
        sclFontSize.setViewportView(ukuran);

        Style_font.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Regular", "Italic", "Bold", "Bold Italic" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        Style_font.setSelectedIndex(0);
        Style_font.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                Style_fontValueChanged(evt);
            }
        });
        sclFontStyle.setViewportView(Style_font);

        btnOK.setBackground(new java.awt.Color(153, 153, 153));
        btnOK.setText("OK");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });

        btnCancel.setBackground(new java.awt.Color(153, 153, 153));
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sclFontList, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(sclFontStyle, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(sclFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sclPreview, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnOK, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sclFontList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sclFontStyle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sclFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)
                        .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(sclPreview))
                .addGap(64, 64, 64))
        );

        pack();
    }// //GEN-END:initComponents

    private void daftarValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_daftarValueChanged

        preview();
    }//GEN-LAST:event_daftarValueChanged

    private void preview()
    {
        setSelectedFont();
        test.setFont(getSelectedFont());
        test.setText(daftar.getSelectedValue().toString());
    }
    private void setSelectedFont()
    {
        String fontName=daftar.getSelectedValue().toString();

        int fontStyle=Style_font.getSelectedIndex();
        switch(fontStyle)
        {
            case 0: fontStyle=Font.PLAIN;break;
            case 1: fontStyle=Font.ITALIC;break;
            case 2: fontStyle=Font.BOLD;break;
            case 3: fontStyle=Font.BOLD|Font.ITALIC;break;
        }

        int fontSize=Integer.parseInt(ukuran.getSelectedValue().toString());

        selectedFont=new Font(fontName,fontStyle,fontSize);
    }
    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed

        choice=OK_OPTION;
        dispose();
    }//GEN-LAST:event_btnOKActionPerformed

    public Font getSelectedFont() {
        return selectedFont;
    }

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        choice=CANCEL_OPTION;
        selectedFont=null;
        dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void Style_fontValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_Style_fontValueChanged
        preview();
    }//GEN-LAST:event_Style_fontValueChanged

    private void ukuranValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ukuranValueChanged
        preview();
    }//GEN-LAST:event_ukuranValueChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Menu_format dialog = new Menu_format(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
               dialog.showFontDialog();
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList Style_font;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOK;
    private javax.swing.JList daftar;
    private javax.swing.JScrollPane sclFontList;
    private javax.swing.JScrollPane sclFontSize;
    private javax.swing.JScrollPane sclFontStyle;
    private javax.swing.JScrollPane sclPreview;
    private javax.swing.JTextArea test;
    private javax.swing.JList ukuran;
    // End of variables declaration//GEN-END:variables

    private String[] availableFonts;
    private static final int OK_OPTION=1;
    private static final int CANCEL_OPTION=0;
    private int choice=0;
    private static  Font selectedFont;
}

3. About

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package notepad;

/**
 *
 * @author Opay
 */
public class About extends javax.swing.JFrame {

    /** Creates new form About */
    public About() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Form About");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Taupik Nurhidayat");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Dimodifikasi Oleh....");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("versi 0.0.1 ");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("49013105");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("D4 TKJMD ITB");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel6.setText("email : anoeri06@gmail.com");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel7.setText("website : https://anoeri06.wordpress.com");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// //GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    this.setVisible(false);          // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new About().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    // End of variables declaration//GEN-END:variables

}

Direktori Simpan
notepad

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s