第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

華容道出問題啦,大神快來。

華容道出問題啦,大神快來。

ShallHurk 2016-01-23 23:22:55
Person.java package?華容道; import?javax.swing.*; import?java.awt.*; import?java.awt.event.*; public?class?Person?extends?JButton?implements?FocusListener?{ int?number; Color?c?=?new?Color(255,245,170); Font?font?=?new?Font("宋體",Font.BOLD,12); Person(int?number,String?s){ super(s); setBackground(c); setFont(font); this.number=number; c?=?getBackground(); addFocusListener(this); } public?void?focusGained(FocusEvent?e){ setBackground(Color.red); } ?? public?void?focusLost(FocusEvent?e){ setBackground(c); } } HRD.java package?華容道; public?class?HRD?{ public?static?void?main(String[]?args)?{ //?TODO?Auto-generated?method?stub ????????new?Hua_Rong_Road(); ?????? } }?Hua_Rong_Road.javapackage 華容道;import java.awt.*;import javax.swing.*;import java.awt.event.*;public class Hua_Rong_Road extends JFrame implements MouseListener,KeyListener,ActionListener{ Person person[]=new Person[10]; JButton left; JButton right; JButton above; JButton below; JButton restart=new JButton("重新開始"); public Hua_Rong_Road(){ init(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);// setBounds(100,100,320,500); setVisible(true); validate(); addWindowListener( new WindowAdapter()? ? ? ? ?{? ? ? ? ? ? ?public void windowClosing(WindowEvent e)? ? ? ? ? ? ?{? ? ? ? ? ? ? ? ?System.exit(0);? ? ? ? ? ? ?}? ? ? ? ?}? ?); } public void init(){ setLayout(null); add(restart); restart.setBounds(100,320,120,35); restart.addActionListener(this); String name[]={"曹操","關(guān)羽","張飛","劉備","周瑜","黃蓋","兵","兵","兵","兵"}; for(int k=0; k<name.length; k++){ person[k]=new Person(k,name[k]); person[k].addMouseListener(this); person[k].addKeyListener(this); add(person[k]); } person[0].setBounds(104, 54, 100, 100); person[1].setBounds(104, 154, 100, 50); person[2].setBounds(54, 154, 50, 100); person[3].setBounds(204, 154, 50, 100); person[4].setBounds(54, 54, 50, 100); person[5].setBounds(204, 54, 50, 100); person[6].setBounds(54, 254, 50, 50); person[7].setBounds(204, 254, 50, 50); person[8].setBounds(104, 204, 50, 50); person[9].setBounds(154, 204, 50, 50); person[9].requestFocus(); left=new JButton(); right=new JButton(); above=new JButton(); below=new JButton(); add(left); add(right); add(above); add(below); left.setBounds(49,49,5,260); right.setBounds(254, 49, 5, 260); above.setBounds(49, 49, 210, 5); below.setBounds(49, 304, 210, 5); validate(); } public void keyTyped(KeyEvent e){} public void keyReleased(KeyEvent e){} public void keyPressed(KeyEvent e){ Person man=(Person)e.getSource(); if(e.getKeyCode()==KeyEvent.VK_DOWN){ go(man,below); } if(e.getKeyCode()==KeyEvent.VK_UP){ go(man,above); } if(e.getKeyCode()==KeyEvent.VK_LEFT){ go(man,left); } if(e.getKeyCode()==KeyEvent.VK_RIGHT){ go(man,right); } } public void mousePressed(MouseEvent e){ Person man=(Person)e.getSource();? int x=-1; int y=-1; x=e.getX(); y=e.getY(); int w=man.getBounds().width; int h=man.getBounds().height; if(y>h/2){ go(man,below); } if(y<h/2){ go(man,above); } if(x<w/2){ go(man,left); } if(x>w/2){ go(man,right); } } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} private void go(Person man, JButton direction) { // TODO Auto-generated method stub boolean move=true; Rectangle manRect=man.getBounds(); int x=man.getBounds().x; int y=man.getBounds().y; if(direction==below){ y=y+50; }else if(direction==above){ y=y-50; }else if(direction==left){ x=x-50; }else if(direction==right){ x=x+50; } manRect.setLocation(x,y); Rectangle directionRect=direction.getBounds(); for(int k=0; k<10; k++){ Rectangle personRect=person[k].getBounds(); if((manRect.intersects(personRect))&&(man.number!=k)){ move=false; } } if(manRect.intersects(directionRect)){ move=false; } if(move==true){ man.setLocation(x, y); } } public void actionPerformed(ActionEvent e){ dispose(); new Hua_Rong_Road(); } }下面是程序運(yùn)行結(jié)果,有四個(gè)人顯示不出來,大神看看吧。
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 2044 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)