如何在GUI中打开.jsp网页? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.BufferedInputStream;import java.io.ByteArrayOutputStream;import java.net.URL;import javax.swing.JButton;import javax.swing.JEditorPane;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.SpringLayout;import javax.swing.SwingConstants;public class JavaExplorer extends JFrame{ private final class LoadUrlAction extends MouseAdapter { /** * @param meta * @return */ public String getCharsetName(String meta) { if (null == meta || meta.trim().length() == 0) { return ""; } meta = meta.trim().toLowerCase(); int index = 0; if ((index = meta.indexOf("charset")) < 0) { return ""; } if (index >= 0) { while (index < meta.length()) { if (meta.charAt(index) != '=') { index++; } else { index++; break; } } int endIndex = index; while (endIndex < meta.length()) { if (meta.charAt(endIndex) != ';' && meta.charAt(endIndex) != '\"' && meta.charAt(endIndex) != '\'') { endIndex++; } else { break; } } return meta.substring(index, endIndex); } return ""; } public void mousePressed(MouseEvent e) { try { URL url = new URL(JavaExplorer.this.urlTxt.getText()); BufferedInputStream receiver = new BufferedInputStream(url.openStream()); ByteArrayOutputStream _bodyByteBuffer = new ByteArrayOutputStream(4 * 1024); byte[] buffer = new byte[1024]; int len = -1; do { len = receiver.read(buffer); if (len < 0) { break; } _bodyByteBuffer.write(buffer, 0, len); } while (len != 0); String charsetName = getCharsetName(_bodyByteBuffer.toString()); String body; if (charsetName.length() > 0) { body = _bodyByteBuffer.toString(charsetName); } else { // if we can't get the charset,let's use the the lastest // charset.(usual default charset) body = _bodyByteBuffer.toString(); } JavaExplorer.this.content.setText(body); JOptionPane.showMessageDialog(JavaExplorer.this, body); } catch (Exception e1) { e1.printStackTrace(); } } } private JTextField urlTxt; private SpringLayout springLayout; private JEditorPane content; /** * Launch the application * * @param args */ public static void main(String args[]) { try { JavaExplorer frame = new JavaExplorer(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the frame */ public JavaExplorer() { super(); springLayout = new SpringLayout(); getContentPane().setLayout(springLayout); setTitle("Java 浏览器"); setBounds(100, 100, 648, 503); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel(); label.setHorizontalAlignment(SwingConstants.RIGHT); label.setHorizontalTextPosition(SwingConstants.RIGHT); label.setText("地址:"); getContentPane().add(label); springLayout.putConstraint(SpringLayout.SOUTH, label, 25, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, label, 90, SpringLayout.WEST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, getContentPane()); urlTxt = new JTextField(); urlTxt.setText("http://www.boasoft.com/t2s/index.jsp"); getContentPane().add(urlTxt); springLayout.putConstraint(SpringLayout.SOUTH, urlTxt, 0, SpringLayout.SOUTH, label); springLayout.putConstraint(SpringLayout.EAST, urlTxt, -75, SpringLayout.EAST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, urlTxt, 0, SpringLayout.NORTH, label); springLayout.putConstraint(SpringLayout.WEST, urlTxt, 5, SpringLayout.EAST, label); final JButton goButton = new JButton(); goButton.addMouseListener(new LoadUrlAction()); goButton.setText("GO"); getContentPane().add(goButton); springLayout.putConstraint(SpringLayout.SOUTH, goButton, 0, SpringLayout.SOUTH, urlTxt); springLayout.putConstraint(SpringLayout.EAST, goButton, -5, SpringLayout.EAST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, goButton, 0, SpringLayout.NORTH, urlTxt); springLayout.putConstraint(SpringLayout.WEST, goButton, 5, SpringLayout.EAST, urlTxt); final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane); springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout.SOUTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, goButton); springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, label); springLayout.putConstraint(SpringLayout.WEST, scrollPane, 0, SpringLayout.WEST, label); content = new JEditorPane(); scrollPane.setViewportView(content); }} //修改了一下import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.BufferedInputStream;import java.io.ByteArrayOutputStream;import java.net.URL;import javax.swing.JButton;import javax.swing.JEditorPane;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.SpringLayout;import javax.swing.SwingConstants;public class JavaExplorer extends JFrame{ private final class LoadUrlAction extends MouseAdapter { /** * @param meta * @return */ public String getCharsetName(String meta) { if (null == meta || meta.trim().length() == 0) { return ""; } meta = meta.trim().toLowerCase(); int index = 0; if ((index = meta.indexOf("charset")) < 0) { return ""; } if (index >= 0) { while (index < meta.length()) { if (meta.charAt(index) != '=') { index++; } else { index++; break; } } int endIndex = index; while (endIndex < meta.length()) { if (meta.charAt(endIndex) != ';' && meta.charAt(endIndex) != '\"' && meta.charAt(endIndex) != '\'') { endIndex++; } else { break; } } return meta.substring(index, endIndex); } return ""; } public void mousePressed(MouseEvent e) { try { URL url = new URL(JavaExplorer.this.urlTxt.getText()); JavaExplorer.this.content.setPage(url); // BufferedInputStream receiver = new // BufferedInputStream(url.openStream()); // ByteArrayOutputStream _bodyByteBuffer = new // ByteArrayOutputStream(4 * 1024); // byte[] buffer = new byte[1024]; // int len = -1; // do // { // len = receiver.read(buffer); // if (len < 0) // { // break; // } // _bodyByteBuffer.write(buffer, 0, len); // } // while (len != 0); // String charsetName = // getCharsetName(_bodyByteBuffer.toString()); // String body; // if (charsetName.length() > 0) // { // body = _bodyByteBuffer.toString(charsetName); // } // else // { // // if we can't get the charset,let's use the the lastest // // charset.(usual default charset) // body = _bodyByteBuffer.toString(); // } // JavaExplorer.this.content.setText(body); // JOptionPane.showMessageDialog(JavaExplorer.this, body); } catch (Exception e1) { e1.printStackTrace(); } } } private JTextField urlTxt; private SpringLayout springLayout; private JEditorPane content; /** * Launch the application * * @param args */ public static void main(String args[]) { try { JavaExplorer frame = new JavaExplorer(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the frame */ public JavaExplorer() { super(); springLayout = new SpringLayout(); getContentPane().setLayout(springLayout); setTitle("Java 浏览器"); setBounds(100, 100, 648, 503); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel(); label.setHorizontalAlignment(SwingConstants.RIGHT); label.setHorizontalTextPosition(SwingConstants.RIGHT); label.setText("地址:"); getContentPane().add(label); springLayout.putConstraint(SpringLayout.SOUTH, label, 25, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, label, 90, SpringLayout.WEST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, getContentPane()); urlTxt = new JTextField(); urlTxt.setText("http://www.boasoft.com/t2s/index.jsp"); getContentPane().add(urlTxt); springLayout.putConstraint(SpringLayout.SOUTH, urlTxt, 0, SpringLayout.SOUTH, label); springLayout.putConstraint(SpringLayout.EAST, urlTxt, -75, SpringLayout.EAST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, urlTxt, 0, SpringLayout.NORTH, label); springLayout.putConstraint(SpringLayout.WEST, urlTxt, 5, SpringLayout.EAST, label); final JButton goButton = new JButton(); goButton.addMouseListener(new LoadUrlAction()); goButton.setText("GO"); getContentPane().add(goButton); springLayout.putConstraint(SpringLayout.SOUTH, goButton, 0, SpringLayout.SOUTH, urlTxt); springLayout.putConstraint(SpringLayout.EAST, goButton, -5, SpringLayout.EAST, getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, goButton, 0, SpringLayout.NORTH, urlTxt); springLayout.putConstraint(SpringLayout.WEST, goButton, 5, SpringLayout.EAST, urlTxt); final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane); springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout.SOUTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, goButton); springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, label); springLayout.putConstraint(SpringLayout.WEST, scrollPane, 0, SpringLayout.WEST, label); content = new JEditorPane(); scrollPane.setViewportView(content); }} 今天面试问题 发个帖子散一点点点点点分 在线图片编辑 本人的新发现,与人共享. 跪求JAVA编写的俄罗斯方块游戏的论文或其资料!!!!! 请大侠帮忙:jsp中上传与下载文件问题。 怎么让int型转变成string型,牛兄们!拜托了! 学J2SE一般看什么书,J2SE就是JAVA吗? 为什么从sokect 接口只读出了1个字节? jive在tomcat下运行时的错误 用java制作浏览器 无法理解一段代码~~~~~~~~~~~
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;public class JavaExplorer extends JFrame
{
private final class LoadUrlAction extends MouseAdapter
{
/**
* @param meta
* @return
*/
public String getCharsetName(String meta)
{
if (null == meta || meta.trim().length() == 0)
{
return "";
}
meta = meta.trim().toLowerCase();
int index = 0;
if ((index = meta.indexOf("charset")) < 0)
{
return "";
}
if (index >= 0)
{
while (index < meta.length())
{
if (meta.charAt(index) != '=')
{
index++;
}
else
{
index++;
break;
}
}
int endIndex = index;
while (endIndex < meta.length())
{
if (meta.charAt(endIndex) != ';' && meta.charAt(endIndex) != '\"' && meta.charAt(endIndex) != '\'')
{
endIndex++;
}
else
{
break;
}
}
return meta.substring(index, endIndex);
}
return "";
} public void mousePressed(MouseEvent e)
{
try
{
URL url = new URL(JavaExplorer.this.urlTxt.getText());
BufferedInputStream receiver = new BufferedInputStream(url.openStream());
ByteArrayOutputStream _bodyByteBuffer = new ByteArrayOutputStream(4 * 1024);
byte[] buffer = new byte[1024];
int len = -1;
do
{
len = receiver.read(buffer);
if (len < 0)
{
break;
}
_bodyByteBuffer.write(buffer, 0, len);
}
while (len != 0);
String charsetName = getCharsetName(_bodyByteBuffer.toString());
String body;
if (charsetName.length() > 0)
{
body = _bodyByteBuffer.toString(charsetName);
}
else
{
// if we can't get the charset,let's use the the lastest
// charset.(usual default charset)
body = _bodyByteBuffer.toString();
}
JavaExplorer.this.content.setText(body);
JOptionPane.showMessageDialog(JavaExplorer.this, body);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
} private JTextField urlTxt; private SpringLayout springLayout; private JEditorPane content; /**
* Launch the application
*
* @param args
*/
public static void main(String args[])
{
try
{
JavaExplorer frame = new JavaExplorer();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
} /**
* Create the frame
*/
public JavaExplorer()
{
super();
springLayout = new SpringLayout();
getContentPane().setLayout(springLayout);
setTitle("Java 浏览器");
setBounds(100, 100, 648, 503);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setHorizontalTextPosition(SwingConstants.RIGHT);
label.setText("地址:");
getContentPane().add(label);
springLayout.putConstraint(SpringLayout.SOUTH, label, 25, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, label, 90, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, getContentPane());
urlTxt = new JTextField();
urlTxt.setText("http://www.boasoft.com/t2s/index.jsp");
getContentPane().add(urlTxt);
springLayout.putConstraint(SpringLayout.SOUTH, urlTxt, 0, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.EAST, urlTxt, -75, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, urlTxt, 0, SpringLayout.NORTH, label);
springLayout.putConstraint(SpringLayout.WEST, urlTxt, 5, SpringLayout.EAST, label);
final JButton goButton = new JButton();
goButton.addMouseListener(new LoadUrlAction());
goButton.setText("GO");
getContentPane().add(goButton);
springLayout.putConstraint(SpringLayout.SOUTH, goButton, 0, SpringLayout.SOUTH, urlTxt);
springLayout.putConstraint(SpringLayout.EAST, goButton, -5, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, goButton, 0, SpringLayout.NORTH, urlTxt);
springLayout.putConstraint(SpringLayout.WEST, goButton, 5, SpringLayout.EAST, urlTxt);
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane);
springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout.SOUTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, goButton);
springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.WEST, scrollPane, 0, SpringLayout.WEST, label);
content = new JEditorPane();
scrollPane.setViewportView(content);
}
}
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;public class JavaExplorer extends JFrame
{
private final class LoadUrlAction extends MouseAdapter
{
/**
* @param meta
* @return
*/
public String getCharsetName(String meta)
{
if (null == meta || meta.trim().length() == 0)
{
return "";
}
meta = meta.trim().toLowerCase();
int index = 0;
if ((index = meta.indexOf("charset")) < 0)
{
return "";
}
if (index >= 0)
{
while (index < meta.length())
{
if (meta.charAt(index) != '=')
{
index++;
}
else
{
index++;
break;
}
}
int endIndex = index;
while (endIndex < meta.length())
{
if (meta.charAt(endIndex) != ';' && meta.charAt(endIndex) != '\"' && meta.charAt(endIndex) != '\'')
{
endIndex++;
}
else
{
break;
}
}
return meta.substring(index, endIndex);
}
return "";
} public void mousePressed(MouseEvent e)
{
try
{
URL url = new URL(JavaExplorer.this.urlTxt.getText());
JavaExplorer.this.content.setPage(url);
// BufferedInputStream receiver = new
// BufferedInputStream(url.openStream());
// ByteArrayOutputStream _bodyByteBuffer = new
// ByteArrayOutputStream(4 * 1024);
// byte[] buffer = new byte[1024];
// int len = -1;
// do
// {
// len = receiver.read(buffer);
// if (len < 0)
// {
// break;
// }
// _bodyByteBuffer.write(buffer, 0, len);
// }
// while (len != 0);
// String charsetName =
// getCharsetName(_bodyByteBuffer.toString());
// String body;
// if (charsetName.length() > 0)
// {
// body = _bodyByteBuffer.toString(charsetName);
// }
// else
// {
// // if we can't get the charset,let's use the the lastest
// // charset.(usual default charset)
// body = _bodyByteBuffer.toString();
// }
// JavaExplorer.this.content.setText(body);
// JOptionPane.showMessageDialog(JavaExplorer.this, body);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
} private JTextField urlTxt; private SpringLayout springLayout; private JEditorPane content; /**
* Launch the application
*
* @param args
*/
public static void main(String args[])
{
try
{
JavaExplorer frame = new JavaExplorer();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
} /**
* Create the frame
*/
public JavaExplorer()
{
super();
springLayout = new SpringLayout();
getContentPane().setLayout(springLayout);
setTitle("Java 浏览器");
setBounds(100, 100, 648, 503);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setHorizontalTextPosition(SwingConstants.RIGHT);
label.setText("地址:");
getContentPane().add(label);
springLayout.putConstraint(SpringLayout.SOUTH, label, 25, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, label, 90, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, getContentPane());
urlTxt = new JTextField();
urlTxt.setText("http://www.boasoft.com/t2s/index.jsp");
getContentPane().add(urlTxt);
springLayout.putConstraint(SpringLayout.SOUTH, urlTxt, 0, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.EAST, urlTxt, -75, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, urlTxt, 0, SpringLayout.NORTH, label);
springLayout.putConstraint(SpringLayout.WEST, urlTxt, 5, SpringLayout.EAST, label);
final JButton goButton = new JButton();
goButton.addMouseListener(new LoadUrlAction());
goButton.setText("GO");
getContentPane().add(goButton);
springLayout.putConstraint(SpringLayout.SOUTH, goButton, 0, SpringLayout.SOUTH, urlTxt);
springLayout.putConstraint(SpringLayout.EAST, goButton, -5, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, goButton, 0, SpringLayout.NORTH, urlTxt);
springLayout.putConstraint(SpringLayout.WEST, goButton, 5, SpringLayout.EAST, urlTxt);
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane);
springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout.SOUTH, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, goButton);
springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, label);
springLayout.putConstraint(SpringLayout.WEST, scrollPane, 0, SpringLayout.WEST, label);
content = new JEditorPane();
scrollPane.setViewportView(content);
}
}