⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 travel.java

📁 本程序是一个简单的"铁路_运费查询"程序,用户只需在源代码注释处加入或更改一些简单的代码就能变成自己特定的查询"系统" 程序简单,界面友好,方便,实用!
💻 JAVA
字号:
package examples;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
class WindowTravel extends JFrame{
	private static final long serialVersionUID = 1L;
	private CheckboxGroup mode;//运送方式
	private Checkbox wholeCar,container;//整车,集装箱
	private Choice destination,springboard,production;//到站,发站,产品
	private JButton count;//计算
	private JTextArea result;//结果区
	WindowTravel(){
		super("整车和集装箱货物运价查询");
		mode=new CheckboxGroup();
		wholeCar=new Checkbox("整车",true,mode);
		container=new Checkbox("集装箱",false,mode);
		JPanel p1=new JPanel();
		Label label0=new Label("运送方式");
		p1.add(label0);
		p1.add(wholeCar);
		p1.add(container);
		springboard=new Choice();
		springboard.add("燕岗");
		destination=new Choice();
		destination.add("绵阳");
		destination.add("成都");
		destination.add("西昌");
		destination.add("昆明");
		destination.add("广元");
		destination.add("重庆");
		destination.add("北京");
		destination.add("武汉");
		destination.add("上海");
		destination.add("攀枝花");//增加更多到站名,只需在此后添加如左格式代码,并将汉字改为相应品名然后在下面添加相应里程即可
		production=new Choice();
		production.add("煤");
		production.add("瓷砖");
		production.add("衣服");
		production.add("蔬菜");
		production.add("粮食");
		production.add("水果");
		production.add("茶叶");//增加更多品名,只需在此后添加如左格式代码,并将汉字改为相应品名即可
		JPanel p2=new JPanel(new FlowLayout());
		Label label1=new Label("发站");
		p2.add(label1);
		p2.add(springboard);
		Label label2=new Label("到站");
		p2.add(label2);
		p2.add(destination);
		Label label3=new Label("品名");
		p2.add(label3);
		p2.add(production);
		count=new JButton("计算");
		JPanel p3=new JPanel();
		p3.add(count);
		JPanel p4=new JPanel(new BorderLayout());
		p4.add(p1,BorderLayout.NORTH);
		p4.add(p2,BorderLayout.CENTER);
		p4.add(p3,BorderLayout.SOUTH);
		p4.setBorder(new TitledBorder("信息输入窗口"));
		result=new JTextArea();
		result.setBorder(new TitledBorder("结果显示窗口"));
		result.setEditable(false);
		getContentPane().add(p4,BorderLayout.NORTH);
		getContentPane().add(result,BorderLayout.CENTER);
		setBounds(450,260,330,300);
		setVisible(true);
	//	setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//到此窗口做好了
		count.addActionListener(new ActionListener(){
			public void actionPerformed (ActionEvent e){
				result.setText("");
				WholeCarCount wholeCarCount=new WholeCarCount();
				wholeCarCount.f1();
			}
		});
	}
	class WholeCarCount{
		int x=0;
		double y=0,z=0;
		void f1(){
			switch(destination.getSelectedIndex()){
			case 0:	x=275;break;
			case 1:x=160;break;
			case 2:x=397;break;
			case 3:x=940;break;
			case 4:x=497;break;
			case 5:x=490;break;
			case 6:x=2202;break;
			case 7:x=1597;break;
			case 8:x=2511;break;
			case 9:x=565;break;//增加更多到站名,需在此后添加如左格式代码,并将X值附值为相应里程值即可
			}
			y=85.3+0.3768*x;
			result.append("发站\t"+springboard.getSelectedItem()+
					"\n到站\t"+destination.getSelectedItem()+
					"\n里程\t"+x+
					"\n品名\t"+production.getSelectedItem()+
					"\n计算结果\n");
			if(wholeCar.getSelectedObjects()!=null){
				y=85.3+0.3768*x;
				result.append("整车每吨运价="+y);
			}
			else{
				z=6.8+0.0311*x;
				result.append("集装箱每吨运价="+z);
			}
		}
	}
}
public class Travel {
	public static void main(String[] args) {
		new WindowTravel();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -