diff --git a/src/java2022spring/FontDialog.java b/src/java2022spring/FontDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..aa50886b6195f595f25cc42be216e18f31f91a89 --- /dev/null +++ b/src/java2022spring/FontDialog.java @@ -0,0 +1,101 @@ +package java2022spring; +import java.awt.event.*; +import java.awt.*; +import javax.swing.*; +public class FontDialog extends JDialog implements ItemListener,ActionListener{ + FontFamilyNames fontFamilyNames; + int fontSize=12; + int fontStyle=Font.PLAIN; + String fontName; + JComboBox fontNameList,fontSizeList,fontStyleList; + JLabel label; + Font font; + JButton yes,cancel; + static int YES=1,NO=0; + int state=-1; + FontDialog(JFrame f){ + super(f); + setTitle("字体设置"); + font=new Font("宋体",Font.PLAIN,12); + fontFamilyNames=new FontFamilyNames(); + setModal(true); + yes=new JButton("确定"); + cancel=new JButton("取消"); + yes.addActionListener(this); + cancel.addActionListener(this); + label=new JLabel("记事本-Notepad",JLabel.CENTER); + fontNameList=new JComboBox(); + fontSizeList=new JComboBox(); + fontStyleList=new JComboBox(); + String name[]=fontFamilyNames.getFontName(); + fontNameList.addItem("字体"); + for(int k=0;k0) { + text.setFont(new Font(f.getFamily(),f.getStyle(),f.getSize()-1)); + } + } + else { + scroller.addMouseWheelListener(sysWheel); + sysWheel.mouseWheelMoved(e); + scroller.removeMouseWheelListener(sysWheel); + } + } + } + + //实现DocumentListener接口中的方法 + public void insertUpdate(DocumentEvent e) { + editM_Cancel.setEnabled(true); + popupM_Cancel.setEnabled(true); + } + public void removeUpdate(DocumentEvent e) { + editM_Cancel.setEnabled(true); + popupM_Cancel.setEnabled(true); + } + public void changedUpdate(DocumentEvent e) { + editM_Cancel.setEnabled(true); + popupM_Cancel.setEnabled(true); + } + + class UndoHandler implements UndoableEditListener + { public void undoableEditHappened(UndoableEditEvent ue) + { undo.addEdit(ue.getEdit()); + } + } + + +} \ No newline at end of file diff --git a/src/java2022spring/Test.java b/src/java2022spring/Test.java index 24deb29bfc0e5f50fdedcd21b504e77b529d48b6..87983e7cd4755a5e31b136573d27487b5f4fef58 100644 --- a/src/java2022spring/Test.java +++ b/src/java2022spring/Test.java @@ -1,7 +1,10 @@ package java2022spring; +import javax.swing.*; + public class Test { - public static void main(String[] args) { - System.out.println("Hello world!"); - } + public static void main(String args[]) + { Notepad notepad=new Notepad(); + notepad.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } }