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); |
} |
} |
|
}); |
|
} |
} |
初级程序员
by: 赶蚊子 发表于:2017-06-20 11:06:27 顶(0) | 踩(0) 回复
哇
回复评论