我正在準備計算機展覽的一個項目,我正在爲它準備網絡瀏覽器。 它運行完美,但是當我打開一個網站如google時,它看不清楚。出現一個藍色的屏幕,帶有谷歌徽標和一些文字。無法在擺動中打開網站
我的代碼是:
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.*;
public class browser
extends JFrame
implements HyperlinkListener{
URL pageURL;
private static final long serialVersionUID = 1630568393141656837L;
JPanel panel;
JButton back,forward,go;
JTextField website;
JEditorPane display;
JScrollPane sp;
public void setPanel()
{
panel=new JPanel();
back=new JButton("<<");
forward=new JButton(">>");
go=new JButton("GO");
panel.add(back);
panel.add(forward);
website=new JTextField("http://",10);
panel.add(website);
panel.add(go);
sp=new JScrollPane();
display=new JEditorPane();
display.setEditable(false);
display.setContentType("text/html");
sp.add(display);
go.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
browse();
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(panel,BorderLayout.NORTH);
add(display,BorderLayout.CENTER);
setSize(900,500);
setVisible(true);
}
protected void browse() {
String page=website.getText();
try {
pageURL=new URL(page);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
display.setPage(pageURL);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String arg[])
{
browser br=new browser();
br.setPanel();
}
@Override
public void hyperlinkUpdate(HyperlinkEvent arg0) {
// TODO Auto-generated method stub
HyperlinkEvent.EventType event=arg0.getEventType();
if(event==HyperlinkEvent.EventType.ACTIVATED);
{
browse();
}
}
}
更換'display.setEnabled(假);'和'display.setEditable(假);'第一。 – 2014-10-29 14:41:57