- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第10章 GUI与问题域类交互作用
开发AddCustomer的GUI类,以便输入客户属性值。 开发GUI类:AddBoat,该类可用于向码头系统中添加新船只。 如何使用单选按钮RadioButton类和CardLayout布局管理器。 Sailboat keelDepth numberSails motorType Boat stateRegNo boatLength manufacturer Year Powerboat numberEngines fuelType 10.3 添加船只 添加船只框架: 该框架使用5行1列的GridLayout upperPanel使用2行4列的GridLayout centerPanel使用FlowLayout boatPanel使用CardLayout, 显示sailboatPanel或powerboatPanel lowerPanel使用FlowLayout 10.3 添加船只 sailboatPanel包含2个附加面板:leftSailboatPanel和rightSailboatPanel 2行2列的GridLayout 使用FlowLayout sailboatPanel 10.3 添加船只 如果选择了sailboat单选按钮,boatPanel会显示下面的sailboatPanel。 如果选择了Powerboat单选按钮,boatPanel会显示下面的powerboatPanel。 powerboatPanel 使用FlowLayout 10.3 添加船只 import java.awt.*; // Font, Color, Layout managers import javax.swing.*; // GUI components import java.awt.event.*; // ActionEvent, ActionListener, WindowAdapter public class AddBoat extends JFrame implements ActionListener 10.3 添加船只 // GUI reference variables //needing class scope JPanel boatPanel; CardLayout boatLayout; JTextField manufacturerText, boatLengthText, yearText, stateRegistrationText; JTextField numberOfSailsText, keelDepthText, numberOfEnginesText; JRadioButton sailboatRadioButton, powerboatRadioButton; JRadioButton noEngineRadioButton, inboardEngineRadioButton, outboardEngineRadioButton; JRadioButton gasolineFuelRadioButton, dieselFuelRadioButton; JButton addButton, clearButton, closeButton; 属性变量: 10.3 添加船只 主方法: public static void main(String args[]) { AddBoat frame = new AddBoat(); } 10.3 添加船只 创建面板 Container c = this.getContentPane(); c.setLayout(new GridLayout(5,1)); JPanel upperPanel = new JPanel(new GridLayout(2,4)); JPanel centerPanel = new JPanel(new FlowLayout()); JPanel sailboatPanel = new JPanel(new FlowLayout()); JPanel powerboatPanel = new JPanel(new FlowLayout()); JPanel lowerPanel = new JPanel(new FlowLayout()); 构造函数构建包含各种GUI组件的框架。 10.
文档评论(0)