「java滚动效果」滚动特效怎么做
今天给各位分享java滚动效果的知识,其中也会对滚动特效怎么做进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、Java怎么运用Ajax实现滚动效果
- 2、用java怎么写出滚动效果?
- 3、Java程序 实现图形面板上的字幕滚动效果
- 4、JAVA中怎么实现背景图片滚动
- 5、通过javasccript实现图片滚动效果
- 6、求助Java怎么实现窗口标题的滚动
Java怎么运用Ajax实现滚动效果
最简单的方法:进入该页面== 右键== 查看源文件== 然后找相关内容
ajax是js写的,去看js脚本吧
-_|||
------解决方案--------------------
原理很简单的:
1:web界面首先响应鼠标事件,即你在拖动滚动条的时候,触发事件。
2:在事件中向服务器发送请求,即采用ajax技术。
3:服务器接受请求后进行处理。
4:界面响应服务器返回的信息。
用java怎么写出滚动效果?
package edu.njit.cs.ding;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
public class App extends JFrame{
private JButton btn ;
public static Worker w ;
public static int x,y ;
public App(){
btn = new JButton("ok") ;
this.setSize(500,500) ;
this.add(btn) ;
this.setVisible(true);
w = new Worker() ;
}
public static void main(String[] args) throws Exception {
Timer timer = new Timer(false);
App theApp = new App() ;
timer.schedule(App.w, new Date(System.currentTimeMillis() + 1000));
}
class Worker extends TimerTask {
public void run() {
while(true){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
btn.setLocation(x++,y) ;
}
}
}
}
Java程序 实现图形面板上的字幕滚动效果
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
public class mi
{
private static String username;
private static String password ;
private static JTextField []t={
new JTextField("账号:",8),new JTextField(10),
new JTextField("密码:",8),new JPasswordField(10)};
public static void main (String args[]){
JFrame app=new JFrame("账号密码演示程序");
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(280,120);
Container c=app.getContentPane();
c.setLayout(new FlowLayout());
t[0].setEditable(false);
t[2].setEditable(false);
for(int i=0;i4;i++)
c.add(t[i]);t[1].setText("");
JButton[]b={new JButton("确定"),new JButton("重置")};
c.add(b[0]);c.add(b[1]);
app.setLocationRelativeTo(null);
app.setVisible(true);
b[1].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
t[1].setText("");
t[3].setText("");
}
});
// 登录按钮加事件监听器
b[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
username = t[1].getText();
password = t[3].getText();
//判断用户名密码是否正确
if (username.equals("数字") password.equals("123")) {
JOptionPane.showMessageDialog(null, "登陆成功!", "消息",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
}); }
}
JAVA中怎么实现背景图片滚动
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainJFrame extends JFrame {
public MainJFrame() {
//设置标题
super("JFram设置背景图片(Cannel_2020)");
//设置大小
setSize(500, 400);
//设置位置
setLocation(200, 50);
//背景图片的路径。(相对路径或者绝对路径。本例图片放于"java项目名"的文件下)
String path = "background.jpg";
// 背景图片
ImageIcon background = new ImageIcon(path);
// 把背景图片显示在一个标签里面
JLabel label = new JLabel(background);
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0, 0, this.getWidth(), this.getHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
JPanel imagePanel = (JPanel) this.getContentPane();
imagePanel.setOpaque(false);
// 把背景图片添加到分层窗格的最底层作为背景
this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//设置可见
setVisible(true);
//点关闭按钮时退出
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MainJFrame();
}
}
运行如下
通过javasccript实现图片滚动效果
直接给你一段简单的代码,不懂再问
html
head
title图片滚动 /title
style
#div1
{position:relative;width:650px;height:210px;overflow:hidden;
}
#div2{position:absolute;}
li{float:left;list-style-type:none;padding:5px;}
img{border:none;}
#div2 li a:hover{top:-10px;}
a{position:relative;}
/style
script
window.onload=function()
{
var odiv2=document.getElementById('div2');
var ali=odiv2.getElementsByTagName('li');
var aspeed=-5;
var timer=null;
odiv2.innerHTML+=odiv2.innerHTML;
odiv2.style.width=ali[0].offsetWidth*ali.length+'px';
odiv2.onmouseover=function(){clearInterval(timer);};
function a()
{
timer=setInterval(function()
{
odiv2.style.left=odiv2.offsetLeft+aspeed+'px';
if (odiv2.offsetLeft-odiv2.offsetWidth/2)
{
odiv2.style.left='0px';
}
},30);};
odiv2.onmouseout=a;
a();
}
/script
/head
body
div id='div1'
div id='div2'
lia href=""img src="1.jpg" //a/li
lia href=""img src="2.jpg" //a/li
lia href=""img src="3.jpg" //a/li
lia href=""img src="4.jpg" //a/li
/div
/div
/body
/html
希望能解决您的问题。
求助Java怎么实现窗口标题的滚动
窗口标题的滚动, 就是文字的定期更换, javax.swing.Timer 就可以定期执行
效果如图
完整代码
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
public class MyFrame extends JFrame {
//标题文字
public String title = "总要有些随风,有些入梦,有些长留在心中~~~";
//记录显示在标题上的第一个文字,在title中的文字
int index = 0;
// 构造函数
public MyFrame() {
setTitle(title);// 窗口标题
setSize(300, 200);// 窗口大小 宽300 高200
setLocationRelativeTo(null);// 窗口居中
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 当窗口关闭时,程序结束
//创建1个定时器, 每500毫秒执行1次
Timer t = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
index++;
if (index = title.length()) {
index = 0;
}
//标题栏要显示的字符
String str = title.substring(index, title.length()) + title.substring(0, index);
setTitle(str);//设置标题文字
}
});
t.start();//启动定时器,去定期执行任务
}
// main函数
public static void main(String[] args) {
MyFrame frame = new MyFrame();// 创建窗口
frame.setVisible(true);// 让该窗口实例可见
}
}
java滚动效果的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于滚动特效怎么做、java滚动效果的信息别忘了在本站进行查找喔。