[Java] 校园导航 →→→→→进入此内容的聊天室

来自 , 2019-06-09, 写在 Java, 查看 105 次.
URL http://www.code666.cn/view/372d3f30
  1. package xiaoyuandaohang;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.KeyAdapter;
  8. import java.awt.event.KeyEvent;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11.  
  12. import javax.swing.AbstractButton;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JButton;
  15. import javax.swing.JComboBox;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19.  
  20.  
  21.  
  22. public class jiemian {
  23.         static int selectstart=-1;
  24.         static int selectend=-1;
  25.         public static void main(String[] args) {
  26.                 // TODO Auto-generated method stub
  27.                 point SimpleGraph=new point();
  28.                 //窗口界面大小
  29.                 int FrameWidth = 1120;
  30.                 int FrameHight = 700;
  31.                 //图形用户界面大小
  32.                 int pictureWitch=1100;
  33.                 int pictureHight=550;
  34.                 //图形用户界面离窗口界面的边界宽度
  35.                 int picturePanelLeftMargin = 10;
  36.                 int picturePanelTopMargin = 140;
  37.                 //新建一个窗口界面
  38.                 JFrame mainFrame = new JFrame("广州商学院导航系统");
  39.                 mainFrame.setSize(FrameWidth,FrameHight);
  40.                 mainFrame.setVisible(true);
  41.                 mainFrame.setLayout(null);
  42.                 mainFrame.setResizable(false);
  43.                
  44.                 //新建一个图形用户界面
  45.                 JPanel picturePanel = new JPanel();
  46.                 picturePanel.setBounds(picturePanelLeftMargin,picturePanelTopMargin,pictureWitch,pictureHight);
  47.                 picturePanel.setBackground(Color.white);
  48.                 //在图形用户界面里添加图片
  49.                 ImageIcon picture = new ImageIcon("D:\\广州商学院导航图.png");
  50.                 JLabel pictureLabel=new JLabel(picture);
  51.                 picturePanel.add(pictureLabel);
  52.                 //在窗口界面添加图形用户界面
  53.                 mainFrame.add(picturePanel);
  54.                 //新建起点标签
  55.                 JLabel startlabel = new JLabel();
  56.                 startlabel.setText("起点:");
  57.                 startlabel.setBounds(100,50,100,50);
  58.                 mainFrame.add(startlabel);
  59.                 //新建终点标签
  60.                 JLabel endLabel=new JLabel();
  61.                 endLabel.setText("终点:");
  62.                 endLabel.setBounds(300,50,100,50);
  63.                 mainFrame.add(endLabel);
  64.                 //新建查询最短路径的按钮
  65.                 JButton inquiryButton = new JButton();
  66.                 inquiryButton.setText("查询");
  67.                 inquiryButton.setBounds(600,50,100,50);
  68.                 mainFrame.add(inquiryButton);
  69.                
  70.                 //新建下拉菜单选择起点
  71.             JComboBox<String> start=new JComboBox<String>();
  72.                 for(int i=0;i<SimpleGraph.placename.length;i++){
  73.                         start.addItem(SimpleGraph.placename[i]);
  74.                 }
  75.                 start.setBounds(150,60,100,30);
  76.                 mainFrame.add(start);
  77.                 //新建下拉菜单选择终点
  78.                 JComboBox<String> end=new JComboBox<String>();
  79.                 for(int i=0;i<SimpleGraph.placename.length;i++){
  80.                         end.addItem(SimpleGraph.placename[i]);
  81.                 }
  82.                 end.setBounds(350,60,100,30);
  83.                 mainFrame.add(end);
  84.                 mainFrame.setVisible(true);
  85.                
  86.                 Graphics g=picturePanel.getGraphics();
  87.                 //获取在起点和终点的菜单中的选择
  88.                 start.addActionListener(new ActionListener(){
  89.                         public void actionPerformed(ActionEvent evevt){
  90.                                 selectstart=start.getSelectedIndex();
  91.                         }
  92.                 });
  93.                 end.addActionListener(new ActionListener(){
  94.                         public void actionPerformed(ActionEvent evevt){
  95.                                 selectend=end.getSelectedIndex();
  96.                         }
  97.                 });
  98.                
  99.                 //调用另一个类的draw画出简易图。
  100.                 SimpleGraph.draw(g);
  101.                 //错误提示标签
  102.                 JLabel errorLabel=new JLabel();
  103.                 errorLabel.setBounds(800,50,300,50);
  104.                 mainFrame.add(errorLabel);
  105.             //监听鼠标的点击
  106.                 inquiryButton.addMouseListener(new MouseAdapter(){
  107.                         public void mouseClicked(MouseEvent event){
  108.                              //点击[查询]按钮要做的事情的代码
  109.                                 if(selectstart==-1||selectend==-1)
  110.                                 {
  111.                                         errorLabel.setText("未选择起点和终点!");
  112.                                 }
  113.                                 else if(selectstart==selectend)
  114.                                 {
  115.                                         errorLabel.setText("选择的起点和终点相同,请重新选择!");
  116.                                 }
  117.                                 else
  118.                                 {
  119.                                         SimpleGraph.draw(g);
  120.                                         //找到场所是第几个节点在传进去
  121.                                         SimpleGraph.drawShortestPath(SimpleGraph.place[selectstart], SimpleGraph.place[selectend],g);
  122.                                 }
  123.                         }                      
  124.                        
  125.                 });
  126.                
  127.         }
  128.  
  129. }
  130.  

回复 "校园导航"

这儿你可以回复上面这条便签

captcha