可能重复:
jEditorPane 作为 Web 浏览器
我有一个相对简单的小型网络浏览器,我希望在浏览器中启用 Javascript。我该怎么做呢?我希望保持浏览器相对简单,但任何改进或建议都将受到欢迎。继承人的代码。提前致谢。
public class javamark13 {
static String command ;
static JEditorPane epane;
static JPanel panel;
static JFrame frame ;
static JTextField field ;
static JLabel label;
static JButton button ;
static JScrollBar bar ;
public static void main (String[] args){
//design of the jpanel jframe
frame=new JFrame ("Lotta Browser ");
frame.setVisible(true );
frame.setLocation(1,1);
frame .setSize(1000,700);
panel =new JPanel ();
label=new JLabel(" Enter a URL");
label.setBounds(50,5,50,20);
panel.add(label);
button=new JButton("Search");
button.setBounds(870, 0, 110, 25);
frame .setContentPane(panel);
panel.setBackground(Color.gray);
panel .setLayout(null);
epane=new JEditorPane();
epane.setEditable(false);
epane .setBounds(1, 25, panel.getWidth(),panel.getHeight());
panel.add(epane);
field=new JTextField ();
panel.add(button);
field.setBounds(75,1,panel.getWidth()-191,23);
panel.add(field);
//******************************************************
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
command =field.getText();
String http="http://www.";
String com=".com/";
command=http +command+com;
field.setText(command);
try {
epane.setPage(new URL(command));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
};
}});
};
}