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

📄 resolution.java

📁 java编写的最短路径算法
💻 JAVA
字号:
package user_interface;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import integrate.*;
public class Resolution extends JFrame{
	private JFrame parentWin;
	public Structure output;
	public Resolution(Structure oo){
		super("Result Display");
		
		output=oo;
		parentWin=this;
		setSize(Constant.frameWidth, Constant.frameHeight);
		
		//set the background
		((JPanel)this.getContentPane()).setOpaque(false); 
		ImageIcon img = new ImageIcon("BG.jpg"); 
		JLabel background = new JLabel(img); 
		this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); 
		background.setBounds(0, 0, img.getIconWidth(),img.getIconHeight());
		
		setVisible(true);
		addButtons();
		repaint();
	}
	public void paint(Graphics g) {
		super.paint(g);
		g = this.getContentPane().getGraphics();
		g.setColor(Color.white);
		int i,j,x,y,xx=0,yy=0;
		for (i=1; i<=9; i++){
			x=71+(i-1)*30;
			g.drawLine(x, 40, x, 150);
		}
		for (i=1; i<=5; i++){
			y=72+(i-1)*16;
			for (j=1; j<=9; j++){
				x=71+(j-1)*30;
				g.drawLine(x-5, y, x+5, y);
			}
		}
		
		g.setColor(Color.red);

		
		for (i=0; i<=output.unitNum; i++){
			x=71+(8-output.unitList[i].rank)*30+15;
			y=72+(4-output.unitList[i].layer)*16+8;
			g.fillRect(x-2, y-2, 4, 4);
			if (i>0){
				g.drawLine(x, y, xx, yy);
			}
			xx=x;
			yy=y;
			
		}
		
		//put down the total distance
		g.setFont(new Font("SansSerif", Font.BOLD, 14));
		g.setColor(Color.white);
		String display="The total moving distance is ";
		
		
		//output.resultDis=129445.124;
		Double result=new Double(output.resultDis);
		String re=result.toString();
		int deci=-1;
		for (i=0; i<re.length(); i++){
			if (re.charAt(i)=='.'){
				deci=i;
			}
		}
		if ((deci>=0)&&(re.length()-deci-1>3)){
			re=re.substring(0, deci+4);
		}
		display+=re;
		
		display+=" (mm)";
		g.drawString(display, (Constant.frameWidth-display.length()*8)/2,
					180);
		
	}
	
	public void addButtons() {
//		Button Back
		JToggleButton jbb=new JToggleButton();
		jbb.setText("Back");
		jbb.setBounds(new Rectangle(Constant.frameWidth/2-Constant.boxWidth/2, Constant.frameHeight/2+3*Constant.buttonClearance, Constant.boxWidth,
				Constant.boxHeight));
		jbb.setToolTipText("Back.");

		this.getContentPane().add(jbb);
			
		
		jbb.setVisible(true);
		jbb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event){
				parentWin.dispose();
		}}
		
		);
	}

}

⌨️ 快捷键说明

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