java实现文字循环上下滚动并逐渐放大或缩小
在编辑一个点名系统同,想在窗口里把所有人的名字循环地上下滚动,在一个时刻显示3个名字上下滚动,并且从上滚到中间的时候逐渐变大,从中间滚到下面的时候逐渐变小,哪位高手可以帮...
在编辑一个点名系统同,想在窗口里把所有人的名字循环地上下滚动,在一个时刻显示3个名字上下滚动,并且从上滚到中间的时候逐渐变大,从中间滚到下面的时候逐渐变小,哪位高手可以帮一下我?
P.S.不要jsp和JavaScript的,要纯java application 展开
P.S.不要jsp和JavaScript的,要纯java application 展开
2个回答
展开全部
是用java Applet 么?
我试着写了个,估计代码不是很简, 你看看是不是这种效果:坐标自己可以去调整下,名字从上到下移动,从上到中间的时候变大,过了中间逐渐变小,过了底部显示下一个名字,循环显示,题意应该没理解错吧
import java.applet.*;
import java.awt.*;
public class ShowName extends Applet
{
String names[]=new String[]{"luojian","qianhongcheng","fenglingxin","luoxiaojian","wangyin"};
int size=20;
int index =0;
int offsetY=20;
int size1 =size;
int size2 =size-10;
int size3 =size-20;
int name1Y =0+offsetY;
int name2Y =-40+offsetY;
int name3Y =-80+offsetY;
int name1Index =index;
int name2Index =index+1;
int name3Index =index+2;
public void init()
{
resize(400,400);
setVisible(true);
}
public void paint(Graphics g)
{
try
{
checkName("name1Index",name1Y);
checkName("name2Index",name2Y);
checkName("name3Index",name3Y);
String name1 =names[name1Index];
String name2 =names[name2Index];
String name3 =names[name3Index];
name1Y=checkY(name1Y);
name2Y=checkY(name2Y);
name3Y=checkY(name3Y);
size1=checkSize(name1Y,size1);
size2=checkSize(name2Y,size2);
size3=checkSize(name3Y,size3);
Font font1 = new Font(null,Font.PLAIN,size1);
Font font2 = new Font(null,Font.PLAIN,size2);
Font font3 = new Font(null,Font.PLAIN,size3);
g.setFont(font1);
g.drawString(name1, 100, name1Y);
g.setFont(font2);
g.drawString(name2, 100, name2Y);
g.setFont(font3);
g.drawString(name3, 100, name3Y);
Thread.sleep(300);
}
catch(Exception e)
{
e.printStackTrace();
}
repaint();
}
public int checkSize(int p,int psize)
{
if(p<200)
psize =psize+10;
if(p>200)
psize =psize-10;
if(p>=400)
psize =size-20;
return psize;
}
public int checkY(int p)
{
if(p>=400)
p=-80;
else
p=p+40;
return p;
}
public void checkName(String nameindex,int p)
{
if(p>=400)
{
if(nameindex.equals("name1Index"))
{
if(name1Index<4)
name1Index++;
else
name1Index =index;
}
if(nameindex.equals("name2Index"))
{
if(name2Index<4)
name2Index++;
else
name2Index =index;
}
if(nameindex.equals("name3Index"))
{
if(name3Index<4)
name3Index++;
else
name3Index =index;
}
}
}
}
我试着写了个,估计代码不是很简, 你看看是不是这种效果:坐标自己可以去调整下,名字从上到下移动,从上到中间的时候变大,过了中间逐渐变小,过了底部显示下一个名字,循环显示,题意应该没理解错吧
import java.applet.*;
import java.awt.*;
public class ShowName extends Applet
{
String names[]=new String[]{"luojian","qianhongcheng","fenglingxin","luoxiaojian","wangyin"};
int size=20;
int index =0;
int offsetY=20;
int size1 =size;
int size2 =size-10;
int size3 =size-20;
int name1Y =0+offsetY;
int name2Y =-40+offsetY;
int name3Y =-80+offsetY;
int name1Index =index;
int name2Index =index+1;
int name3Index =index+2;
public void init()
{
resize(400,400);
setVisible(true);
}
public void paint(Graphics g)
{
try
{
checkName("name1Index",name1Y);
checkName("name2Index",name2Y);
checkName("name3Index",name3Y);
String name1 =names[name1Index];
String name2 =names[name2Index];
String name3 =names[name3Index];
name1Y=checkY(name1Y);
name2Y=checkY(name2Y);
name3Y=checkY(name3Y);
size1=checkSize(name1Y,size1);
size2=checkSize(name2Y,size2);
size3=checkSize(name3Y,size3);
Font font1 = new Font(null,Font.PLAIN,size1);
Font font2 = new Font(null,Font.PLAIN,size2);
Font font3 = new Font(null,Font.PLAIN,size3);
g.setFont(font1);
g.drawString(name1, 100, name1Y);
g.setFont(font2);
g.drawString(name2, 100, name2Y);
g.setFont(font3);
g.drawString(name3, 100, name3Y);
Thread.sleep(300);
}
catch(Exception e)
{
e.printStackTrace();
}
repaint();
}
public int checkSize(int p,int psize)
{
if(p<200)
psize =psize+10;
if(p>200)
psize =psize-10;
if(p>=400)
psize =size-20;
return psize;
}
public int checkY(int p)
{
if(p>=400)
p=-80;
else
p=p+40;
return p;
}
public void checkName(String nameindex,int p)
{
if(p>=400)
{
if(nameindex.equals("name1Index"))
{
if(name1Index<4)
name1Index++;
else
name1Index =index;
}
if(nameindex.equals("name2Index"))
{
if(name2Index<4)
name2Index++;
else
name2Index =index;
}
if(nameindex.equals("name3Index"))
{
if(name3Index<4)
name3Index++;
else
name3Index =index;
}
}
}
}
展开全部
<html>
<head>
<meta http-equiv=content-type content="text/html;charset=GBK">
<script>
var students = ["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"];
// 做了一个自定义的堆栈,来实现顺序显示
var stack = {
tags : [document.createElement("h5"),
document.createElement("h4"),
document.createElement("h3"),
document.createElement("h2"),
document.createElement("h1"),
document.createElement("h2"),
document.createElement("h3"),
document.createElement("h4"),
document.createElement("h5")],
data : ["", "", "", "", "", "", "", "", ""],
push : function(text){
this.data.shift();
this.data.push(text);
for(var i=0; i<this.tags.length; i++){
this.tags[i].innerHTML = this.data[i];
}
}
};
</script>
</head>
<body>
</body>
<script>
var tags = stack.tags;
for(var j=0; j<tags.length; j++)
document.body.appendChild(tags[j]);
// 每一秒显示一个姓名
function func(){
var index = 0;
var len = students.length;
var timer = setInterval(function(){
var text = students[index++];// 如果达到最后一个姓名,则停止循环
if(text) { stack.push(text); }
else { clearInterval(timer); return false; }
}, 1000);
}
func();
</script>
</html>
<head>
<meta http-equiv=content-type content="text/html;charset=GBK">
<script>
var students = ["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"];
// 做了一个自定义的堆栈,来实现顺序显示
var stack = {
tags : [document.createElement("h5"),
document.createElement("h4"),
document.createElement("h3"),
document.createElement("h2"),
document.createElement("h1"),
document.createElement("h2"),
document.createElement("h3"),
document.createElement("h4"),
document.createElement("h5")],
data : ["", "", "", "", "", "", "", "", ""],
push : function(text){
this.data.shift();
this.data.push(text);
for(var i=0; i<this.tags.length; i++){
this.tags[i].innerHTML = this.data[i];
}
}
};
</script>
</head>
<body>
</body>
<script>
var tags = stack.tags;
for(var j=0; j<tags.length; j++)
document.body.appendChild(tags[j]);
// 每一秒显示一个姓名
function func(){
var index = 0;
var len = students.length;
var timer = setInterval(function(){
var text = students[index++];// 如果达到最后一个姓名,则停止循环
if(text) { stack.push(text); }
else { clearInterval(timer); return false; }
}, 1000);
}
func();
</script>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询