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

📄 coffeebrewer.java

📁 这是我修读美国卡耐基梅隆大学Carnegie Mellon University(CMU)课程ssd3:Object-Oriented Programming and Design时完成的课程设计
💻 JAVA
字号:
import  java.awt.*;
import  javax.swing.*;

/**
 * This class models a coffee brewer. It extends {@link Product} and adds the
 * following information:
 * <ol>
 * <li>the model of the coffee brewer, a <code>String</code></li>
 * <li>the water supply ("Pour-over" or "Automatic")</li>
 * <li>the capacity expressed in number of cups, a <code>int</code></li>
 * </ol>
 *
 * @author 张维
 * @version  1.0.0
 * @see Product
 */
public class CoffeeBrewer extends Product  {

	/* Model of the coffee brewer. */
	private String  model;

	/* The water supply of the coffee brewer ("Pour-over" or "Automatic"). */
	private String  waterSupply;

	/* The capacity expressed in number of cups. */
	private int  numberOfCups;

	/**
	 * Constructs a <code>CoffeeBrewer</code> object.
	 *
	 * @param initialCode  the code of the product.
	 * @param initialDescription  a short description of the product.
	 * @param initialPrice  the price of the product.
	 * @param initialModel  the model of the coffee brewer.
	 * @param initialWaterSupply  the water supply is ("Pour-over" or
	 *                        "Automatic").
	 * @param initialNumberOfCups  the capacity expressed in number of cups.
	 */
	public CoffeeBrewer(String initialCode, String initialDescription,
			double  initialPrice, String initialModel,
			String initialWaterSupply, int initialNumberOfCups)  {

		super(initialCode, initialDescription, initialPrice);

		model = initialModel;
		waterSupply = initialWaterSupply;
		numberOfCups = initialNumberOfCups;
	}

	/**
	 * Returns the model of this coffee brewer.
	 *
	 * @return  the model of this coffee brewer.
	 */
	public String  getModel()  {

		return  model;
	}

	/**
	 * Returns the type of water supply.
	 *
	 * @return  returns "Pour-over" or "Automatic".
	 */
	public String  getWaterSupply()  {

		return  waterSupply;
	}

	/**
	 * Returns the capacity of this coffee brewer expressed in number of cups.
	 *
	 * @return  the capacity of this coffee brewer expressed in number of cups.
	 */
	public int  getNumberOfCups()  {

		return  numberOfCups;
	}

	/**
	 * Returns the string representation of this coffee brewer.
	 *
	 * @return  the string representation of this coffee brewer.
	 */
	public String  toString()  {

		return super.toString() + "_" + getModel() + "_" + getWaterSupply()
		       + "_" + getNumberOfCups();
	}

	/**
	 * Obtains a {@link JPanel} object with the information of this coffee
	 * brewer.
	 *
	 * @return a <code>JPanel</code> with the information of this coffee brewer.
	 */
	public JPanel getPanel() {

		/* Creates a object of class {@link @JPanel} */
		JPanel jpanel = new JPanel();
		jpanel.setLayout(new BorderLayout());
		
		/* Create the components */
    JTextField jtextfield = new JTextField(getCode(), 17);
    JTextField jtextfield1 = new JTextField(getDescription(), 17);
    JTextField jtextfield2 = new JTextField(Double.toString(getPrice()), 17);
    JTextField jtextfield3 = new JTextField(getModel(), 17);
    JTextField jtextfield4 = new JTextField(getWaterSupply(),17);
    JTextField jtextfield5 = new JTextField(Integer.toString(getNumberOfCups()), 17);
        
    /* Make the text area un-editable */       
    jtextfield.setEditable(false);
    jtextfield1.setEditable(false);
    jtextfield2.setEditable(false);
    jtextfield3.setEditable(false);
    jtextfield4.setEditable(false);
    jtextfield5.setEditable(false);
        
        
    JPanel jpanel1 = new JPanel(new GridLayout(6, 1));
    jpanel1.add(new JLabel("Code:"));
    jpanel1.add(new JLabel("Description: "));
    jpanel1.add(new JLabel("Price:"));
    jpanel1.add(new JLabel("Model:"));
    jpanel1.add(new JLabel("Water supply:"));
    jpanel1.add(new JLabel("Number of cups:"));
                
    JPanel jpanel2 = new JPanel(new GridLayout(6, 1));
    jpanel2.add(jtextfield);
    jpanel2.add(jtextfield1);
    jpanel2.add(jtextfield2);
    jpanel2.add(jtextfield3);
    jpanel2.add(jtextfield4);
    jpanel2.add(jtextfield5);
        
    /* Add components to the container */  
    jpanel.add(jpanel1, BorderLayout.CENTER);
    jpanel.add(jpanel2, BorderLayout.EAST);
        
    return jpanel;
	}
}

⌨️ 快捷键说明

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