==================================下面代码可以不看,只是为了保证代码的完整
==================================
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Auto {
boolean packFrame = false; /**
* Construct and show the application.
*/
public Auto() {
Auto_Frame frame = new Auto_Frame();
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
} /**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new Auto();
}
});
}
}
=============================
上面的代码不是重点.可以不看....
=============================
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JSplitPane;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JTree;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.TitledBorder;
import java.io.*;
import javax.swing.Timer;public class Auto_Frame extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton jBuAuto = new JButton();
JSplitPane jSplitPane1 = new JSplitPane();
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JTree jTree1 = new JTree();
ImageIcon icon=new ImageIcon("F:/代码区/image/01.jpg");
JLabel jLabel1 = new JLabel(icon);
static Timer AutoTimer;
public Auto_Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(400, 300));
setTitle("Auto");
jBuAuto.setIcon(icon);
jBuAuto.setText("Auto");
jBuAuto.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jBuAuto_actionPerformed(e);
}
});
jLabel1.setText("jLabel1");
contentPane.add(jPanel1, java.awt.BorderLayout.SOUTH);
jPanel1.add(jBuAuto);
contentPane.add(jSplitPane1, java.awt.BorderLayout.CENTER);
jSplitPane1.add(jScrollPane1, JSplitPane.LEFT);
jScrollPane1.getViewport().add(jTree1);
jSplitPane1.add(jScrollPane2, JSplitPane.RIGHT);
jScrollPane2.getViewport().add(jLabel1);
AutoTimer.addActionListener(new ActionListener(){
int i=0;
File f=new File("F:/代码区/image/");
String[] files=f.list();
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==AutoTimer)
{
if(i==files.length)
i=0;
icon=new ImageIcon("F:/代码区/image/"+files[i]);
jLabel1.setIcon(icon);
jLabel1.repaint();
i++; while(i>=0&&i<files.length){
}
}
}
}); } public void jBuAuto_actionPerformed(ActionEvent e) {
AutoTimer.start();
}
}
==================================
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Auto {
boolean packFrame = false; /**
* Construct and show the application.
*/
public Auto() {
Auto_Frame frame = new Auto_Frame();
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
} /**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new Auto();
}
});
}
}
=============================
上面的代码不是重点.可以不看....
=============================
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JSplitPane;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JTree;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.TitledBorder;
import java.io.*;
import javax.swing.Timer;public class Auto_Frame extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton jBuAuto = new JButton();
JSplitPane jSplitPane1 = new JSplitPane();
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JTree jTree1 = new JTree();
ImageIcon icon=new ImageIcon("F:/代码区/image/01.jpg");
JLabel jLabel1 = new JLabel(icon);
static Timer AutoTimer;
public Auto_Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(400, 300));
setTitle("Auto");
jBuAuto.setIcon(icon);
jBuAuto.setText("Auto");
jBuAuto.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jBuAuto_actionPerformed(e);
}
});
jLabel1.setText("jLabel1");
contentPane.add(jPanel1, java.awt.BorderLayout.SOUTH);
jPanel1.add(jBuAuto);
contentPane.add(jSplitPane1, java.awt.BorderLayout.CENTER);
jSplitPane1.add(jScrollPane1, JSplitPane.LEFT);
jScrollPane1.getViewport().add(jTree1);
jSplitPane1.add(jScrollPane2, JSplitPane.RIGHT);
jScrollPane2.getViewport().add(jLabel1);
AutoTimer.addActionListener(new ActionListener(){
int i=0;
File f=new File("F:/代码区/image/");
String[] files=f.list();
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==AutoTimer)
{
if(i==files.length)
i=0;
icon=new ImageIcon("F:/代码区/image/"+files[i]);
jLabel1.setIcon(icon);
jLabel1.repaint();
i++; while(i>=0&&i<files.length){
}
}
}
}); } public void jBuAuto_actionPerformed(ActionEvent e) {
AutoTimer.start();
}
}
这句话老加不上去.
在线等待求助
timer.schedule(new TimerTask() {
public void run()
{
MainProcess();
}
},0,1*3000);
這個可以!
timer.scheduleAtFixedRate(notetimer, 1000, 1000 * 3);
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.
我做的是一个自动播放photo的东西,我想要它每3秒自动播放一张.AutoTimer=new Timer(3000,this);
这句话老加不上去.
在线等待求助
java.util.GregorianCalendar now = null;
tmr.schedule(new java.util.TimerTask(){
public void run(){
now = new GregorianCalendar();
//do something
}
},now.getTime(),3000);