package jiekou;
public interface ITour {
String Suggest(String cityName);
}
package jiekou;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestTour extends Frame{
CityTour cityTour =new CityTour("D:\\cities.txt");
public static void main(String[] Args){
new TestTour();
}
JTextField text1=new JTextField(20);
JTextField text2=new JTextField(20);
public TestTour(){
JFrame f=new JFrame("city & tourist attractions");
Dimension d=new Dimension();
d.setSize(400,200);
f.setSize(d);
f.setBackground(Color.RED);
Point p=new Point(100,100);
JPanel jPanel=new JPanel();
JLabel labelCity=new JLabel("city ");
JLabel labelattraction=new JLabel("tourist attractions");
JButton buttonQuery =new JButton("OK");
jPanel.setLayout(new BoxLayout(jPanel,BoxLayout.Y_AXIS));
JPanel panel1=new JPanel(new FlowLayout(FlowLayout.RIGHT));
panel1.add(labelCity);
panel1.add(text1);
panel1.setAlignmentX(Component.CENTER_ALIGNMENT);
jPanel.add(panel1);
JPanel panel2=new JPanel(new FlowLayout(FlowLayout.RIGHT));
panel2.add(labelattraction);
panel2.add(text2);
panel2.add(buttonQuery);
panel2.setAlignmentX(Component.CENTER_ALIGNMENT);
jPanel.add(panel2);
f.add(jPanel);
f.setLocation(p);
f.setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
buttonQuery.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String cityName=text1.getText();
text2.setText(cityTour.Suggest(cityName));
}
});
}
}
ITour TestTour
于 2024-06-18 22:45:57 首次发布