求用TextPad做个超级简单小游戏的代码。。。
小弟我最近在学JAVA,马上就要学期结束了,要用TextPad做一款简单的游戏,求高手给个小游戏的代码,越简单越好,谢谢了~~~~~~~~
import java.awt.Dimension; import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Random; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class ClickMe extends JFrame{ private JButton button; public ClickMe() { super("小游戏"); getContentPane().setLayout(null); button= new JButton("点我"); button.setMargin(new Insets(-2,-1,-2,-1)); button.setBounds(30, 30, 30, 30); button.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ JOptionPane.showMessageDialog(null, "你点中我啦!"); } } ); add(button); addMouseMotionListener( new MouseAdapter(){ Random rand = new Random(); public void mouseMoved(MouseEvent event){ int xdot = rand.nextInt(400); int ydot = rand.nextInt(400); button.setLocation(xdot, ydot); } } ); setSize(400,400); setResizable(false); //屏幕居中 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = getSize(); setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new ClickMe(); } }