java中怎样让swing倒入jsp网页中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java中怎样让swing倒入jsp网页中相关的知识,希望对你有一定的参考价值。
参考技术A Applet 有这功能,说不清楚的。这是介绍:Applet(小应用程序)采用Java创建的基于html的程序。浏览器将其暂时下载到用户的硬盘上,并在Web页打开时在本地运行。一般的Applet只能通过appletviewer或者浏览器来运行,一般的Java程序通过继承Applet类也可以嵌入网页运行。
百科地址:http://baike.baidu.com/view/150834.html?wtp=tt 参考技术B jsp中的java代码是运行在服务器端的,所以不可以调用Swing组件。本回答被提问者采纳 参考技术C 这个是applet技术了。帅哥。具体的你可以看看applet的应用,现在这个应用我知道的胜利软件在搞追问
这个我知道applet可以做到,但是swing就一点不可以了么。。
参考技术D 这样子做的应用毫无意义,你还是学习用js+css来搞网页界面才是正道 第5个回答 2011-08-02 那个不是导入,就是appletjava swing中登录界面验证码的实现。
public class ValidCode extends JComponent implements MouseListener
private String code;
private int width, height = 40;
private int codeLength = 4;
private Random random = new Random();
public ValidCode()
width = this.codeLength * 16 + (this.codeLength - 1) * 10;
setPreferredSize(new Dimension(width, height));
setSize(width, height);
this.addMouseListener(this);
setToolTipText("点击可以更换验证码");
public int getCodeLength()
return codeLength;
/*
设置验证码文字的长度
*/
public void setCodeLength(int codeLength)
if(codeLength < 4)
this.codeLength = 4;
else
this.codeLength = codeLength;
public String getCode()
return code;
/*
产生随机的颜色
*/
public Color getRandColor(int min, int max)
if (min > 255)
min = 255;
if (max > 255)
max = 255;
int red = random.nextInt(max - min) + min;
int green = random.nextInt(max - min) + min;
int blue = random.nextInt(max - min) + min;
return new Color(red, green, blue);
/*
设置验证码具体的字母是什么
*/
protected String generateCode()
char[] codes = new char[this.codeLength];
for (int i = 0, len = codes.length; i < len; i++)
if (random.nextBoolean())
codes[i] = (char) (random.nextInt(26) + 65);
else
codes[i] = (char) (random.nextInt(26) + 97);
this.code = new String(codes);
return this.code;
@Override
protected void paintComponent(Graphics g)
super.paintComponent(g);
if(this.code == null || this.code.length() != this.codeLength)
this.code = generateCode();
width = this.codeLength * 16 + (this.codeLength - 1) * 10;
super.setSize(width, height);
super.setPreferredSize(new Dimension(width, height));
Font mFont = new Font("Arial", Font.BOLD | Font.ITALIC, 25);
g.setFont(mFont);
//绘制出验证码的背景的矩形轮廓
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(getRandColor(200, 250));
g2d.fillRect(0, 0, width, height);
g2d.setColor(getRandColor(180, 200));
g2d.drawRect(0, 0, width - 1, height - 1);
//绘制出验证码背景的线
int i = 0, len = 150;
for (; i < len; i++)
int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int x1 = random.nextInt(width - 10) + 10;
int y1 = random.nextInt(height - 4) + 4;
g2d.setColor(getRandColor(180, 200));
g2d.drawLine(x, y, x1, y1);
/*i = 0; len = 300;
for (; i < len; i++)
int x = random.nextInt(width);
int y = random.nextInt(height);
g2d.setColor(getRandColor(150, 180));
g2d.drawRect(x, y, 0, 0);
*/
//绘制出验证码的具体字母
i = 0; len = this.codeLength;
FontMetrics fm = g2d.getFontMetrics();
int base = (height - fm.getHeight())/2 + fm.getAscent();
for(;i<len;i++)
int b = random.nextBoolean() ? 1 : -1;
g2d.rotate(random.nextInt(10)*0.01*b);
g2d.setColor(getRandColor(20, 130));
g2d.drawString(code.charAt(i)+"", 16 * i + 10, base);
//下一个验证码
public void nextCode()
generateCode();
repaint();
@Override
public void mouseClicked(MouseEvent e)
nextCode();
@Override
public void mousePressed(MouseEvent e)
// TODO Auto-generated method stub
@Override
public void mouseReleased(MouseEvent e)
// TODO Auto-generated method stub
@Override
public void mouseEntered(MouseEvent e)
// TODO Auto-generated method stub
@Override
public void mouseExited(MouseEvent e)
// TODO Auto-generated method stub
呜~
以上是关于java中怎样让swing倒入jsp网页中的主要内容,如果未能解决你的问题,请参考以下文章