重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
可在html页面中加入java代码。
网站制作、成都网站设计介绍好的网站是理念、设计和技术的结合。创新互联建站拥有的网站设计理念、多方位的设计风格、经验丰富的设计团队。提供PC端+手机端网站建设,用营销思维进行网站设计、采用先进技术开源代码、注重用户体验与SEO基础,将技术与创意整合到网站之中,以契合客户的方式做到创意性的视觉化效果。
1、打开HTML软件。
2、在主页选择Java。
3、点击Java。
4、进入编辑页面,进行编辑即可。
//这是一位老师讲课时的爬邮箱代码,你可以参考一下
package cn.itcast.regex.test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
* 网页爬虫:其实就一个程序用于在互联网中获取符合指定规则的数据。
*
* 爬取邮箱地址。
*
*/
public class RegexTest2 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ListString list = getMailsByWeb();
for(String mail : list){
System.out.println(mail);
}
}
public static ListString getMailsByWeb() throws IOException {
//1,读取源文件。
// BufferedReader bufr = new BufferedReader(new FileReader("c:\\mail.html"));
URL url = new URL("");
BufferedReader bufIn = new BufferedReader(new InputStreamReader(url.openStream()));
//2,对读取的数据进行规则的匹配。从中获取符合规则的数据.
String mail_regex = "\\w+@\\w+(\\.\\w+)+";
ListString list = new ArrayListString();
Pattern p = Pattern.compile(mail_regex);
String line = null;
while((line=bufIn.readLine())!=null){
Matcher m = p.matcher(line);
while(m.find()){
//3,将符合规则的数据存储到集合中。
list.add(m.group());
}
}
return list;
}
public static ListString getMails() throws IOException{
//1,读取源文件。
BufferedReader bufr = new BufferedReader(new FileReader("c:\\mail.html"));
//2,对读取的数据进行规则的匹配。从中获取符合规则的数据.
String mail_regex = "\\w+@\\w+(\\.\\w+)+";
ListString list = new ArrayListString();
Pattern p = Pattern.compile(mail_regex);
String line = null;
while((line=bufr.readLine())!=null){
Matcher m = p.matcher(line);
while(m.find()){
//3,将符合规则的数据存储到集合中。
list.add(m.group());
}
}
return list;
}
}
/* 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); //关闭时的操作,即退出程序
setTitle("登录界面"); //设置标题:欢迎使用股票管理系统
setResizable(false); //设置窗口不可调节大小
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18)); //设置标签的字体
jLabel1
.setText("您好,请输入信息");
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( //层次布局管理器,下面n长的代码,就是设置位置,自己看吧,呵呵,这个必须的,就不多写了
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(159, Short.MAX_VALUE)
.addComponent(jLabel1).addGap(140, 140,
140))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(110, 110, 110)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(54, 54, 54)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jTextField2,
javax.swing.GroupLayout.DEFAULT_SIZE,
191,
Short.MAX_VALUE)
.addGap(
112,
112,
112))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
191,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(141, 141, 141)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
68,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(89, 89, 89)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
72,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(145, Short.MAX_VALUE)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(55, 55, 55)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(41, 41, 41)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(48, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
pack();
setLocationRelativeTo(null); //居中
}// /editor-fold
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //事件处理,不建议这样做
// TODO add your handling code here:
String name = this.jTextField1.getText().trim(); //获得用户名,去空格
String password = this.jTextField2.getText().trim(); //获得密码,去空格
if (name.equals("admin") password.equals("123456")) { //如果符合条件.....其实这里应该去和数据库关联,这是死代码
// Showinformation sf=new Showinformation(); //我估计是另外一个框架,就是登录成功之后的框架
// sf.setVisible(true);
// sf.show(); //这个方法就直接秒杀,不用了,因为sf.setVisible(true)已经被调用了,这里就多次一举了
} else { //用户名或者密码验证失败
JOptionPane.showMessageDialog(this, "用户名或者密码错误啦~", "提示", //提示框
JOptionPane.INFORMATION_MESSAGE);
this.jTextField1.setText(""); //清空输入框
this.jTextField2.setText("");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { //事件处理,其实可以将jButton1ActionPerformed放在一起处理,只要获得按钮的标签内容 (JButton)(evt.getSuorse()).getText()就做对比就ko了
// TODO add your handling code here:
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { //好方法,呵呵使用该方式的原因是:awt是单线程模式的,所有awt的组件只能在(推荐方式)事件处理线程中访问,从而保证组件状态的可确定性。java核心编程技术中每个实例基本都用到了
public void run() {
new Main().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;}
// End of variables declaration//GEN-END:variables
你修改一下吧,从记事本获得用户名判断一下就行了