用java编写记事本时(AWT 技术),文字输入区域是用面版,还是用TextArea panel不能用于文字输入,应该是用TextArea 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以画字DrawString() 吗? 这样可以调字体大小颜色了 Find.html<title>Find</title><hr><applet code="Find.class" width=250 height=195></applet><hr>Find.javaimport java.applet.Applet;import java.awt.BorderLayout;import java.awt.Button;import java.awt.GridLayout;import java.awt.Label;import java.awt.Panel;import java.awt.TextArea;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Find extends Applet{ TextArea editor = new TextArea(5,20); Label findLabel = new Label("find:"),changeLabel = new Label("change:"); TextField findField = new TextField(5),changeField = new TextField(5); Button findButton = new Button("Find"),changeFindButton = new Button("Change & Find"),changeButton = new Button("Change"); public void init() { Panel north = new Panel(),center = new Panel(),south = new Panel(); north.add(editor); center.setLayout(new GridLayout(2,2)); center.add(findLabel); center.add(findField); center.add(changeLabel); center.add(changeField); south.add(findButton); south.add(changeFindButton); south.add(changeButton); setLayout(new BorderLayout()); add(north,"North"); add(center,"Center"); add(south,"South"); findButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { findNext(findField.getText()); } }); changeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { replace(changeField.getText()); } }); changeFindButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int start = editor.getSelectionStart(), end = editor.getSelectionEnd(); if(start != end) { replace(changeField.getText()); } findNext(findField.getText()); } }); } void replace(String change) { int start = editor.getSelectionStart(),end = editor.getSelectionEnd(); if(start != end) { editor.replaceRange(change,start,end); } } void findNext(String find) { String edit = editor.getText(); int start = editor.getSelectionStart(),end = editor.getSelectionEnd(),index = -1; index = edit.indexOf(find,start + 1); if(index == -1 && start != 0) { index = edit.indexOf(find); } if(index != -1) { editor.setSelectionStart(index); editor.setSelectionEnd(index + find.length()); } }} 问个弱弱的问题 关于默认类型 关于多态性中的包含多态性? 简单Gui画图问题 为何无法接收另外一个类的信息? 关于如何编写内部项目文档 cross compile linux VM 有关编码和InputStream类两个问题 请教:一个jav程序为何编译时出现这种情况? 可以给一个在JDK1.4下用的CachedRowSet包吗? ****在try{ }块里不能用return吗? 大家用JAVE主要用什么开发工具? 急问诸位高手
<title>Find</title>
<hr>
<applet code="Find.class" width=250 height=195>
</applet>
<hr>Find.java
import java.applet.Applet;import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class Find extends Applet
{
TextArea editor = new TextArea(5,20);
Label findLabel = new Label("find:"),changeLabel = new Label("change:"); TextField findField = new TextField(5),changeField = new TextField(5); Button findButton = new Button("Find"),changeFindButton = new Button("Change & Find"),changeButton = new Button("Change"); public void init()
{
Panel north = new Panel(),center = new Panel(),south = new Panel(); north.add(editor); center.setLayout(new GridLayout(2,2));
center.add(findLabel);
center.add(findField);
center.add(changeLabel);
center.add(changeField); south.add(findButton);
south.add(changeFindButton);
south.add(changeButton); setLayout(new BorderLayout());
add(north,"North");
add(center,"Center");
add(south,"South"); findButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
findNext(findField.getText());
}
}); changeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
replace(changeField.getText());
}
}); changeFindButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
int start = editor.getSelectionStart(),
end = editor.getSelectionEnd(); if(start != end)
{
replace(changeField.getText()); }
findNext(findField.getText());
}
});
} void replace(String change)
{
int start = editor.getSelectionStart(),end = editor.getSelectionEnd(); if(start != end)
{
editor.replaceRange(change,start,end);
}
} void findNext(String find)
{
String edit = editor.getText();
int start = editor.getSelectionStart(),end = editor.getSelectionEnd(),index = -1; index = edit.indexOf(find,start + 1); if(index == -1 && start != 0)
{
index = edit.indexOf(find);
}
if(index != -1)
{
editor.setSelectionStart(index);
editor.setSelectionEnd(index + find.length());
}
}
}