
App包
package com.Allen;
import javax.swing.*;
public class App {
public static void main(String[]args)
{
MainJFrame mainJFrame=new MainJFrame();
}
}
MainJFrame包
package com.Allen;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
public class MainJFrame extends JFrame implements KeyListener , ActionListener {
int date[][]=new int[4][4];
int loseflag=1;
int score=0;
String theme="A-";
JMenuItem jMenuItem1=new JMenuItem("经典");
JMenuItem jMenuItem2=new JMenuItem("炫彩");
JMenuItem jMenuItem3=new JMenuItem("糖果");
JMenuItem jMenuItem4=new JMenuItem("重置");
public MainJFrame(){
this.InitFrame();
this.InitMexnu();
this.InitDate();
this.paintView();
this.addKeyListener(this);
super.setVisible(true);
}
public void InitMexnu() {
JMenuBar jMenuBar=new JMenuBar();
JMenu jMenu1=new JMenu("换肤");
JMenu jMenu2=new JMenu("重新开始游戏");
jMenuBar.add(jMenu1);
jMenuBar.add(jMenu2);
jMenu2.add(jMenuItem4);
jMenuItem4.addActionListener(this);
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem2);
jMenu1.add(jMenuItem3);
jMenuItem1.addActionListener(this);
jMenuItem2.addActionListener(this);
jMenuItem3.addActionListener(this);
super.setJMenuBar(jMenuBar);
}
public void InitDate(){
this.GenterNum();
this.GenterNum();
}
public void horizontalSwap(){
for (int i = 0; i < date.length; i++) {
this.reverseArray(date[i]);
}
}
public void reverseArray(int arr[]){
for (int start = 0, end=arr.length-1; start < end; start++,end--) {
int temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
}</