用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

校园导航

2016-12-19 作者: 爱因斯坦举报

[java]代码库

package xiaoyuandaohang;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;



public class jiemian {
	static int selectstart=-1;
	static int selectend=-1;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		point SimpleGraph=new point();
		//窗口界面大小
		int FrameWidth = 1120;
		int FrameHight = 700;
		//图形用户界面大小
		int pictureWitch=1100;
		int pictureHight=550;
		//图形用户界面离窗口界面的边界宽度
		int picturePanelLeftMargin = 10;
		int picturePanelTopMargin = 140;
		//新建一个窗口界面
		JFrame mainFrame = new JFrame("广州商学院导航系统");
		mainFrame.setSize(FrameWidth,FrameHight);
		mainFrame.setVisible(true);
		mainFrame.setLayout(null);
		mainFrame.setResizable(false);
		
		//新建一个图形用户界面
		JPanel picturePanel = new JPanel();
		picturePanel.setBounds(picturePanelLeftMargin,picturePanelTopMargin,pictureWitch,pictureHight);
		picturePanel.setBackground(Color.white);
		//在图形用户界面里添加图片
		ImageIcon picture = new ImageIcon("D:\\广州商学院导航图.png");
		JLabel pictureLabel=new JLabel(picture);
		picturePanel.add(pictureLabel);
		//在窗口界面添加图形用户界面
		mainFrame.add(picturePanel);
		//新建起点标签
		JLabel startlabel = new JLabel();
		startlabel.setText("起点:");
		startlabel.setBounds(100,50,100,50);
		mainFrame.add(startlabel);
		//新建终点标签
		JLabel endLabel=new JLabel();
		endLabel.setText("终点:");
		endLabel.setBounds(300,50,100,50);
		mainFrame.add(endLabel);
		//新建查询最短路径的按钮
		JButton inquiryButton = new JButton();
		inquiryButton.setText("查询");
		inquiryButton.setBounds(600,50,100,50);
		mainFrame.add(inquiryButton);
		
		//新建下拉菜单选择起点
	    JComboBox<String> start=new JComboBox<String>();
		for(int i=0;i<SimpleGraph.placename.length;i++){
			start.addItem(SimpleGraph.placename[i]);
		}
		start.setBounds(150,60,100,30);
		mainFrame.add(start);
		//新建下拉菜单选择终点
		JComboBox<String> end=new JComboBox<String>();
		for(int i=0;i<SimpleGraph.placename.length;i++){
			end.addItem(SimpleGraph.placename[i]);
		}
		end.setBounds(350,60,100,30);
		mainFrame.add(end);
		mainFrame.setVisible(true);
		
		Graphics g=picturePanel.getGraphics();
		//获取在起点和终点的菜单中的选择
		start.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evevt){
				selectstart=start.getSelectedIndex();
			}
		});
		end.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evevt){
				selectend=end.getSelectedIndex();
			}
		});
		
		//调用另一个类的draw画出简易图。
		SimpleGraph.draw(g);
		//错误提示标签
		JLabel errorLabel=new JLabel();
		errorLabel.setBounds(800,50,300,50);
		mainFrame.add(errorLabel);
	    //监听鼠标的点击
		inquiryButton.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent event){
			     //点击[查询]按钮要做的事情的代码
				if(selectstart==-1||selectend==-1)
				{
					errorLabel.setText("未选择起点和终点!");
				}
				else if(selectstart==selectend)
				{
					errorLabel.setText("选择的起点和终点相同,请重新选择!");
				}
				else
				{
					SimpleGraph.draw(g);
					//找到场所是第几个节点在传进去
					SimpleGraph.drawShortestPath(SimpleGraph.place[selectstart], SimpleGraph.place[selectend],g);
				}
			}			
			
		});
		
	}

}

[代码运行效果截图]


校园导航

[源代码打包下载]




网友评论    (发表评论)

共4 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...