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;
//新建一个窗口界面
mainFrame.setSize(FrameWidth,FrameHight);
mainFrame.setVisible(true);
mainFrame.setLayout(null);
mainFrame.setResizable(false);
//新建一个图形用户界面
picturePanel.setBounds(picturePanelLeftMargin,picturePanelTopMargin,pictureWitch,pictureHight);
picturePanel.
setBackground(Color.
white);
//在图形用户界面里添加图片
picturePanel.add(pictureLabel);
//在窗口界面添加图形用户界面
mainFrame.add(picturePanel);
//新建起点标签
startlabel.setText("起点:");
startlabel.setBounds(100,50,100,50);
mainFrame.add(startlabel);
//新建终点标签
endLabel.setText("终点:");
endLabel.setBounds(300,50,100,50);
mainFrame.add(endLabel);
//新建查询最短路径的按钮
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);
//获取在起点和终点的菜单中的选择
selectstart=start.getSelectedIndex();
}
});
selectend=end.getSelectedIndex();
}
});
//调用另一个类的draw画出简易图。
SimpleGraph.draw(g);
//错误提示标签
errorLabel.setBounds(800,50,300,50);
mainFrame.add(errorLabel);
//监听鼠标的点击
//点击[查询]按钮要做的事情的代码
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);
}
}
});
}
}