📄 helpframe.java
字号:
package chapter14;
import java.awt.Container;//有段代码我不懂。!!!!!!!!!!
import java.awt.Cursor;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.Document;
public class Helpframe extends JInternalFrame{
public Helpframe(){
super("help",true,true,true,true);
this.setBounds(200,200,200,200);
htmlpane html=new htmlpane();
this.getContentPane().add(html);
}
}
class htmlpane extends JScrollPane implements HyperlinkListener{
public JEditorPane html;
public htmlpane(){
try{
File f=new File("xiangfanyizhongshouye.html");
String s=f.getAbsolutePath();
s="file:"+s;
URL url=new URL(s);
html=new JEditorPane(s);
html.setEditable(false);
html.addHyperlinkListener(this);
JViewport vp=this.getViewport();
vp.add(html);//这两句为什么不能变成别的呢!
}catch(MalformedURLException e){
System.out.println("malformed url:"+e);
}catch(IOException e){
System.out.println("ioexception e:"+e);
}
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
linkactivated(e.getURL());
}
}
protected void linkactivated(URL u){
Cursor c=html.getCursor();
Cursor waitcursor=Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitcursor);
SwingUtilities.invokeLater(new pageloader(u,c));
}
class pageloader implements Runnable{
URL url;
Cursor cursor;
pageloader(URL u,Cursor c){
url=u;
cursor=c;
}
public void run(){
if(url==null){
html.setCursor(cursor);
Container parent=html.getParent();
parent.repaint();
}else{
Document doc=html.getDocument();
try{
html.setPage(url);
}catch(IOException e){
html.setDocument(doc);
getToolkit().beep();
}finally{
url=null;
SwingUtilities.invokeLater(this);//这段程序我看不懂。
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -