📄 texteditorframe.java
字号:
{
TextEditorFrame_AboutBox dlg = new TextEditorFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
jMenuFileExit_actionPerformed(null);
}
}
void jMenuEditFont_actionPerformed(ActionEvent e)
{
// Handling the "Edit|Font" menu item
// Pick up the existing font from the text area and put it
// into the FontChooser before showing the FontChooser,
// so that we are editing the current font.
jFontChooser.setSelectedFont(jTextArea.getFont());
// Test the return value of showDialog() to see if the user
// pressed OK. Obtain the new Font from the FontChooser.
if (jFontChooser.showDialog())
{
// Set the font of jTextArea to the font
// the user selected before pressing the OK button.
jTextArea.setFont(jFontChooser.getSelectedFont());
}
}
void jMenuEditForeColor_actionPerformed(ActionEvent e)
{
// Handle the "Edit|Foreground Color" menu item
Color foreColor = JColorChooser.showDialog(this, "Foreground Color",
jTextArea.getForeground());
if (foreColor != null)
{
jTextArea.setForeground(foreColor);
}
}
void jMenuEditBackColor_actionPerformed(ActionEvent e)
{
// Handle the "Background Color" menu item
Color backColor = JColorChooser.showDialog(this, "Background Color",
jTextArea.getBackground());
if (backColor != null)
{
jTextArea.setBackground(backColor);
}
}
void jMenuFileNew_actionPerformed(ActionEvent e)
{
// Handle the File|New menu item.
if (okToAbandon())
{
// Clears the text of the text area.
jTextArea.setText("");
// Clear the current filename and reset the file to clean.
currentFileName = null;
dirty = false;
updateCaption();
}
}
void jMenuFileOpen_actionPerformed(ActionEvent e)
{
// Handle the File|Open menu item.
if (!okToAbandon())
return;
// Use the OPEN version of the dialog, test return for Approve/Cancel
if (JFileChooser.APPROVE_OPTION == jFileChooser.showOpenDialog(this))
{
// Call openFile() method to attempt to load the text from file into JTextArea
openFile(jFileChooser.getSelectedFile().getPath());
//repaints menu after item is selected
this.repaint();
}
}
void jMenuFileSave_actionPerformed(ActionEvent e)
{
//Handle the File|Save menu item.
saveFile();
}
void jMenuFileSaveAs_actionPerformed(ActionEvent e)
{
//Handle the File|Save As menu item.
saveAsFile();
}
void jButtonOpenFile_actionPerformed(ActionEvent e)
{
//Handle toolbar Open button
fileOpen();
}
void jButtonCloseFile_actionPerformed(ActionEvent e)
{
//Handle toolbar Close/Save button
saveFile();
}
void jButtonHelp_actionPerformed(ActionEvent e)
{
//Handle toolbar Help button
helpAbout();
}
void document_changedUpdate(DocumentEvent e)
{
dirty = true;
updateCaption();
}
void document_insertUpdate(DocumentEvent e)
{
dirty = true;
updateCaption();
}
void document_removeUpdate(DocumentEvent e)
{
dirty = true;
updateCaption();
}
}
class TextEditorFrame_jMenuFileExit_ActionAdapter
implements ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuFileExit_ActionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileExit_actionPerformed(e);
}
}
class TextEditorFrame_jMenuHelpAbout_ActionAdapter
implements ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuHelpAbout_ActionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}
class TextEditorFrame_jMenuEditFont_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuEditFont_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuEditFont_actionPerformed(e);
}
}
class TextEditorFrame_jMenuEditForeColor_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuEditForeColor_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuEditForeColor_actionPerformed(e);
}
}
class TextEditorFrame_jMenuEditBackColor_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuEditBackColor_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuEditBackColor_actionPerformed(e);
}
}
class TextEditorFrame_jMenuFileNew_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuFileNew_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileNew_actionPerformed(e);
}
}
class TextEditorFrame_jMenuFileOpen_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuFileOpen_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileOpen_actionPerformed(e);
}
}
class TextEditorFrame_jMenuFileSave_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuFileSave_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileSave_actionPerformed(e);
}
}
class TextEditorFrame_jMenuFileSaveAs_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jMenuFileSaveAs_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileSaveAs_actionPerformed(e);
}
}
class TextEditorFrame_jButtonOpenFile_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jButtonOpenFile_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButtonOpenFile_actionPerformed(e);
}
}
class TextEditorFrame_jButtonCloseFile_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jButtonCloseFile_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButtonCloseFile_actionPerformed(e);
}
}
class TextEditorFrame_jButtonHelp_actionAdapter
implements java.awt.event.ActionListener
{
TextEditorFrame adaptee;
TextEditorFrame_jButtonHelp_actionAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButtonHelp_actionPerformed(e);
}
}
class TextEditorFrame_document_documentAdapter
implements javax.swing.event.DocumentListener
{
TextEditorFrame adaptee;
TextEditorFrame_document_documentAdapter(TextEditorFrame adaptee)
{
this.adaptee = adaptee;
}
public void changedUpdate(DocumentEvent e)
{
adaptee.document_changedUpdate(e);
}
public void insertUpdate(DocumentEvent e)
{
adaptee.document_insertUpdate(e);
}
public void removeUpdate(DocumentEvent e)
{
adaptee.document_removeUpdate(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -