📄 guide.java
字号:
/*
* @(#)Guide.java 1.0 06/04/08
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_1\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Guide extends JFrame implements ActionListener{
private JButton buttonStart,buttonFlush,buttonShowBestPath;
private JComboBox from,to;
private PictruePanel pictruePanel;
private JTextArea text;
public Guide()
{
buttonStart=new JButton("start");
buttonFlush=new JButton("flush");
buttonShowBestPath =new JButton("show hole path");
pictruePanel=new PictruePanel();
pictruePanel.setBackground(Color.white);
pictruePanel.setBorder(new TitledBorder("show map"));
text=new JTextArea();
text.setPreferredSize(new Dimension(180,200));
from=new JComboBox();
to=new JComboBox();
text.setText("Welcome to beihai park,\n and this application will \n performance as your guide\nwhile traveling"
+"It has two buttons \n'from' and 'to' from\nwhich you can choose\n your present"
+"location \nand you destination,then \nclick start,the map will\nshow you the best way\n"
+"The flush button \nwill show you the original\nmap and the last button\nwill show you the best\nway to travel"
+"from the entrance\nand then go through all\npoints and end your\ntrip at the exit"
+"Wish you have a \ngood time");
for(int i=0;i<15;i++)
{
from.addItem(pictruePanel.name[i]);
to.addItem(pictruePanel.name[i]);
}
JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel("from"));
p1.add(from);
p1.add(new JLabel("to"));
p1.add(to);
p1.add(buttonStart);
p1.add(buttonFlush);
p1.add(buttonShowBestPath);
LineBorder bord1=new LineBorder(Color.BLACK,2);
p1.setBorder(bord1);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.SOUTH);
getContentPane().add(pictruePanel,BorderLayout.CENTER);
getContentPane().add(text,BorderLayout.EAST);
buttonStart.addActionListener(this);
buttonFlush.addActionListener(this);
buttonShowBestPath.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==buttonStart)
pictruePanel.drawpath(from.getSelectedIndex(),to.getSelectedIndex());
else if(e.getSource()==buttonFlush)
pictruePanel.flush();
else if(e.getSource()==buttonShowBestPath)
{
pictruePanel.drawholepath();
}
StringBuffer string=new StringBuffer("the hole path:\n");
AllPath allpath=pictruePanel.allpath;
if(allpath==null)
return;
Path path=allpath.firstPath;
Node node;
while(path!=null)
{ node=path.head;
string.append("\nPATH:\n");
while(node!=null)
{ string.append(pictruePanel.name[node.point]+"-->\n");
node=node.next;
}
path=path.nextPath;
}
text.setText(string.toString());
text.repaint();
}
public static void main(String[] args)
{
Guide guide=new Guide();
guide.setTitle("guide in the park");
guide.setBounds(80,80,750,600);
guide.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -