📄 gui.java
字号:
import javax.swing.*;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
//import second.WindowDestroyer;
import java.awt.*;
import java.awt.event.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class GUI extends JFrame implements ActionListener
{
Icon banner = new ImageIcon("E:\\图片\\ditu.jpg");
JLabel ditu =new JLabel();
JTextField[] field=new JTextField[2];
JTextArea result=new JTextArea(24,30);
private Mistake me;
public static final int WIDTH=700;
public static final int HEIGHT=460;
{
try
{
InputStream in = new FileInputStream("E:\\音乐视频\\歌曲\\今天.wav");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException e)
{
System.out.print("FileNotFoundException ");
}
catch(IOException e)
{
System.out.print("有错误!");
}
ditu.setIcon(banner);
setResizable(false);
setLocation(400, 50);
setTitle("GPS定位系统");
setSize(WIDTH,HEIGHT);
Container content=getContentPane();
content.setBackground(Color.WHITE);
content.setLayout(new BorderLayout());//建立窗体及容器
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowDestroyer());
JPanel map=new JPanel();
JPanel button=new JPanel();
JTextArea grap=new JTextArea(24,30);
button.setLayout(new FlowLayout());
result.setEditable(false);
field[0]=new JTextField(10);
field[1]=new JTextField(10);
JLabel lb[]=new JLabel[2];
Font font=new Font("隶书",Font.BOLD,25);
lb[0]=new JLabel("始点 ");
lb[1]=new JLabel("终点 ");
JButton []b=new JButton[3];
b[0]=new JButton("线路查询");
b[1]=new JButton("地点管理");
b[2]=new JButton(" 退出 ");
for (int i=0;i<2;i++)
{
lb[i].setFont(font);
button.add(lb[i]);
button.add(field[i]);
}
for(int i=0;i<3;i++)
{
b[i].addActionListener(this);//监听器
button.add(b[i]);
}
for(int i=0;i<2;i++)
{
field[i].addActionListener(this);//监听器
}
grap.setBackground(Color.orange);
result.setBackground(Color.magenta);
map.add(ditu,BorderLayout.WEST);
map.add(result,BorderLayout.EAST);
content.add(map,BorderLayout.CENTER);
content.add(button,BorderLayout.SOUTH);//添加按钮槽
setVisible(true);
}
//
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("线路查询"))
{
try
{
if(field[0].getText().equals("")||field[1].getText().equals("")){
JOptionPane.showMessageDialog(null,"请输入完整信息!","无效操作",1);
try
{
InputStream in = new FileInputStream("E:\\图片\\ku.wav");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException a)
{
System.out.print("FileNotFoundException ");
}
catch(IOException a)
{
System.out.print("有错误!");
} }
else if(field[0].getText().equals(field[1].getText()))
result.setText("始点与终点相同 \n 总长 0 千米");
else
{
Map m=new Map();
int s=m.getnumber(field[0].getText());
int t=m.getnumber(field[1].getText());
int n=m.getamount();
int d[]=new int[n+1], p[]=new int[n+1];
String r[]=new String[n+1];
m.Search(s,t,d,p);
if(m.Search(s,t,d,p)==0)
{
try
{
InputStream in = new FileInputStream("E:\\图片\\ku.wav");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException a)
{
System.out.print("FileNotFoundException ");
}
catch(IOException a)
{
System.out.print("有错误!");
}
result.setText("从"+ field[0].getText() +"到"+field[1].getText() +"无路抵达");
}
else
{
int temp=t;int i=0;
while(temp!=0)
{
r[i]=m.getname(temp);
temp=p[temp];
i++;
}
String rote="此结束";
for( i=0;i<=n;i++)
if(r[i]!=null)
rote=r[i]+" 到 "+rote;
try
{
InputStream in = new FileInputStream("E:\\图片\\huanhu.wav");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException a)
{
System.out.print("FileNotFoundException ");
}
catch(IOException a)
{
System.out.print("有错误!");
}
result.setText("最短路径为: \n "+ rote +"\n总长为: \n "+d[t]+" 千米");
}
}
}
catch(Exception ee)
{
me=new Mistake("地名输入错误!");
}
}
else if(e.getActionCommand().equals("地点管理"))
{//
myframe1 frame1 =new myframe1();
}
else if(e.getActionCommand().equals(" 退出 "))
{
int result = JOptionPane.showConfirmDialog(null,"您确定要退出吗?","退出",0);
if( result == 0 )System.exit(0);
}
}
public static void main(String[]args)
{
new GUI();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -