「java图片轮播」html图片轮播图怎么做

博主:adminadmin 2023-01-11 20:33:10 86

今天给各位分享java图片轮播的知识,其中也会对html图片轮播图怎么做进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

请给我的JAVA程序添加一个自动播放图片功能

//其余的类在qq上给你..

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Image;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.WindowEvent;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.lang.reflect.AccessibleObject;

import java.lang.reflect.Field;

import java.util.Properties;

import javax.swing.BorderFactory;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.LookAndFeel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.event.DocumentEvent;

import javax.swing.event.DocumentListener;

import javax.swing.filechooser.FileNameExtensionFilter;

public class ImageFrame extends JFrame implements ActionListener, MouseListener {

/**

*

*/

private static final long serialVersionUID = -5241799989073556019L;

static Properties property = new Properties();

static {

Class iClass;

try {

iClass = Class.forName("sun.awt.im.InputMethodContext");

Field field = iClass.getDeclaredField("belowTheSpotInputRequested");

AccessibleObject.setAccessible(new AccessibleObject[] { field },

true);

field.setBoolean(null, false);

} catch (Exception e) {

}

}

public JPanel imagePanel;

public JPanel buttonPanel;

public JPanel statePanel;

public JLabel imageLabel;

public JLabel stateLabel;

public JButton before;

public JButton play;

public JButton stop;

public JButton next;

public JButton bigger;

public JButton smaller;

static JTextArea area = new JTextArea(5, 60);

JScrollPane scroll = new JScrollPane(area);

public File picFile;

public Image img;

public ImageIcon imageIcon;

public String fileParent;

FileNameExtensionFilter imageFilter = new FileNameExtensionFilter(null,

"jpeg", "jpg", "png", "gif");

JFileChooser imageChooser = new JFileChooser();

public File filePath[];

public File imagePath[];

public static Picture images[];

public int imageFileNumber = 0;

public static int locationImage = 0;

public static ImageFrame myImageFrame;

private PlayTimer playTimer;

public Image[] imageOffer;

public int scale = 8;

public JScrollPane imageScrollPane;

public ImageFrame(String picPath) {

picFile = new File(picPath);

fileParent = picFile.getParent();

filePath = (new File(fileParent)).listFiles();

try {

img = javax.imageio.ImageIO.read(picFile);

} catch (IOException ex) {

ex.printStackTrace();

}

imageIcon = new ImageIcon(img);

imageLabel = new JLabel(imageIcon);

imagePanel = new JPanel(new BorderLayout());

imagePanel.setBackground(Color.black);

//R:238 G:243 B:250

//imagePanel.setBackground(new Color(238,243,250));

stateLabel = new JLabel();

final String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

try {

UIManager.setLookAndFeel(windows);

SwingUtilities.updateComponentTreeUI(this);// 更新控件的外观

} catch (Exception e) {

e.printStackTrace();

}

setLayout(new BorderLayout());

setTitle("PowerSee 图片查看器");

setIconImage(new ImageIcon("icon/powerSee.png").getImage());

setSize(800, 600);

this.setMinimumSize(new Dimension(600, 400));

setVisible(true);

setExtendedState(JFrame.MAXIMIZED_BOTH);

buttonPanel = makeButtonPanel();

area.setLineWrap(true);

// area.setWrapStyleWord(true);

area.addMouseListener(this);

// area.setFont(new Font(area.getFont().getFamily(), Font.PLAIN,

// 18));

LookAndFeel.installColorsAndFont(area, "Label.background",

"Label.foreground", "TextArea.font");

area.setBorder(BorderFactory.createTitledBorder("此处可添加照片描述:"));

area.setLineWrap(true);

area.setWrapStyleWord(true);

area.getDocument().addDocumentListener(new SWING_OnValueChanged());

/*

area.setText("");

area.setText("像素大小: " + imageIcon.getIconWidth() + "*"

+ imageIcon.getIconHeight() + " 文件位置: " + picFile.toString()

+ " 文件大小: " + picFile.length() / 1024 + "KB");

*/

/*

area.getDocument()

.addDocumentListener(new SWING_OnValueChanged());

*/

// area.setBackground(new Color() );

Font font = new Font("宋体", Font.PLAIN, 17);

area.setFont( font);

// area.setEditable(false);

statePanel = new JPanel();

//:36 G:53 B:71R:192 G:192 B:196

statePanel.setBackground(new Color(192,192,196));

stateLabel.setText("像素大小: " + imageIcon.getIconWidth() + "*"

+ imageIcon.getIconHeight() + " 文件位置: " + picFile.toString()

+ " 文件大小: " + picFile.length() / 1024 + "KB");

//stateLabel;

imagePanel.add(imageLabel, BorderLayout.CENTER);

imageScrollPane = new JScrollPane(imagePanel);

add(imageScrollPane, BorderLayout.CENTER);

add(buttonPanel, BorderLayout.NORTH);

//statePanel.add(stateLabel);

//statePanel.setBackground(Color.black);

statePanel.add(area, BorderLayout.CENTER);//scroll

add(statePanel, BorderLayout.SOUTH);

imagePanel.repaint();

imagePanel.validate();

Load();

}

//对于此法可借鉴,返回一个panel竟然......

public JPanel makeButtonPanel() {

JPanel aButtonPanel = new JPanel();

before = new JButton("前一张");

next = new JButton("下一张");

play = new JButton("自动播放");

stop = new JButton("停止");

bigger = new JButton("放大");

smaller = new JButton("缩小");

stop.setEnabled(false);

before.addActionListener(this);

next.addActionListener(this);

play.addActionListener(this);

stop.addActionListener(this);

bigger.addActionListener(this);

smaller.addActionListener(this);

aButtonPanel.add(before);

aButtonPanel.add(play);

aButtonPanel.add(stop);

aButtonPanel.add(next);

aButtonPanel.add(smaller);

aButtonPanel.add(bigger);

return aButtonPanel;

}

/*

* //imageFileNumber 个图像文件

//filePath.length 个文件

//filePath 以某个文件夹的所有文件为元素的数组, 以File类型为元素

//imagePath 以所有图像文件为元素的数组,仍然以File类型为元素

*/

public void Load() {

imageChooser.setFileFilter(imageFilter);

//System.out.println(filePath.length+"----");

//filePath.length,也就是Image这个文件夹里有多少个文件.......所有种类的文件....!!

for (int i = 0; i filePath.length; i++) {

if (!filePath[i].isDirectory() imageFilter.accept(filePath[i])) {

imageFileNumber++;

} else {

filePath[i] = null;

}

}

//imageFileNumber 个图像文件

//filePath.length 个文件

//filePath 以某个文件夹的所有文件为元素的数组, 以File类型为元素

//imagePath 以所有图像文件为元素的数组,仍然以File类型为元素

imagePath = new File[imageFileNumber];

images = new Picture[imageFileNumber];

imageFileNumber = 0;

for (int i = 0; i filePath.length; i++) {

if (filePath[i] != null) {

imagePath[imageFileNumber++] = filePath[i];

}

}

imageFileNumber--;

for (int i = 0; i imagePath.length; i++) {

if (imagePath[i] == picFile) {

locationImage = i;

}

}

for (int i = 0; i imagePath.length; i++) {

initTxt(imagePath[i], i);

}

}

public void initTxt(File picFile, int i) {

try {

property.load(new FileInputStream("a.properties"));

/*

String txt = property.getProperty(picFile.getParent() + "."

+ picFile.getName());

*/

images[i] = new Picture(imagePath[i].getParent() + "."

+ imagePath[i].getName(), "");

} catch (Exception e) {

}

//初始化图片的时候,要从资源文件里读取所有文件的txt信息,可能花费时间较长

}

/*

*

//imageFileNumber 个图像文件

//filePath.length 个文件

//filePath 以某个文件夹的所有文件为元素的数组, 以File类型为元素

//imagePath 以所有图像文件为元素的数组,仍然以File类型为元素

*/

public void Before() {

scale = 8;

if (--locationImage 0) {

locationImage = imageFileNumber;

}

try {

img = javax.imageio.ImageIO.read(imagePath[locationImage]);

} catch (IOException ex) {

ex.printStackTrace();

}

imageIcon.setImage(img);

imageLabel.setIcon(imageIcon);

picFile = imagePath[locationImage];

/*

String text = "像素大小: " + imageIcon.getIconWidth() + "*"

+ imageIcon.getIconHeight() + " 文件位置: " + picFile.toString()

+ " 文件大小: " + picFile.length() / 1024 + "KB";

*/

//System.out.println(picFile.toString());

//Picture p = new Picture(picFile, text);

try {

Properties property = new Properties();

property.load(new FileInputStream("a.properties"));

String areaTxt = "";

areaTxt = property.getProperty(picFile.getParent() + "."

+ picFile.getName());

area.setText("");

area.setText(areaTxt);

} catch (Exception e) {

}

imagePanel.repaint();

imagePanel.validate();

imageScrollPane.repaint();

imageScrollPane.validate();

}

/*

* //imageFileNumber 个图像文件

//filePath.length 个文件

//filePath 以某个文件夹的所有文件为元素的数组, 以File类型为元素

//imagePath 以所有图像文件为元素的数组,仍然以File类型为元素

*/

public void Next() {

scale = 8;

if (++locationImage imageFileNumber) {

locationImage = 0;

}

try {

img = javax.imageio.ImageIO.read(imagePath[locationImage]);

} catch (IOException ex) {

ex.printStackTrace();

}

imageIcon.setImage(img);

imageLabel.setIcon(imageIcon);

picFile = imagePath[locationImage];

try {

Properties property = new Properties();

property.load(new FileInputStream("a.properties"));

String areaTxt = "";

areaTxt = property.getProperty(picFile.getParent() + "."

+ picFile.getName());

area.setText("");

area.setText(areaTxt);

} catch (Exception e) {

}

imagePanel.repaint();

imagePanel.validate();

imageScrollPane.repaint();

imageScrollPane.validate();

}

public void Bigger() {

ImageIcon icon = imageIcon;

if (scale = 17) {

ImageIcon tmpicon = new ImageIcon(new DrawImage(icon.getImage(),

icon.getIconWidth() / 8, icon.getIconHeight() / 8, ++scale)

.getImage());

imageLabel.setIcon(tmpicon);

} else {

return;

}

}

public void Smaller() {

ImageIcon icon = imageIcon;

if (scale 1) {

ImageIcon tmpicon = new ImageIcon(new DrawImage(icon.getImage(),

icon.getIconWidth() / 8, icon.getIconHeight() / 8, --scale)

.getImage());

imageLabel.setIcon(tmpicon);

} else {

return;

}

}

public void actionPerformed(ActionEvent e) {

if (e.getSource().equals(before)) {

Before();

}

if (e.getSource().equals(next)) {

Next();

}

if (e.getSource().equals(play)) {

stop.setEnabled(true);

before.setEnabled(false);

next.setEnabled(false);

bigger.setEnabled(false);

smaller.setEnabled(false);

play.setEnabled(false);

playTimer = new PlayTimer(this);

playTimer.start();

}

if (e.getSource().equals(stop)) {

stop.setEnabled(false);

before.setEnabled(true);

next.setEnabled(true);

bigger.setEnabled(true);

smaller.setEnabled(true);

play.setEnabled(true);

playTimer.cancel();

}

if (e.getSource().equals(bigger)) {

Bigger();

}

if (e.getSource().equals(smaller)) {

Smaller();

}

}

public void mouseClicked(MouseEvent arg0) {

// 鼠标点击

area.setEditable(true);

// pane.add(scroll, BorderLayout.CENTER);

}

public void mouseExited(MouseEvent arg0) {

// 鼠标离开区域

area.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); //鼠标离开Text区后恢复默认形态

area.setBackground(null);

//保存信息

//area.setEditable(false);

}

