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

📄 picturepanel.java

📁 该程序实现公园导游功能
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
class PictruePanel extends JPanel{
  private Pictrue pictrue;
  private int[][]  location;
  private Path path;
  protected       AllPath allpath;
  String[] name;
  public PictruePanel()
  { pictrue=new Pictrue();
  	name=new String[20];
  	location=new int[20][2];
  	try{
  	pictrue=new Pictrue();
  	name[0]="entrance";
  	name[14]="exit";
  	for(int i=1;i<14;i++)
  	  name[i]=String.valueOf(i);
  	location[0][0]=200/3*2;location[0][1]=760/3*2-50;
  	location[1][0]=100/3*2;location[1][1]=680/3*2-50;
  	location[2][0]=215/3*2;location[2][1]=690/3*2-50;
  	location[3][0]=420/3*2;location[3][1]=715/3*2-50;
  	location[4][0]=550/3*2;location[4][1]=620/3*2-50;
  	location[5][0]=600/3*2;location[5][1]=520/3*2-50;
  	location[6][0]=630/3*2;location[6][1]=470/3*2-50;
  	location[13][0]=585/3*2;location[13][1]=230/3*2-50;
  	location[12][0]=415/3*2;location[12][1]=415/3*2-50;
  	location[11][0]=210/3*2;location[11][1]=520/3*2-50;
  	location[10][0]=235/3*2;location[10][1]=420/3*2-50;
  	location[14][0]=400/3*2;location[14][1]=760/3*2-50;
  	location[9][0]=170/3*2;location[9][1]=370/3*2-50;
  	location[7][0]=70/3*2;location[7][1]=560/3*2-50;
  	location[8][0]=65/3*2;location[8][1]=230/3*2-50;
  
  	}
  	catch(ArrayIndexOutOfBoundsException e)
	{
  		System.out.println(e.toString());
	}
  	
  }
  public void paintComponent(Graphics g)
  {
  	super.paintComponent(g);
  	g.setColor(Color.BLACK);
  	for(int i=0;i<15;i++)
  	{     
  		  g.fillOval(location[i][0]-3,location[i][1]-3,10,10);
  		  g.setFont(new Font("Serif",Font.PLAIN,15));
  		  g.drawString(name[i],location[i][0]-15,location[i][1]-5);
    }      //draw name of landscape;      
    for(int i=0;i<15;i++)
  	  for(int j=0;j<i;j++)
  	  {  if(pictrue.weight[i][j]<Integer.MAX_VALUE)
  	  { g.drawLine(location[i][0],location[i][1],location[j][0],location[j][1]);
  	    g.drawString(String.valueOf(pictrue.weight[i][j]),(location[i][0]+location[j][0])/2,(location[i][1]+location[j][1])/2);
  	  }
  	  }     //draw path;	
        g.setColor(Color.RED);
    	if(path!=null)
    	{   Node t=path.head;
    	while(t.next!=null)
         {	  g.drawLine(location[t.point][0],location[t.point][1],location[t.next.point][0],location[t.next.point][1]);
             t=t.next;
         }
       }
    }
  public void drawpath(int from,int to)
  {
  	if(from==to)
      return;
  	allpath=pictrue.findpath(from,to);
  	if(allpath==null)
  	  System.out.println("error");
  	path=pictrue.getbestpath(allpath);
  	this.repaint(); 	
  }
  public void drawholepath()
  {
  	allpath=pictrue.findallpath();
  	path=pictrue.getbestpath(allpath);
  	this.repaint();
  }
  public void flush()
  {
  	path=null;
  	repaint();
  }
}

⌨️ 快捷键说明

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