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

📄 restaurant2.java

📁 JAVA编写的小餐厅用户界面式的点餐算价器,还带有外框Boder
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Restaurant2 extends JFrame implements ActionListener {
	JMenuBar	menuBar;
	JMenu		options, calcu;
	JMenuItem	rest, quit, starters, mains, desserts;
	JPanel		Starters = new JPanel(new GridLayout(4,2,2,2));
	JPanel		Mains = new JPanel(new GridLayout(4,2,2,2));
	JPanel		Desserts = new JPanel(new GridLayout(4,2,2,2));
	JPanel		total = new JPanel(new GridLayout(3,1,2,2));
	JLabel		A[],B[],C[];
	JComboBox	a[],b[],c[];
	JTextField	text1,text2,text3,text4;
	Border		blackline = BorderFactory.createLineBorder(Color.black);

	public Restaurant2() {

		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		options = new JMenu("options");
		menuBar.add(options);
		rest = new JMenuItem("Rest");
		rest.addActionListener(this);
		options.add(rest);
		quit = new JMenuItem("Quit");
		quit.addActionListener(this);
		options.add(quit);
		options.addSeparator();

		calcu = new JMenu("calculation");
		menuBar.add(calcu);
		starters = new JMenuItem("Starters");
		starters.addActionListener(this);
		calcu.add(starters);
		mains = new JMenuItem("Mains");
		mains.addActionListener(this);
		calcu.add(mains);
		desserts = new JMenuItem("Mains");
		desserts.addActionListener(this);
		calcu.add(desserts);

		String[] num = {"0","1","2","3","4","5","6"};
		Border title = BorderFactory.createTitledBorder(blackline, "title");

		A = new JLabel[4];
		A[0] = new JLabel("Chickens Lettuce Wraps - 7.95");
		A[1] = new JLabel("Bruschetta - 6.95");
		A[2] = new JLabel("Chilli Cheese Fries - 6.25");
		A[3] = new JLabel("Total Starter Cost:");
		a = new JComboBox[3];
		for (int l=0; l<3; l++) {
			a[l] = new JComboBox (num);
			a[l].addActionListener(this);
		}
		text1 = new JTextField("£0.00");
		addToJPanel(Starters, A, a, text1, title);

		B = new JLabel[4];
		B[0] = new JLabel("Gardenburger(v) - 7.45");
		B[1] = new JLabel("Angel Hair Pasta - 9.45");
		B[2] = new JLabel("Pot Roast Dinner - 12.95");
		B[3] = new JLabel("Total Main Course Cost:");
		b = new JComboBox [3];
		for (int k=0; k<3; k++) {
			b[k] = new JComboBox (num);
			b[k].addActionListener(this);
		}
		text2 = new JTextField("£0.00");
		addToJPanel(Mains, B, b, text2, title);

		C = new JLabel[4];
		C[0] = new JLabel("BJ's Famous Pizookie - 4.75");
		C[1] = new JLabel("Cookies and Cream, Party Platter - 14.95");
		C[2] = new JLabel("BJ's Brownie - 3.75");
		C[3] = new JLabel("Total Dessert Cost:");
		c = new JComboBox[3];
		for (int m=0; m<3; m++) {
			c[m] = new JComboBox(num);
			c[m].addActionListener(this);
		}
		text3 = new JTextField("£0.00");
		addToJPanel(Desserts, C, c, text3, title);

		total.add(Starters);
		total.add(Mains);
		total.add(Desserts);

		setTitle("BJ's Brewhouse");
		setSize(450,500);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(total, BorderLayout.CENTER);
		setVisible(true);

	}

	static void addToJPanel (JPanel panel, JLabel[] label, JComboBox[] box, JTextField text, Border title) {
		for(int i=0; i<8; i++) {
			if (i%2==0) {
				panel.add(label[i/2]);
			} else if(i==7) {
				text.setEditable(false);
				panel.add(text);
			} else {
				box[(i-1)/2].setSelectedIndex(0);
				panel.add(box[(i-1)/2]);
			}
		}
		panel.setBorder(title);

	}



	public void actionPerformed(java.awt.event.ActionEvent e) {


	}



	public static void main(String args[]) {

		JFrame meal = new Restaurant2();

	}

}

⌨️ 快捷键说明

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