public void mousePressed(MouseEvent arg0) {

}

public void mouseReleased(MouseEvent arg0) {

// 鼠标释放

}

public void mouseEntered(MouseEvent arg0) {

// 鼠标释进入区域

area.setCursor(new Cursor(Cursor.TEXT_CURSOR)); //鼠标进入Text区后变为文本输入指针

area.setBackground(new Color(255, 255, 170));

}

protected void processWindowEvent(WindowEvent e) {

super.processWindowEvent(e);

if (e.getID() == WindowEvent.WINDOW_CLOSING) {

try {

} catch (Exception ex) {

}

System.exit(0);

}

}

public static void main(String a[]) {

new ImageFrame("Image/p1.jpg");

}

}

class Picture {

String text;

String picFile;

Picture(String string, String text) {

this.picFile = string;

this.text = text;

}

String getText() {

return this.text;

}

String getFilePath() {

return this.picFile;

}

void setText(String text) {

this.text = text;

}

}

class SWING_OnValueChanged implements DocumentListener {

public void changedUpdate(DocumentEvent e) {

textValueChanged(e);

}

public void insertUpdate(DocumentEvent e) {

textValueChanged(e);

}

public void removeUpdate(DocumentEvent e) {

textValueChanged(e);

}

public void textValueChanged(DocumentEvent evt) {

//images

int i = 0;

System.out.println("Swing文本框的内容改变了!" + ImageFrame.locationImage);

i = ImageFrame.locationImage;

//System.out.println("图片!" + ImageFrame.images[i].getFilePath());

try {

ImageFrame.property.setProperty(ImageFrame.images[i].getFilePath(),

ImageFrame.area.getText());

// ImageFrame.images[i].setText(ImageFrame.area.getText());

ImageFrame.property.store(new FileOutputStream("a.properties"),

"a.properties");

} catch (Exception ex) {

}

}

}

java myeclipse软件 可以实现图片轮播吗

这个和MyEclipse没什么关系,但是也可以编辑。实现这个功能的是htm+css+javascript。这三个不是编译型语言,使用普通的编辑器就行,最简单的是windows的记事本。编写完成后把后缀名改成.html就行。

java web 怎么统计某个图片在前端页面展示的次数 图片在前端以轮播的形式展示

当图片展示的时候用ajax向后台传值证明展示了一次。后台不就可以统计次数了

北大青鸟java培训:banner轮播图的利弊?

对于许多的企业网站来说,首页最上部分一般都是企业的banner图,为了能够更多的展现内容,许多的设计师将banner都设计成为轮播图的形式,但是,真的轮播图就有很好的展现和点击吗,其实不然,反而因为轮播图的图片大小和代码问题导致了许多SEO问题的产生。

今天,IT培训就仔细来分析一下,到底要不要设置banner轮播图呢。

确保你真的需要使用轮播图首先,设计不当的轮播图容易被用户当成与他想浏览的内容不相关的广告图片而直接无视。

在各种网页中早以身经百战的用户,会选择最快速的方式找到和浏览他们想要看的内容。

把精力放在翻看没有预期的轮播图上显然是低效的,一上来就自动进入了用户的视觉盲区。

下面的热力图展示了用户的浏览行为习惯:快速扫描找到想要阅读的区域,然后再进行有序的沉浸式阅读,毫无例外他们都忽略了看起来像广告的图片部分。

