请给我的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) {
}
}
}
大学生经常去哪些网站或论坛?
1.QQ我想每个上网的都差不多有吧!QQ空间和游戏里大学生应该不少。2大学生上网常做的事,上QQ,听音乐,看电影,玩游戏,看电子书,也有爱聊天的,要么查资料,所以有这些东西的网站特别是知名的以及搜索引擎排名靠前的网站是首选。3网吧,这个地方是大部分大学生上网的主要据点,可以考虑在网吧以搞活动的方式宣传,比如利用流行的电子竞技搞比赛等。至此,仅供参考
如何拓展校园市场
想要拓展校园市场,宣传是必不可少的。一个好的产品经营,必然是需要人才能够完善市场,也只有这样才能够真正获得更多的进步,也才能够打入校园市场内部,了解更多商机。好的产品必然是需要市场打磨,市场的拓展必然还是需要人才的带领,因此,必须要找到窍门才能够做好更多的成绩。
在校园内做市场,必然团队之间的协作也是非常重要, 定期地做一些促销和活动,必然是需要大家一起合作,这样才能够真正出成绩。
学生兼职,对于校园的市场也是有一定的帮助,可以从一定程度上帮助自己更好地掌握校园市场和用户者心理,这样也有利于市场的稳定。而对于很多人来说,如果能够在校园里拥有一个商品店,必然也是有很多生意可做,如果能够定期做些促销活动,是不错的办法。
虽然我们都是学生,但是说到生意上的市场必然还是需要进行一番调研的,只有这样才知道走什么样的产品合适,才能把市场拓展开,这一点是非常重要的。