자바 스윙 실현 수첩

/*   
    Copyright (C) 2017 mzy  <[email protected]>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .
*/

package notepad;

import java.awt.Color;

/**
 *
 * @author     
 * @version 1.0
 */

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.filechooser.FileNameExtensionFilter;


public class Notepad extends JFrame implements ActionListener{
	public static void main(String[] args) {
		new Notepad();
		
	}
	
	private static final long serialVersionUID = -2843137103983861960L;
	JTextArea text; //     JTextArea             
	
	
	public Notepad(){
		notepadUI();
		setVisible(true); // setVisible  true           JFrame    ,         
		
	}
	private void notepadUI() {
		//          
		setTitle("MZY   ");
		setSize(600, 400);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		
		setIconImage(new ImageIcon("icon/notepad.png").getImage());
		// setIconImage(new ImageIcon(getClass().getResource("icon/notepad.png")).getImage());//        icon   
		Container cp = getContentPane();
		//    JMenuItem   container  
		text = new JTextArea();
		text.setFont(new Font("   ",Font.PLAIN, 24));
		cp.add(new JScrollPane(text));
	
		String[] captions = {"  (F)","  (E)","  (O)","  (H)"};
		String[][] titles = {
				{"  ","  ...","  ","   ...", "-", "  "},
				{"  ","  ","  ","  "},
				{"  (F)..."},
				{"  ","-","     "}
		};
		// JMenuBar ->  
		JMenuBar menuBar = new JMenuBar();
		JMenu menu;
		JMenuItem item;
		for(int i =0; i fontList = new JList(fontName);
	JList StyleList = new JList(fontStyle);
	// SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, Number stepSize) 
	SpinnerModel spinnerModel = new SpinnerNumberModel(bounds, 0, 80, 2);
	JSpinner spinner = new JSpinner(spinnerModel); //       
	
	// south
	
	JButton ok = new JButton("  ");
	JButton cancel = new JButton("  ");

	
	MyFormat(JTextArea text){
		this.text = text;
		setIconImage(new ImageIcon("icon/notepad.png").getImage());
		
		cp.setPreferredSize(new Dimension(500, 300));
        cp.setLayout(null);
		
		JLabel l2 = new JLabel("  ");
		JLabel l1 = new JLabel("  ");
		JLabel l3 = new JLabel("  ");
		l1.setFont(new Font("    ",Font.BOLD, 28));
		l2.setFont(new Font("    ",Font.BOLD, 28));
		l3.setFont(new Font("    ",Font.BOLD, 28));
	
		l1.setBounds(40, 20, 140, 35);
		l2.setBounds(215, 20, 120, 35);
		l3.setBounds(360, 20, 75, 35);
		cp.add(l1);
		cp.add(l2);
		cp.add(l3);
		
		StyleList.setFont(new Font("   ",0 , 18));
		JScrollPane j2 = new JScrollPane(StyleList);
		
		
		fontList.setFont(new Font("   ",0 , 12));
		JScrollPane j1 = new JScrollPane(fontList);
		
		
		spinner.setFont(new Font("   ",1 , 18));
		
		j1.setBounds(40, 75, 150, 175);
		j2.setBounds(215, 75, 80, 120);
		spinner.setBounds(360, 75, 45, 50);
		cp.add(j1);
		cp.add(j2);
		cp.add(spinner);
		
		ok.addActionListener(this);
		cancel.addActionListener(this);
		cp.add(ok);
		cp.add(cancel);
		
		ok.setBounds(245, 240, 80, 30);
		cancel.setBounds(380, 240, 80, 30);
		
		setTitle("  ");
		setVisible(true);
        setLocationRelativeTo(null);
        setResizable(false); //          
		pack(); //                               
	}
	
	public void actionPerformed(ActionEvent e) {	
		String s = e.getActionCommand();
		if("  ".equals(s)) {
			style = myGetType();
			bounds = Integer.parseInt(spinner.getValue().toString());
			font = new Font((String)fontList.getSelectedValue(), style, bounds);
			text.setFont(font);
			this.dispose();
		}
		if("  ".equals(s)) {
			dispose();
		}
	}
	
	private int myGetType() {
		if("  ".equals(StyleList.getSelectedValue())) {
			return 0;
		} else if("  ".equals(StyleList.getSelectedValue())) {
			return 1;
		} else if("  ".equals(StyleList.getSelectedValue())) {
			return 2;
		} else if("  ".equals(StyleList.getSelectedValue())) {
			return 3;
		}
		return 0;
	}
}

class AboutHelp extends JDialog {//     
	
	private static final long serialVersionUID = 1L;

	AboutHelp() {
		
		JTextArea t = new JTextArea();
		t.setFont(new Font("    ",1 , 16));
		String s = "     :              "
				+ "         :"
				+ "        ";
				
        t.setText(s);
        t.setEditable(false);
        add(t);
        setIconImage(new ImageIcon("icon/notepad.png").getImage());
        setSize(480, 100);
        setVisible(true);
        setLocationRelativeTo(null);
        setResizable(false); //          
  
	}
}

class AboutMyNotepad extends JDialog {//     
	
	private static final long serialVersionUID = 1L;

	AboutMyNotepad() {
		
		JTextArea t = new JTextArea();
		t.setFont(new Font("    ",1 , 16));
		String s = "     :              "
				+ "  :mzy1.0     "
				+ "   :[email protected]";
        t.setText(s);
        t.setEditable(false);
        add(t);
        setIconImage(new ImageIcon("icon/notepad.png").getImage());
        setSize(550, 100);
        setVisible(true);
        setLocationRelativeTo(null);
        setResizable(false); //          
  
	}
}

좋은 웹페이지 즐겨찾기