首页>代码>java swing开发的2048小游戏>/2048游戏/src/_2048/GamePlay.java
package _2048;

import java.awt.Color;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;



/**
 * 2048游戏主界面
 * @author zzc
 *
 */
public class GamePlay extends JFrame {
	URL url11 = GamePlay.class.getResource("上1.png");
	URL url12 = GamePlay.class.getResource("上2.png");
	URL url13 = GamePlay.class.getResource("上3.png");
	
	URL url21 = GamePlay.class.getResource("下1.png");
	URL url22 = GamePlay.class.getResource("下2.png");
	URL url23 = GamePlay.class.getResource("下3.png");
	
	URL url31 = GamePlay.class.getResource("左1.png");
	URL url32 = GamePlay.class.getResource("左2.png");
	URL url33 = GamePlay.class.getResource("左3.png");
	
	URL url41 = GamePlay.class.getResource("右1.png");
	URL url42 = GamePlay.class.getResource("右2.png");
	URL url43 = GamePlay.class.getResource("右3.png");
	
	public static void main(String[] args) {
		GamePlay play=new GamePlay();
		play.Init();
	}
	
	public void Init(){
		this.setSize(590, 500);
		this.setLocation(300, 160);
		this.setTitle("2048");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		MyPanel mypanel=new MyPanel();
		mypanel.setLayout(null);
		mypanel.setBackground(Color.white);
		this.add(mypanel);
		
		//方向按钮
		JButton bt1=new JButton();
		bt1.setBounds(480,290, 35, 35);
		bt1.setBackground(Color.white);
		bt1.setIcon(new ImageIcon(url11));
		bt1.setRolloverIcon(new ImageIcon(url12));
		bt1.setPressedIcon(new ImageIcon(url13));
		bt1.setBorderPainted(false);
		bt1.setActionCommand("up");
		bt1.addActionListener(mypanel);
		mypanel.add(bt1);
		
		JButton bt2=new JButton();
		bt2.setBounds(480,390, 35, 35);
		bt2.setBackground(Color.white);
		bt2.setIcon(new ImageIcon(url21));
		bt2.setRolloverIcon(new ImageIcon(url22));
		bt2.setPressedIcon(new ImageIcon(url23));
		bt2.setBorderPainted(false);
		bt2.setActionCommand("down");
		bt2.addActionListener(mypanel);
		mypanel.add(bt2);
		
		JButton bt3=new JButton();
		bt3.setBounds(435,340, 35, 35);
		bt3.setBackground(Color.white);
		bt3.setIcon(new ImageIcon(url31));
		bt3.setRolloverIcon(new ImageIcon(url32));
		bt3.setPressedIcon(new ImageIcon(url33));
		bt3.setBorderPainted(false);
		bt3.setActionCommand("left");
		bt3.addActionListener(mypanel);
		mypanel.add(bt3);
		
		JButton bt4=new JButton();
		bt4.setBounds(525,340, 35, 35);
		bt4.setBackground(Color.white);
		bt4.setIcon(new ImageIcon(url41));
		bt4.setRolloverIcon(new ImageIcon(url42));
		bt4.setPressedIcon(new ImageIcon(url43));
		bt4.setBorderPainted(false);
		bt4.setActionCommand("right");
		bt4.addActionListener(mypanel);
		mypanel.add(bt4);
		
		
		this.setVisible(true);
	}
	
}
最近下载更多
1112WHQ  LV7 2023年11月3日
双方各何必呢  LV13 2023年5月31日
huangzy  LV12 2023年4月6日
liangge2115  LV27 2021年12月14日
选了了  LV7 2021年12月13日
Demo1111  LV30 2021年12月8日
123aa21a  LV5 2021年6月23日
misamjsds  LV9 2021年6月3日
快乐小贝  LV4 2021年2月1日
段朝洪  LV15 2020年11月21日
最近浏览更多
7456321  LV1 4月22日
ClydeSon  LV5 2023年12月27日
微信网友_6793785677565952  LV1 2023年12月25日
lshlsh 2023年12月25日
暂无贡献等级
bangyiyang  LV2 2023年12月21日
1112WHQ  LV7 2023年11月3日
jiangneng666  LV2 2023年10月20日
412836806 2023年10月13日
暂无贡献等级
双方各何必呢  LV13 2023年5月31日
huangzy  LV12 2023年4月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友