大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1.打开编程工具:
成都创新互联-专业网站定制、快速模板网站建设、高性价比林周网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式林周网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖林周地区。费用合理售后完善,十余年实体公司更值得信赖。
打开java编程的界面,采用的是eclipse软件;
2
2.建立一个java工程:
简洁操作如下:单击“file”-“new”-“java project”;
然后,在工程菜单中选中工程,单击鼠标右键出出来菜单,依次选中“new”-“class”;
具体查看“ eclipse如何建立一个java工程”;
0eclipse如何建立一个java工程
END
2.代码实现步骤
1.建立输入扫描:
采用java中的Scanner类实现输入数据的获取,具体代码如下;
Scanner scan = new Scanner(System.in);
2.接收用户名:
建立一个提示信息,提示输入用户名,并储存输入的用户名,代码如下:
System.out.println("请输入登陆用户名:");
String usename=scan.nextLine();
3.接收密码:
建立一个提示信息,提示输入密码,并存储输入的密码,代码如下:
System.out.println("请输入登陆的密码:");
String password=scan.nextLine();
4.验证信息:
采用if else语句来实现对用户名和密码的验证,并打印提示信息,代码如下:
if(!usename.equals("me")){
System.out.println("用户名非法。");
}else if(!password.equals("123456")){
System.out.println("登陆密码错误。");
}else{
System.out.println("恭喜您,登陆信息通过验证。");
}
不知道你问的是不是生成这种图片验证码?如果只要一个随机四位数 那这行代码就够了(new Random().nextInt(9000) + 1000;),如果是生成页面图片验证码就是下面的了: //设定 响应模式 resp.setContentType("image/jpeg"); // 生成令牌环数据; Integer token = new Random().nextInt(9000) + 1000; // 保存令牌环数据到session中 req.getSession().setAttribute(IMAGE_TOKEN_NAME, token); // 生成令牌环图片 ServletOutputStream out = resp.getOutputStream(); BufferedImage img = new BufferedImage(60, 20, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.setColor(Color.YELLOW); g.fillRect(0, 0, img.getWidth(), img.getHeight()); g.setColor(Color.BLUE); g.setFont(new Font("", Font.BOLD, 18)); g.drawString(String.valueOf(token), 10, 16); ImageIO.write(img, "jpg", out); out.close();
下面简单的介绍他们的功能和用途,执行效率等。每个都有各自的优缺点看你是做甚什么方面的研究开发用。.net,是网站编程,现在很多都用这个,但是这个语言编程都有统一思路,很好掌握。窒息那个效率不是很高;php 支持跨平台,很容易学会,执行的效率很高;asp是ASP.net的前身,它比较稳定,比.net要弱一点。但是比.net好学。jsp 是网页编程,这个学习大约一周就能搞定,不过这个得多实践,不然的话,时间长了,就容易忘记。
我自己做的系统里面用作验证码的JSP的%@page contentType="image/jpeg;charset=utf-8"%%@page import="java.util.*,java.awt.*,java.awt.image.*,javax.imageio.*" %%@ page import="java.io.OutputStream" %html body %! Color getRandColor(int fc,int bc) { Random rd=new Random(); if(fc255) fc=255; if(bc255) bc=255; int red=fc+rd.nextInt(bc-fc); int green=fc+rd.nextInt(bc-fc); int blue=fc+rd.nextInt(bc-fc); return new Color(red,green,blue); } % % Random r=new Random(); response.addHeader("Pragma","No-cache"); response.addHeader("Cache-Control","no-cache"); response.addDateHeader("expires",0); int width=90; int height=23; BufferedImage pic=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); Graphics gc=pic.getGraphics(); gc.setColor(getRandColor(200,250)); gc.fillRect(0,0,width,height); String[] rNum ={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w", "x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N", "O","P","Q","R","S","T","U","V","W","X","Y","Z"}; int[] style = {Font.PLAIN,Font.BOLD,Font.ITALIC,Font.PLAIN+Font.BOLD, Font.BOLD+Font.ITALIC,Font.PLAIN+Font.ITALIC,Font.PLAIN+Font.BOLD+Font.ITALIC}; gc.setColor(Color.WHITE); gc.drawLine(0,30,90,10); gc.setColor(getRandColor(160,200)); for (int i=0;i50;i++) { int x = r.nextInt(width); int y = r.nextInt(height); int xl = r.nextInt(10); int yl = r.nextInt(10); gc.drawLine(x,y,x+xl,y+yl); } gc.setColor(getRandColor(60,150)); String rt = ""; for(int i=0;i4;i++){ String temp = rNum[r.nextInt(62)]; rt = rt+temp; gc.setFont(new Font("Times New Roman",style[r.nextInt(7)],15)); gc.drawString(temp,5+i*15+r.nextInt(10),10+r.nextInt(10)); } gc.dispose(); session.setAttribute("randNum",rt); OutputStream os=response.getOutputStream(); ImageIO.write(pic,"JPEG",os); System.out.println("当前验证码为:"+session.getAttribute("randNum")); os.flush(); os.close(); os=null; response.flushBuffer(); out.clear(); out = pageContext.pushBody(); % /body/html
jSlider.setUI(new MetalSliderUI() {
@Override
public void paintThumb(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.red);
//
g2d.fillRect(thumbRect.x, thumbRect.y, thumbRect.width,
//
thumbRect.height);
g2d.drawImage(img, x, y, width, height, observer);
}
});
同样道理可以改改滑动条的填充颜色,不过有些复杂。你可以参考javax.swing.plaf.basic.BasicSliderUI、javax.swing.plaf.metal.MetalSliderUI等类中的paintTrack方法来实现怎么自定义自己的滑动条哈。
public class Ean13Barcode {
private String code;
public Ean13Barcode(String code) {
super();
this.code = code;
}
public String encode() {
if (null == code) {
return "";
}
char[] codes = code.toCharArray();
int sum = 0;
for (int i = 0; i codes.length; i++) {
int num = codes[i] - '0';
if (isEven(num)) {
sum += num;
} else {
sum += num * 3;
}
}
int x = sum % 10;
return code + (x == 0 ? 0 : 10 - x);
}
private boolean isEven(int x) {
return x % 2 == 0;
}
public static void main(String[] args) {
System.out.println(new Ean13Barcode("692223361219").encode());
}
}