代码基本无错误,图片可显示,游戏功能基本可以运行。
<pre class="java" name="code">import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Random;
public class SmallGame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField tfDir;
private JTextField tfClass;
File[] fileArray; // 文件夹下所有文件
int NUM_IMG = 0; // 文件总数目
int index = 0; // 当前文件的序号
int i = 0;
JLabel jlbImg1 = null;
JLabel jlbImg2 = null;
JLabel jlbImg3 = null;
/**
* Launch the application.
*/
class myFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
String filename = pathname.getName().toLowerCase();
if (filename.contains(".jpg")) {
return false;
} else {
return true;
}
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SmallGame frame = new SmallGame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public SmallGame() {
setTitle("\u731C\u731C\u770B\u6E38