除此之外,在2013就有研究结果表明,轮播图的交互效果十分不理想:只有1%的用户点击了轮播图上切换按钮,其中84%的用户只在首屏点了1次。

还有学者针对30多个B2B的网站的网站进行了研究分析,根据轮播图的内容分成了三类:品牌宣传(Branding)、白皮书/在线研讨会(ThoughtLeadership)、服务推广(ServicePromtion),发现不管是哪一类的内容,点击率都很低(0.16%~0.65%):不仅如此,不少使用轮播图的网站还存在以下几种SEO问题:复杂的大图导致网站性能低,加载速度慢。

一般轮播图都会承载大量的图片信息,尤其是那些首屏就被高分辨率轮播图铺满的网站,这样庞大的图片信息会对加载速度造成很大影响。

每多加载1秒,就会流失更多用户。

无论是用户还是搜索引擎,都偏好加载更快的网站。

使用轮换的标题。

不少开发者倾向于给页面最上方的轮播图片打上标签,使页面上出现轮换的4-5个不同的标签,导致相关关键词的检索能力降低。

Flash的使用。

部分网站的轮播图使用Flash去展示内容,它能够做出很酷的效果,但却无法被任何搜索引擎抓取。

综上所述,设计不当的轮播图容易被忽略,点击率不理想,还可能会对SEO造成负面影响。

所以,我们不应该在还没有仔细思考过页面希望给用户传容的优先级和希望达到的效果时,就哪里“需要”哪里搬。

事实上,有很多其他方式也能帮助我们解决问题,并带来更好的效果:1、找到最需要触达给用户的内容,将次要内容放在次级位置展示谷歌云平台的产品与服务种类繁多,但并没有使用轮播图展示全部产品和特性,而是将浓缩的品牌价值和理念清晰地展现在用户面前,并提供主(免费试用)、次(与销售人员联系)两个明显的转化入口。

同时,将其他次要入口铺在下方,让用户可以选择通过顶导航或者继续往下浏览,快速找到感兴趣的内容。

2、让它成为内容的一部分氧气是一个专注于提供内衣购买推荐的app,当你按顺序滚动浏览页面的商品时,促销信息会以和通常产品推荐一样的形式出现在你面前,打扰感低,对进入沉浸式阅读的用户转化效果好。

3、砍掉不重要的推广图,直接展示内容右边的图片似乎看起来更“好看”,更“吸引人”,然而在实际场景中用户总是习惯性的忽略banner部分的内容,选择性的浏览正文部分,直接展示用户需要的内容,可以提高用户的检索效率,从而带来更高的转化率。

java怎么样才能使图片在窗口内实现循环播放图片!谢谢!

html

head

style

#d1{

width:100px;

height:100px;

background-color:white;

position:relative;

}

/style

script

function go2(){

var div = document.getElementById('d1');

var v1 = div.style.left;

div.style.left = parseInt(v1) + 50 + 'px';

}

function go1(){

var taskId = setInterval(go2,1000);

setTimeout(function(){

clearInterval(taskId);

},7000);

}

/script

/head

body

div id="d1" style="left:20px;"

img src="图片的地址" id="img1"/a href="javascript:;"

/div

input type="button" value="走吧" onclick="go1();"/

/body

/html

你点击这个按钮的话 可以实现每一秒走一下。

java图形界面实现图片自动轮播

现在没空帮你写代码了,给你个思路自己写吧!轮播肯定是要切换图片的,并且一般切换的时候是从左到右或从右到左慢慢切的,所以你定义一个图片地址数组,再定义两个jlabel用来显示图片,一个JLabel显示当前图片,另一个显示最新图片!好了,现在你定义一个timer定时器来切换,每隔两秒,就判断一下最新的图片是哪个jlabel,然后将另一个jlabel填充新的图片,然后setlocation()来移动图片,x坐标每次向左几个像素,直至移动完成!这样就是一次轮播,当然你需要将两个jlabel放到一个panel中,免得会出现第二个图片多出一截在慢慢移动的情况

关于java图片轮播和html图片轮播图怎么做的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2023-01-11,除非注明,否则均为首码项目网原创文章,转载请注明出处。