int responseCode = -1;
HttpURLConnection con = null;
try {
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");// IE代理进行下载
con.setConnectTimeout(60000);
con.setReadTimeout(60000);
// 获得网页返回信息码
responseCode = con.getResponseCode();
if (responseCode == -1) {
viewArea.setText("连接失败:" + url.toString());
return null;
}
if (responseCode = 400) {
viewArea.setText("请求失败java网页设计代码,错误码:" + responseCode);
return null;
}
InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String str = null;
while ((str = br.readLine()) != null)
builder.append(str);
is.close();
} catch (IOException e) {
e.printStackTrace();
viewArea.setText("IOException: " + url.toString());
} finally {
con.disconnect();
}
return builder.toString();
}
private void searchFromText(String context) {
viewArea.setText("查找URL中java网页设计代码:\n");
Pattern pattern = Pattern.compile("a( [^]+)*(.*?)/a");
Matcher matcher = pattern.matcher(context);
while (matcher.find()) {
for (String prop : matcher.group(1).split(" ")) {
int indexOf = prop.indexOf('=');
if (indexOf0) {
if (prop.substring(0, indexOf).equals("href")) {
String url2 = prop.substring(indexOf + 2, prop.length() - 1);
viewArea.append(url2 + "\n");
}
}
}
}
}
}
用Java设计一个登录页面,不用连接数据库,只要把用户和密码信息存放在文本里面,怎样设计代码???/* Main.java
*
* Created on __DATE__, __TIME__
*/
import javax.swing.JOptionPane;
/**
*
* @author__USER__
*/
public class Main extends javax.swing.JFrame {
/** Creates new form Main */
public Main() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// editor-fold defaultstate="collapsed" desc="Generated Code"
private void initComponents() {
jPanel1 = new javax.swing.JPanel();//标签
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();//登录按钮
jButton2 = new javax.swing.JButton();//
jTextField1 = new javax.swing.JTextField();//文本框
jTextField2 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//关闭时java网页设计代码的操作java网页设计代码,即退出程序
setTitle("登录界面");//设置标题:欢迎使用股票管理系统
setResizable(false);//设置窗口不可调节大小
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18));//设置标签的字体
jLabel1
.setText("您好java网页设计代码,请输入信息");
jLabel2.setText("用户名");
jLabel3.setText("用户密码");
jButton1.setText("登录");
jButton1.addActionListener(new java.awt.event.ActionListener() {//采用匿名内部类来实现按钮监听功能
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("退出");
jButton2.addActionListener(new java.awt.event.ActionListener() {//同上
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(//层次布局管理器java网页设计代码,下面n长的代码,就是设置位置,自己看吧 , 呵呵,这个必须的,就不多写了
推荐阅读
- 移动网连不了日本服务器,移动无法连接外网
- oracle列行函数,oracle列转行函数unpivot
- html自定义标签有哪些,html自定义标签怎么写
- 埃及冒险解谜游戏,埃及谜题
- c语言xml报文解析函数 c语言 xml解析
- 4752g是什么cpu,4750g
- 角色扮演游戏介绍词,角色扮演游戏策划案
- mysql建表语句添加索引,mysql给表加索引
- php数据库插入数据 php怎么添加数据库