《猜猜看》游戏
在界面上,能够展示三张学生图片;能够对猜测做出反应;能够显示另外三张相片,继续玩。
import java.awt.EventQueue;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.AbstractButton;
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.Graphics;
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 Huang 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;
private Graphics g;
class myFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
String filename = pathname.getName().toLowerCase();