📄 urlconnectframe.java
字号:
package ntis.com.util;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
import java.util.Properties;
public class URLConnectFrame extends JFrame {
JPanel contentPane;
JTextField urlField = new JTextField();
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea messageArea = new JTextArea();
JButton conButton = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
TitledBorder titledBorder1;
/**僼儗乕儉偺峔抸*/
public URLConnectFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**僐儞億乕僱儞僩偺弶婜壔*/
private void jbInit() throws Exception {
titledBorder1 = new TitledBorder("");
//setIconImage(Toolkit.getDefaultToolkit().createImage(URLConnectFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("URL Connect");
conButton.setText("愙懕");
conButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
conButton_mouseClicked(e);
}
});
jPanel1.setBorder(titledBorder1);
contentPane.add(urlField, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
contentPane.add(jPanel1, new GridBagConstraints(1, 0, 1, 2, 0.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(conButton, null);
contentPane.add(jScrollPane1, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jScrollPane1.getViewport().add(messageArea, null);
}
/**僂傿儞僪僂偑暵偠傜傟偨偲偒偵廔椆偡傞傛偆偵僆乕僶乕儔僀僪*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void conButton_mouseClicked(MouseEvent e) {
HttpURLConnection _con = null;
InputStream _in = null;
int _len = 0;
byte[] bBuff = new byte[1024];
Properties p = System.getProperties();
p.put("proxyHost", "cache.ntis.nec.co.jp");
p.put("proxyPort", "8080");
p.put("proxySet", "true");
System.setProperties(p);
try {
_con = (HttpURLConnection)(new URL(urlField.getText())).openConnection();
_in = _con.getInputStream();
while((_len = _in.read(bBuff)) != -1) {
messageArea.append(new String(bBuff, 0, _len) + "\n");
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -