然后把改名后的照片文件放到你的项目名的目录下,比如你的项目名叫"slideshow",你就把照片文件放到slideshow文件夹下.
最后把下面的Java程序拷贝到你的项目中,把有DD类名的地方改成你的类名,就行了.
完整的让一些照片在JFrame窗体里自动随机播放的幻灯片程序如下
(我用的图片文件是photo1.jpg,photo2.jpg,photo3.jpg,注意事项在注释中注明
import java.awt.Graphics
import javax.swing.ImageIcon
import javax.swing.JFrame
public class DD extends JFrame implements Runnable{
ImageIcon ii=new ImageIcon("photo1.jpg")//这里换成你的图片文件名,放在你的项目名的文件夹中
DD(){
super("Slide")
setSize(400, 400)
setLocationRelativeTo(null)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
setVisible(true)
}
public void paint(Graphics g){
super.paint(g)
g.drawImage(ii.getImage(),0,0,400,400,null)
}
@Override
public void run() {
while(true){
try {
Thread.sleep(500)//这里是幻灯片播放间隔的时间,这里为500毫秒=0.5秒
} catch (InterruptedException e) {
e.printStackTrace()
}
int i=(int)(Math.random()*3)+1//这里是产生从1-3的随机数,如果你有6个图片文件,把3改成6就是从1-6的随机数了.
ii=new ImageIcon("photo"+i+".jpg")//这里调用你的图片文件,如果你有6个图片文件,改成从1-6的文件名方便调用
this.repaint()
}
}
public static void main(String[] args) {
DD d=new DD()
Thread t=new Thread(d)
t.start()
}
}
java导出ppt幻灯片可采用API的方法来执行,在java程序中导入spire.presentation.jar,然后执行如下代码:import com.spire.presentation.*
import com.spire.presentation.drawing.FillFormatType
import java.awt.*
public class TEST {
public static void main(String[] args)throws Exception{
//创建PPT文档(默认包含一页空白幻灯片)
Presentation presentation = new Presentation()
//添加新矩形框到第一个幻灯片
Rectangle rec = new Rectangle((int) presentation.getSlideSize().getSize().getWidth() / 2 - 250, 80, 500, 150)
IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec)
shape.getShapeStyle().getLineColor().setColor(Color.white)
shape.getFill().setFillType(FillFormatType.NONE)
//添加文字到矩形框
shape.appendTextFrame("你好 世界!")
//设置文字的字体和样式
PortionEx textRange = shape.getTextFrame().getTextRange()
textRange.getFill().setFillType(FillFormatType.SOLID)
textRange.getFill().getSolidColor().setColor(Color.blue)
textRange.setFontHeight(66)
textRange.setLatinFont(new TextFont("宋体"))
//保存文档
presentation.saveToFile("helloWorld.pptx", FileFormat.PPTX_2013)
presentation.dispose()
}
}