资源简介
一个简单的迷你记事本,基本可以实现Windows自带的所有功能,可以用作java的学习,可以直接运行,打包了所有的项目文件,在Eclipse中开项目即可。
代码片段和文件信息
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
public class FontDialog {
private Dialog fontdialog;
private JButton okButton cancelButton;
private int width = 480;
private int height = 250;
private String name = “Serif“;
private int type = 0;
private int size = 12;
private Font customFont = new Font(“宋体“ Font.ITALIC 12);
private boolean okpressed = false;
private boolean cancelpressed = false;
private JLabel lbl1 = new JLabel(“字体:“);
private JLabel lbl2 = new JLabel(“字形:“);
private JLabel lbl3 = new JLabel(“大小:“);
private JTextArea area;
String[] zx = { “常规“ “加粗“ “斜体“ “基线“ };
String[] dx = {“8“ “9“ “10“ “12“ “14“ “15“ “16“ “18“
“20“ “21“ “22“ “24“ “26“ “28“ “30“ “36“
“48“ “54““72“ “89“};
JLabel lbl = new JLabel(“字体样式style“);
private JComboBox cb1 cb3 = new JComboBox(dx) cb2 = new JComboBox(zx);
private String[] zt;
public FontDialog(frame owner String title boolean modal) {
init();
fontdialog = new Dialog(owner title modal);
fontdialog.setLocation(owner.getLocation());
fontdialog.setLayout(new FlowLayout());
fontdialog.setSize(getWidth() getHeight());
fontdialog.add(lbl1);
fontdialog.add(cb1);
fontdialog.add(lbl2);
fontdialog.add(cb2);
fontdialog.add(lbl3);
fontdialog.add(cb3);
fontdialog.add(okButton);
fontdialog.add(cancelButton);
fontdialog.add(area);
fontdialog.setResizable(false);
fontdialog.setAlwaysOnTop(true);
cancelButton.addActionListener(new fontListener());
okButton.addActionListener(new fontListener());
fontdialog.addWindowListener(new fontListener());
cb1.addItemListener(new ItemListener() { //字体动作
public void itemStateChanged(ItemEvent event) { //添加监听器获取选择用户的字体类型
name = (String) event.getItem();
setCustomFont(new Font(name type size));
}
});
cb2.addItemListener(new ItemListener() { //字形动作
public void itemStateChanged(ItemEvent event) { //添加监听器获取选择用户的字形
String s = (String) event.getItem();
if (s.equals(“常规“))
{
type = Font.PLAIN;
setCustomFont(new Font(name type size));
}
else if (s.equals(“加粗“))
{
type = Font.BOLD;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 232 2012-12-27 09:12 MiniNote\.classpath
文件 378 2012-12-27 09:12 MiniNote\.project
文件 1073 2012-12-27 09:16 MiniNote\bin\FontDialog$1.class
文件 1378 2012-12-27 09:16 MiniNote\bin\FontDialog$2.class
文件 1151 2012-12-27 09:16 MiniNote\bin\FontDialog$3.class
文件 1547 2012-12-27 09:16 MiniNote\bin\FontDialog$fontListener.class
文件 5906 2012-12-27 09:16 MiniNote\bin\FontDialog.class
文件 737 2012-12-27 09:18 MiniNote\bin\MiniNote$1.class
文件 1080 2012-12-27 09:18 MiniNote\bin\MiniNote$2.class
文件 3001 2012-12-27 09:18 MiniNote\bin\MiniNote$3.class
文件 2249 2012-12-27 09:18 MiniNote\bin\MiniNote$4.class
文件 741 2012-12-27 09:18 MiniNote\bin\MiniNote$5.class
文件 2245 2012-12-27 09:18 MiniNote\bin\MiniNote$6.class
文件 737 2012-12-27 09:18 MiniNote\bin\MiniNote$7.class
文件 12224 2012-12-27 09:18 MiniNote\bin\MiniNote.class
文件 11 2012-12-27 09:19 MiniNote\nullnull
文件 5880 2012-12-27 09:16 MiniNote\src\FontDialog.java
文件 20574 2012-12-27 09:18 MiniNote\src\MiniNote.java
目录 0 2017-11-27 22:54 MiniNote\bin
目录 0 2017-11-27 22:54 MiniNote\src
目录 0 2017-11-27 22:54 MiniNote
----------- --------- ---------- ----- ----
61144 21
评论
共有 条评论