?? moveblock.java
字號(hào):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MoveBlock extends JFrame{
public JPanel cardPanel;
public CardLayout cardLayout;
public JButton jB1;
public JButton jB2;
public int i;
public MoveBlock(Block block,Point p){
super("移動(dòng)方塊");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setLocation(p);
JPanel []panel=new JPanel[block.lengthRoute()];
cardPanel=new JPanel();
cardLayout=new CardLayout();
cardPanel.setLayout(cardLayout);
int blockNUM=block.numBlock();
for(int i=0;i<panel.length;i++){
panel[i]=new JPanel();
panel[i].setLayout(new GridLayout((int)Math.sqrt(blockNUM),(int)Math.sqrt(blockNUM),2,2));
for(int j=0;j<blockNUM;j++){
JButton b1=new JButton(block.route[i].blockString[j].toString());
panel[i].add(b1);
}
cardPanel.add(panel[i],"第"+i+"個(gè)");
}
i=0;
jB1=new JButton("上一步");
jB2=new JButton("下一步");
if(i==0)jB1.setEnabled(false);
ButtonListener listener=new ButtonListener();
JPanel commandPanel=new JPanel();
jB1.addActionListener(listener);
jB2.addActionListener(listener);
commandPanel.add(jB1);
commandPanel.add(jB2);
JPanel contentPane=(JPanel)getContentPane();
contentPane.add(cardPanel,BorderLayout.CENTER);
contentPane.add(commandPanel,BorderLayout.SOUTH);
pack();
show();
}
private void miss(){this.dispose();}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==jB1){i--;cardLayout.previous(cardPanel);if(i==0)jB1.setEnabled(false);jB2.setText("下一步");jB2.setEnabled(true);}
else if(e.getSource()==jB2&&jB2.getText()=="下一步"){i++;cardLayout.next(cardPanel);if(i==cardPanel.getComponentCount()-1){jB2.setText("完成");JOptionPane.showMessageDialog(new JFrame(),"移動(dòng)成功!!!");}jB1.setEnabled(true);}
else if(e.getSource()==jB2&&jB2.getText()=="完成"){
Point p=new Point(250,200);
miss();
new BlockFace(9,p);
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -