📄 cubepanel.java
字号:
// FrontEnd Plus GUI for JAD
// DeCompiled : CubePanel.class
import java.applet.AudioClip;
import java.awt.*;
public class CubePanel extends Panel
implements Runnable
{
private Thread CubeThread;
private CubeSystem CubeSys;
private CubeStack SpinStack;
private Button ButtonSolve;
private boolean Automatic;
public static AudioClip BadSound;
public static AudioClip SpinSound;
private boolean SoundEnabled;
private boolean Ready;
int PrevX;
int PrevY;
Vertex PrevHotpoint;
Image OffScreen;
Graphics OffGraphics;
Dimension OffScreenSize;
CubePanel(TextField textfield)
{
Automatic = false;
SoundEnabled = true;
Ready = false;
CubeSys = new CubeSystem(new Vertex(60F, 60F, 60F));
SpinStack = new CubeStack(textfield);
}
public void DefineBound()
{
CubeSys.DefineBound(size().width, size().height);
}
public void Start()
{
if(CubeThread == null)
{
CubeThread = new Thread(this);
CubeThread.start();
CubeThread.suspend();
Ready = true;
}
}
public void Stop()
{
CubeThread.stop();
CubeThread = null;
}
public void run()
{
while(!Ready) ;
while(CubeThread != null)
{
do
{
if(Automatic)
{
CubeAction cubeaction = SpinStack.ForceUndo();
if(cubeaction != null)
{
try
{
Thread.sleep(100L);
}
catch(InterruptedException _ex) { }
CubeSys.SpinBegin(cubeaction.GetAxis(), cubeaction.GetPlane(), !cubeaction.GetDir());
} else
{
Automatic = false;
ButtonSolve.setLabel("Solve");
break;
}
}
for(int i = 0; i < 5; i++)
{
CubeSys.Spin(1);
repaint();
try
{
Thread.sleep(100L);
}
catch(InterruptedException _ex) { }
}
CubeSys.SpinEnd();
repaint();
} while(Automatic);
CubeThread.suspend();
}
CubeThread = null;
}
public boolean CommandAction(Event event)
{
if("New Game".equals(event.arg))
{
CubeSys.NewGame();
SpinStack.Clear();
repaint();
}
if("Undo".equals(event.arg))
{
CubeAction cubeaction = SpinStack.Undo();
if(cubeaction != null)
{
CubeSys.SpinBegin(cubeaction.GetAxis(), cubeaction.GetPlane(), !cubeaction.GetDir());
CubeThread.resume();
}
}
if("Redo".equals(event.arg))
{
CubeAction cubeaction1 = SpinStack.Redo();
if(cubeaction1 != null)
{
CubeSys.SpinBegin(cubeaction1.GetAxis(), cubeaction1.GetPlane(), cubeaction1.GetDir());
CubeThread.resume();
}
}
if("Scramble".equals(event.arg))
{
CubeSys.NewGame();
SpinStack.Clear();
int j = -1;
int l = -1;
boolean flag1 = false;
SpinStack.EnableUpdate(false);
for(int i1 = 0; i1 < 60; i1++)
{
int i;
int k;
boolean flag;
do
{
i = (int)(Math.random() * 3D);
k = (int)(Math.random() * 3D);
flag = Math.random() > 0.5D;
} while(i > 2 || k > 2 || i == j && k == l && flag == (!flag1));
j = i;
l = k;
flag1 = flag;
SpinStack.Do(new CubeAction(j, l, flag1));
CubeSys.SpinMap(j, l, flag1);
}
SpinStack.SetWatermark();
SpinStack.EnableUpdate(true);
CubeSys.SetCubeMap();
repaint();
}
if("Stop".equals(event.arg))
{
Automatic = false;
ButtonSolve.setLabel("Solve");
}
if("Solve".equals(event.arg))
{
ButtonSolve = (Button)event.target;
Automatic = true;
ButtonSolve.setLabel("Stop");
CubeThread.resume();
}
if(event.target instanceof Checkbox)
SoundEnabled = ((Checkbox)event.target).getState();
return true;
}
public boolean mouseDown(Event event, int i, int j)
{
if(event.controlDown() || event.metaDown())
{
PrevHotpoint = CubeSys.Unproject(i - size().width / 2, size().height / 2 - j);
if(PrevHotpoint == null && SoundEnabled)
BadSound.play();
} else
{
PrevX = i;
PrevY = j;
}
return true;
}
public boolean mouseUp(Event event, int i, int j)
{
if(event.controlDown() || event.metaDown())
{
if(PrevHotpoint == null)
return true;
Vertex vertex = CubeSys.Unproject(i - size().width / 2, size().height / 2 - j);
int k = CubeSystem.ComputeSpin(PrevHotpoint, vertex);
if(k == 9999 && SoundEnabled)
{
BadSound.play();
PrevHotpoint = null;
return true;
}
int l = k <= 0 ? (-k - 1) / 3 : (k - 1) / 3;
int i1 = k <= 0 ? (-k - 1) % 3 : (k - 1) % 3;
boolean flag = k > 0;
if(SoundEnabled)
SpinSound.play();
CubeSys.SpinBegin(l, i1, flag);
SpinStack.Do(new CubeAction(l, i1, flag));
CubeThread.resume();
PrevHotpoint = null;
}
return true;
}
public boolean mouseDrag(Event event, int i, int j)
{
if(event.controlDown() || event.metaDown())
{
return true;
} else
{
double d = ((double)((PrevY - j) * 2) * 3.1415926535897931D) / (double)size().width;
double d1 = ((double)((PrevX - i) * 2) * 3.1415926535897931D) / (double)size().height;
CubeSys.XRotateView(d);
CubeSys.YRotateView(d1);
repaint();
PrevX = i;
PrevY = j;
return true;
}
}
public void paint(Graphics g)
{
update(g);
}
public synchronized void update(Graphics g)
{
Dimension dimension = size();
if(OffScreen == null || dimension.width != OffScreenSize.width || dimension.height != OffScreenSize.height)
{
OffScreen = createImage(dimension.width, dimension.height);
OffScreenSize = dimension;
OffGraphics = OffScreen.getGraphics();
OffGraphics.setFont(getFont());
}
OffGraphics.setColor(Color.lightGray);
OffGraphics.fillRect(0, 0, dimension.width, dimension.height);
if(CubeSys != null)
{
CubeSys.Paint(OffGraphics, dimension.width, dimension.height);
g.drawImage(OffScreen, 0, 0, null);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -