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

📄 framemaker.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;// demonstrates the family of classes which extend FramedDisplaypublic class FrameMaker extends WindowController implements ActionListener {        // coordinates and dimensions of the frame    private static final double CORNER_X = 175;    private static final double CORNER_Y = 100;    private static final double HEIGHT = 30;    private static final double WIDTH = 100;        // what to put inside of a FramedText object    private static final String LABEL = new String("Hello");        // allows choice of objects    private JComboBox choice;        // the selected object    private FrameIfc target;        // changes the current target (if applicable)    private JButton update;    // highlights the target    private JButton light;    // un-highlight the target    private JButton ulight;        // draw the gui components and initialize target to be a FramedDisplay    public void begin() {                JPanel controlPanel = new JPanel();                update = new JButton("Update");        update.addActionListener(this);                choice = new JComboBox();        choice.addItem( new String("FramedDisplay"));        choice.addItem( new String("FramedText"));        choice.addItem( new String("FramedBarMeter"));        choice.addActionListener(this);                light = new JButton("Highlight");        light.addActionListener(this);        ulight = new JButton("Un-Highlight");        ulight.addActionListener(this);        controlPanel.add(update);        controlPanel.add(choice);        controlPanel.add(light);        controlPanel.add(ulight);                Container contentPane = getContentPane();        contentPane.add(controlPanel, BorderLayout.SOUTH);                target = new FramedDisplayTester(CORNER_X, CORNER_Y, WIDTH, HEIGHT, canvas);            }        // if the update button was pressed, update target    // otherwise, change target to the selected object type    public void actionPerformed( ActionEvent evt ){        Object selected = choice.getSelectedItem();                if (evt.getSource() == update){            target.update();        }        else if (evt.getSource() == light){            target.highlight();        }        else if (evt.getSource() == ulight){            target.unHighlight();        }        else {            canvas.clear();            if (selected.equals("FramedDisplay")){                target = new FramedDisplayTester(CORNER_X, CORNER_Y, WIDTH,                                                 HEIGHT, canvas);            }            else if (selected.equals("FramedText")){                target = new FramedTextTester( LABEL, CORNER_X, CORNER_Y,                                               WIDTH, HEIGHT, canvas);            }            else if (selected.equals("FramedBarMeter")){                target = new FramedBarMeterTester( 0, CORNER_X, CORNER_Y,                                                   WIDTH, HEIGHT, canvas);            }        }            }        }

⌨️ 快捷键说明

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