⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java我的部分代码.txt

📁 华容道游戏
💻 TXT
字号:
public class Hua_Rong_Road2 extends Applet implements KeyListener,ActionListener
{   People people[]=new People[10];//定义people数组存放按钮
    Rectangle left,right,above,below;//定义四个Rectangle(矩形)类的对象,分别是left,right,above,below;
    Button restart=new Button("重新开始");//定义一个复位按钮“重新开始”
    Button b1,b2,b3,b4,b5;//定义五个按钮
    Panel p,p1;//定义Panel类对象,分别为p、p1(为中间容器)
    Label l1,l2,l3,l4,l5;// 定义五个标签
    int flag; //定义标识
    public void init()//初始化applet
    {   setLayout(null);//把applet布局设置为空
        setBackground(Color.green);
        l1=new Label("未通过");
        l2=new Label("未通过");
        l3=new Label("未通过");
        l4=new Label("未通过");
        l5=new Label("未通过");
        flag=1;
        people[0]=new People(0,"曹操",104,54,100,100,this);
        people[1]=new People(1,"关羽",104,154,100,50,this);
        people[2]=new People(2,"张飞",54,154,50,100,this);
        people[3]=new People(3,"刘备",204,154,50,100,this);
        people[4]=new People(4,"张辽",54,54,50,100,this);
        people[5]=new People(5,"曹仁",204,54,50,100,this);
        people[6]=new People(6,"兵 ",54,254,50,50,this);
        people[7]=new People(7,"兵 ",204,254,50,50,this);
        people[8]=new People(8,"兵 ",104,204,50,50,this);
        people[9]=new People(9,"兵 ",154,204,50,50,this);
        p=new Panel(new GridLayout(6,1));
        p1=new Panel(new GridLayout(6,2));
        p1.setBackground(Color.green);
        p1.setForeground(Color.blue);
        
        p1.add(new Label("第一关:横刀立马1"));p1.add(l1);
        p1.add(new Label("第二关:横刀立马2"));p1.add(l2);
        p1.add(new Label("第三关:齐头并前"));p1.add(l3);
        p1.add(new Label("第四关:兵分三路"));p1.add(l4);
        p1.add(new Label("第五关:屯兵东路"));p1.add(l5);
        
        b1=new Button("第一关:横刀立马1");
        b2=new Button("第二关:横刀立马2");
        b3=new Button("第三关:齐头并前");
        b4=new Button("第四关:兵分三路");
        b5=new Button("第五关:屯兵东路");
        p.add(restart);p.add(b1);p.add(b2);p.add(b3);p.add(b4);p.add(b5);add(p);add(p1);
        restart.addActionListener(this);b1.addActionListener(this);b2.addActionListener(this);
        b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);
        p.setBounds(350,54,110,120);p1.setBounds(350,200,200,140);
        b1.setBackground(Color.green);b2.setBackground(Color.green);b3.setBackground(Color.green);
        b4.setBackground(Color.green);b5.setBackground(Color.green);restart.setBackgroud(Color.green);
        b1.setForeground(Color.blue);b2.setForeground(Color.blue);b3.setForeground(Color.blue);
        b4.setForeground(Color.blue);b5.setForeground(Color.blue);restart.setForeground(Color.blue);
        
        
       
        people[9].requestFocus();
        left=new Rectangle(49,49,5,260);
        
        people[0].setForeground(Color.white);
        right=new Rectangle(254,49,5,260);
        above=new Rectangle(49,49,210,5);
        below=new Rectangle(49,304,210,5);
    }
    public void paint(Graphics g)//描绘
    {   g.setColor(Color.blue);
        g.fillRect(49,49,5,260);
        g.fillRect(254,49,5,260);
        g.fillRect(49,304,56,5);
        g.setColor(Color.white);


        g.fillRect(104,304,109,5);
        g.setColor(Color.blue);
        g.fillRect(204,304,55,5);
        g.drawString("单击相应人物,然后按键盘上下左右键移动其位置,使曹操到达指定位置",60,20);
        g.setColor(Color.red);
        g.drawString("曹操逃走的位置",110,300);
    }
    public void genggai(People peo,int a,int b)//定义genggai方法
    {   peo.left_x=a;peo.left_y=b;
        peo.setLocation(a,b);peo.rect.setLocation(a,b);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -