这个JAVA拼图游戏的代码该怎样改?
importjava.awt.Font;importjava.awt.event.ComponentAdapter;importjava.awt.event.Compon...
import java.awt.Font;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class puzzle extends JFrame implements MouseListener,KeyListener{
private static final long serialVersionUID = 1L;
private JList listResult;
private JPanel panMain;
private JPanel panGame;
private JPanel panRight;
private DefaultComboBoxModel dcbm;
private JTextField txtCount;
private JTextField txtLevel;
private JLabel [][] labels;
private final int MAX_LEVEL = 10;
private int[][] nums;
private int level;
private long clickCount = 0L;
/**
* Create the frame
*/
public puzzle() {
super();
addComponentListener(new ComponentAdapter() {
public void componentResized(final ComponentEvent e) {
JFrame jf = (JFrame)e.getSource();
if(jf.getHeight()<400) jf.setSize(jf.getWidth(),400);
if(jf.getWidth()<600) jf.setSize(600,jf.getHeight());
panRight.setBounds(jf.getWidth()-panRight.getWidth()-10,10,panRight.getWidth(),jf.getContentPane().getHeight()-20);
panGame.setBounds(10,10,jf.getWidth()-panRight.getWidth()-30,jf.getContentPane().getHeight()-20);
listResult.setSize(listResult.getWidth(), panRight.getHeight()-listResult.getY()-10);
}
});
setName("frmMain");
setTitle("拼图");
setBounds(100, 100, 579, 438);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panMain = new JPanel();
panMain.setLayout(null);
getContentPane().add(panMain, BorderLayout.CENTER);
panGame = new JPanel();
panGame.setLayout(null);
panGame.setBounds(10, 10, 358, 385);
panMain.add(panGame);
panRight = new JPanel();
panRight.setBackground(Color.CYAN);
panRight.setLayout(null);
panRight.setBounds(374, 10, 187, 385);
panMain.add(panRight);
txtLevel = new JTextField();
txtLevel.setText("3");
txtLevel.setBounds(62, 43, 87, 22);
panRight.add(txtLevel);
final JLabel label = new JLabel();
label.setText("难度:");
label.setBounds(10, 45, 39, 18);
panRight.add(label);
final JButton btnStart = new JButton();
btnStart.addMouseListener(new MouseAdapter() {
public void mouseReleased(final MouseEvent e) {
newGame();
}
});
btnStart.setText("开始");
btnStart.setBounds(10, 95, 73, 22);
panRight.add(btnStart);
final JLabel labCount = new JLabel();
labCount.setText("移动次数:");
labCount.setBounds(10, 176, 39, 18);
panRight.add(labCount);
txtCount = new JTextField();
txtCount.setBounds(62, 174, 87, 22);
额,这个代码太长了发不出来。。。
算了 展开
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class puzzle extends JFrame implements MouseListener,KeyListener{
private static final long serialVersionUID = 1L;
private JList listResult;
private JPanel panMain;
private JPanel panGame;
private JPanel panRight;
private DefaultComboBoxModel dcbm;
private JTextField txtCount;
private JTextField txtLevel;
private JLabel [][] labels;
private final int MAX_LEVEL = 10;
private int[][] nums;
private int level;
private long clickCount = 0L;
/**
* Create the frame
*/
public puzzle() {
super();
addComponentListener(new ComponentAdapter() {
public void componentResized(final ComponentEvent e) {
JFrame jf = (JFrame)e.getSource();
if(jf.getHeight()<400) jf.setSize(jf.getWidth(),400);
if(jf.getWidth()<600) jf.setSize(600,jf.getHeight());
panRight.setBounds(jf.getWidth()-panRight.getWidth()-10,10,panRight.getWidth(),jf.getContentPane().getHeight()-20);
panGame.setBounds(10,10,jf.getWidth()-panRight.getWidth()-30,jf.getContentPane().getHeight()-20);
listResult.setSize(listResult.getWidth(), panRight.getHeight()-listResult.getY()-10);
}
});
setName("frmMain");
setTitle("拼图");
setBounds(100, 100, 579, 438);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panMain = new JPanel();
panMain.setLayout(null);
getContentPane().add(panMain, BorderLayout.CENTER);
panGame = new JPanel();
panGame.setLayout(null);
panGame.setBounds(10, 10, 358, 385);
panMain.add(panGame);
panRight = new JPanel();
panRight.setBackground(Color.CYAN);
panRight.setLayout(null);
panRight.setBounds(374, 10, 187, 385);
panMain.add(panRight);
txtLevel = new JTextField();
txtLevel.setText("3");
txtLevel.setBounds(62, 43, 87, 22);
panRight.add(txtLevel);
final JLabel label = new JLabel();
label.setText("难度:");
label.setBounds(10, 45, 39, 18);
panRight.add(label);
final JButton btnStart = new JButton();
btnStart.addMouseListener(new MouseAdapter() {
public void mouseReleased(final MouseEvent e) {
newGame();
}
});
btnStart.setText("开始");
btnStart.setBounds(10, 95, 73, 22);
panRight.add(btnStart);
final JLabel labCount = new JLabel();
labCount.setText("移动次数:");
labCount.setBounds(10, 176, 39, 18);
panRight.add(labCount);
txtCount = new JTextField();
txtCount.setBounds(62, 174, 87, 22);
额,这个代码太长了发不出来。。。
算了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询