?? notepad.java
字號:
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void actionPerformed(ActionEvent ae)
{
target = tf.getText();
if (ae.getSource().equals(bt))
{
start = allcontent.indexOf(tf.getText(), start);
if (start == -1)
{
lb.setText("End!");
start = 0;
length = 0;
target = null;
}
else
{
length = tf.getText().length();
content.select(start, start + length);
start = start + length;
content.requestFocus();
}
}
}
}
public class Change extends Dialog implements ActionListener, WindowListener
{
Label lb;
TextField tf;
TextField tf2;
Button bt;
Button cg;
Button replaceall;
//Panel pn;
int start = 0;
String allcontent;
String target = null;
int length;
Change(Frame frame, String s, boolean b)
{
super(frame, s, b);
//find = new Dialog(frame, s, b);
lb = new Label("");
tf = new TextField(10);
tf2 = new TextField(10);
bt = new Button("Find");
cg = new Button("Change");
replaceall = new Button("RelpaceAll");
//pn = new Panel(new GridLayout(2,1));
setLayout(new GridLayout(4, 2));
add(new Label(""));
add(new Label(""));
add(tf);
add(bt);
add(tf2);
add(cg);
add(lb);
add(replaceall);
setSize(400, 200);
this.setLocation(500, 300);
setVisible(true);
addWindowListener(this);
bt.addActionListener(this);
cg.addActionListener(this);
replaceall.addActionListener(this);
}
public void windowClosing(WindowEvent e)
{ dispose(); }
public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void actionPerformed(ActionEvent ae)
{
target = tf.getText();
if (ae.getSource().equals(bt))
{
allcontent = content.getText();
start = allcontent.indexOf(tf.getText(), start);
if (start == -1)
{
lb.setText("End!");
start = 0;
length = 0;
target = null;
}
else
{
length = tf.getText().length();
content.select(start, start + length);
start = start + length;
content.requestFocus();
}
}
if (ae.getSource().equals(cg))
{
allcontent = content.getText();
start = allcontent.indexOf(tf.getText(), start);
if (start == -1)
{
lb.setText("End!");
start = 0;
length = 0;
target = null;
}
else
{
length = tf.getText().length();
content.select(start, start + length);
//content.requestFocus();
int begin = content.getSelectionStart();
int end = content.getSelectionEnd();
content.replaceRange(tf2.getText(), begin,end);
start = start + tf2.getText().length();
content.requestFocus();
message.setText("File content Modified");
}
}
if (ae.getSource().equals(replaceall))
{
int count = 0;
if(tf2.getText()==null||tf.getText()==null||content.getText()==null)
{
lb.setText("No Information");
}
else
{
while (true)
{
allcontent = content.getText();
start = allcontent.indexOf(tf.getText(), start);
if (start == -1)
break;
length = tf.getText().length();
content.select(start, start + length);
content.requestFocus();
int begin = content.getSelectionStart();
int end = content.getSelectionEnd();
content.replaceRange(tf2.getText(), begin, end);
start = start + tf2.getText().length();
content.requestFocus();
count++;
}
lb.setText(count+" places have been replaced! ");
message.setText("File content Modified");
}
}
}
}
//above is the edit menu
class font extends Frame implements ActionListener
{
Choice font1, size, bolder;
Button bb;
Button sure;
Color c2=Color.black;
final int bold1[]={Font.BOLD,Font.CENTER_BASELINE,Font.CENTER_BASELINE,Font.ITALIC,
Font.PLAIN,Font.ROMAN_BASELINE,Font.TRUETYPE_FONT};;
String bold[]={"Font.BOLD","Font.CENTER_BASELINE","Font.CENTER_BASELINE","Font.ITALIC",
"Font.PLAIN","Font.ROMAN_BASELINE","Font.TRUETYPE_FONT"};;
font(String s)
{
setTitle(s);
font1 = new Choice();
bolder = new Choice();
size = new Choice();
Panel p1 = new Panel();
Panel p2 = new Panel();
bb = new Button("Click to open");
sure = new Button("OK");
sure.addActionListener(this);
bb.addActionListener(this);
p1.setLayout(new GridLayout(4, 1));
p2.setLayout(new GridLayout(4, 1));
GraphicsEnvironment gg = GraphicsEnvironment.getLocalGraphicsEnvironment();
String ss[] = gg.getAvailableFontFamilyNames();
for (int i = 126; i < ss.length; i++)
font1.add(ss[i]);
for (int i = 12; i <= 64; i += 2)
{
String w = String.valueOf(i);
size.add(w);
}
for (int i = 0; i < bold.length; i++)
{
bolder.add(bold[i]);
}
p1.add(new Label("Font Name"));
p1.add(font1);
p1.add(new Label("Size"));
p1.add(size);
p2.add(new Label("Style"));
p2.add(bolder);
p2.add(new Label("Color"));
p2.add(bb);
add(p2, BorderLayout.WEST);
add(p1, BorderLayout.EAST);
add(sure,BorderLayout.SOUTH);
setSize(250, 150);
setVisible(true);
pack();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ee)
{
dispose();
}
});
}
public String returnfont1()
{
return font1.getSelectedItem();
}
public int returnbolder()
{
return bolder.getSelectedIndex();
}
public int returnsize()
{
return Integer.parseInt(size.getSelectedItem());
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource().equals(bb))
{
c2 = JColorChooser.showDialog(this, "color change", null);
bb.setBackground(c2);
}
if(e.getSource().equals(sure))
{
int i=returnbolder();
Font f=new Font(returnfont1(),bold1[i],returnsize());
content.setFont(f);
content.setForeground(c2);
dispose();
}
}
}
public class About extends Dialog implements WindowListener
{
Label lb;
About(Frame frame,String s,boolean b)
{
super(frame, s, b);
//find = new Dialog(frame, s, b);
lb = new Label("Make by Bill,V1.0");
add(lb);
setSize(300, 150);
this.setLocation(500, 300);
setVisible(true);
addWindowListener(this);
}
public void windowClosing(WindowEvent e)
{ dispose(); }
public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
}
//above is the Help menu
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource().equals(newFile))
{
String cmp=message.getText();
if(cmp.equals(new String("File content Modified")))
{
new Ask(this, "New", false);
}
else
newfile();
}
if (ae.getSource().equals(open))
open();
if (ae.getSource().equals(save))
save();
if (ae.getSource().equals(saveas))
saveas();
if (ae.getSource().equals(exit))
{
String cmp=message.getText();
if(cmp.equals(new String("File content Modified")))
{
new Ask2(this, "Exit", false);
}
else
System.exit(0);
}
if (ae.getSource().equals(undo))
undo();
if (ae.getSource().equals(copy))
copy();
if (ae.getSource().equals(paste))
paste();
if (ae.getSource().equals(cut))
cut();
if (ae.getSource().equals(search))
{
new Find(this, "Find", false);
}
if (ae.getSource().equals(searchAndChange))
{
new Change(this, "Change", false);
}
if (ae.getSource().equals(font))
new font("Font");
if (ae.getSource().equals(about))
{
new About(this, "About", false);
}
}
public void textValueChanged(TextEvent e)
{
message.setText("File content Modified");
}
public void windowClosing(WindowEvent e)
{
String cmp=message.getText();
if(cmp.equals(new String("File content Modified")))
{
new Ask2(this, "Exit", false);
}
else
System.exit(0);
}
public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == e.VK_BACK_SPACE)
{
//System.exit(0);
if (firstBackspace == 1)
{
tmp = content.getText();
firstBackspace++;
}
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public static void main(String args[])
{
new Notepad();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -